ext4_journal: code logic optimization. See below.
[lwext4.git] / lwext4 / ext4_bcache.c
index 628735ab659fe38b5aac1e7fda1f660210f6fafb..3688346f802dcea15f8c733aa5bc4ab575fc73b0 100644 (file)
@@ -132,6 +132,7 @@ ext4_buf_alloc(struct ext4_bcache *bc, uint64_t lba)
 
        buf->lba = lba;
        buf->data = data;
+       buf->bc = bc;
        return buf;
 }
 
@@ -238,6 +239,11 @@ int ext4_bcache_alloc(struct ext4_bcache *bc, struct ext4_block *b,
        /* One more buffer in bcache now. :-) */
        bc->ref_blocks++;
 
+       /*Calc ref blocks max depth*/
+       if (bc->max_ref_blocks < bc->ref_blocks)
+               bc->max_ref_blocks = bc->ref_blocks;
+
+
        ext4_bcache_inc_ref(buf);
        /* Assign new value to LRU id and increment LRU counter
         * by 1*/
@@ -284,7 +290,8 @@ int ext4_bcache_free(struct ext4_bcache *bc, struct ext4_block *b)
                }
 
                /* 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);
 
        }