shithub: lwext4

Download patch

ref: fbfb8e6fbaf7833a851b713efa31f0085ea0cc60
parent: dcbc722c722a79f8f08c538ef21f5126f5f763db
author: ngkaho1234 <ngkaho1234@gmail.com>
date: Thu Dec 31 17:06:03 EST 2015

ext4_bcache: add BC_TMP flag.

--- a/lwext4/ext4_bcache.c
+++ b/lwext4/ext4_bcache.c
@@ -290,7 +290,8 @@
 		}
 
 		/* The buffer is invalidated...drop it. */
-		if (!ext4_bcache_test_flag(buf, BC_UPTODATE))
+		if (!ext4_bcache_test_flag(buf, BC_UPTODATE) ||
+		    ext4_bcache_test_flag(buf, BC_TMP))
 			ext4_bcache_drop_buf(bc, buf);
 
 	}
--- a/lwext4/ext4_bcache.h
+++ b/lwext4/ext4_bcache.h
@@ -151,11 +151,14 @@
  *  - BC_DIRTY: Buffer is dirty.
  *  - BC_FLUSH: Buffer will be immediately flushed,
  *              when no one references it.
+ *  - BC_TMP: Buffer will be dropped once its refctr
+ *            reaches zero.
  */
 enum bcache_state_bits {
 	BC_UPTODATE,
 	BC_DIRTY,
-	BC_FLUSH
+	BC_FLUSH,
+	BC_TMP
 };
 
 #define ext4_bcache_set_flag(buf, b)    \
--- a/lwext4/ext4_journal.c
+++ b/lwext4/ext4_journal.c
@@ -280,8 +280,12 @@
 
 	/* If succeeded, mark buffer as BC_FLUSH to indicate
 	 * that data should be written to disk immediately.*/
-	if (rc == EOK)
+	if (rc == EOK) {
 		ext4_bcache_set_flag(block->buf, BC_FLUSH);
+		/* As we don't want to occupy too much space
+		 * in block cache, we set this buffer BC_TMP.*/
+		ext4_bcache_set_flag(block->buf, BC_TMP);
+	}
 
 	return rc;
 }