shithub: lwext4

Download patch

ref: a160f264f3affc3e32bba0933399c5074cd7d5c7
parent: a926535ddcd5fa7150d43fe2140ea0aad3744b46
author: gkostka <kostka.grzegorz@gmail.com>
date: Mon Apr 7 16:52:00 EDT 2014

Block cache metadata staticly alocated.
Blockdev opt.

--- a/lwext4/ext4_bcache.c
+++ b/lwext4/ext4_bcache.c
@@ -50,37 +50,10 @@
 
     memset(bc, 0, sizeof(struct ext4_bcache));
 
-    bc->refctr = malloc(cnt * sizeof(uint32_t));
-    if(!bc->refctr)
-        goto error;
-
-    bc->lru_id = malloc(cnt * sizeof(uint32_t));
-    if(!bc->lru_id)
-        goto error;
-
-    bc->free_delay = malloc(cnt * sizeof(uint8_t));
-    if(!bc->free_delay)
-        goto error;
-
-    bc->lba = malloc(cnt * sizeof(uint64_t));
-    if(!bc->lba)
-        goto error;
-
-    bc->dirty = malloc(cnt * sizeof(bool));
-    if(!bc->dirty)
-        goto error;
-
-
     bc->data = malloc(cnt * itemsize);
     if(!bc->data)
         goto error;
 
-    memset(bc->refctr, 0, cnt * sizeof(uint32_t));
-    memset(bc->lru_id, 0, cnt * sizeof(uint32_t));
-    memset(bc->free_delay, 0, cnt * sizeof(uint8_t));
-    memset(bc->lba, 0, cnt * sizeof(uint64_t));
-    memset(bc->dirty, 0, cnt * sizeof(bool));
-
     bc->cnt = cnt;
     bc->itemsize = itemsize;
     bc->ref_blocks = 0;
@@ -90,21 +63,6 @@
 
     error:
 
-    if(bc->refctr)
-        free(bc->refctr);
-
-    if(bc->lru_id)
-        free(bc->lru_id);
-
-    if(bc->free_delay)
-        free(bc->free_delay);
-
-    if(bc->lba)
-        free(bc->lba);
-
-    if(bc->dirty)
-       free(bc->dirty);
-
     if(bc->data)
         free(bc->data);
 
@@ -115,21 +73,6 @@
 
 int ext4_bcache_fini_dynamic(struct ext4_bcache *bc)
 {
-    if(bc->refctr)
-        free(bc->refctr);
-
-    if(bc->lru_id)
-        free(bc->lru_id);
-
-    if(bc->free_delay)
-        free(bc->free_delay);
-
-    if(bc->lba)
-        free(bc->lba);
-
-    if(bc->dirty)
-       free(bc->dirty);
-
     if(bc->data)
         free(bc->data);
 
--- a/lwext4/ext4_bcache.h
+++ b/lwext4/ext4_bcache.h
@@ -71,19 +71,19 @@
     uint32_t lru_ctr;
 
     /**@brief   Reference count table (cnt).*/
-    uint32_t *refctr;
+    uint32_t refctr[CONFIG_BLOCK_DEV_CACHE_SIZE];
 
     /**@brief   Last recently used ID table (cnt)*/
-    uint32_t *lru_id;
+    uint32_t lru_id[CONFIG_BLOCK_DEV_CACHE_SIZE];
 
     /**@brief   Writeback free delay mode table (cnt)*/
-    uint8_t *free_delay;
+    uint8_t free_delay[CONFIG_BLOCK_DEV_CACHE_SIZE];
 
     /**@brief   Logical block table (cnt).*/
-    uint64_t *lba;
+    uint64_t lba[CONFIG_BLOCK_DEV_CACHE_SIZE];
 
     /**@brief   Dirty mark (cnt).*/
-    bool *dirty;
+    bool dirty[CONFIG_BLOCK_DEV_CACHE_SIZE];
 
     /**@brief   Cache data buffers (cnt * itemsize)*/
     uint8_t *data;
@@ -98,21 +98,11 @@
 
 /**@brief   Static initializer of block cache structure.*/
 #define EXT4_BCACHE_STATIC_INSTANCE(__name, __cnt, __itemsize)      \
-        static uint32_t __name##_refctr[(__cnt)];                   \
-        static uint32_t __name##_lru_id[(__cnt)];                   \
-        static uint8_t  __name##_free_delay[(__cnt)];               \
-        static uint64_t __name##_lba[(__cnt)];                      \
-        static bool     __name##_dirty[(__cnt)];                    \
         static uint8_t  __name##_data[(__cnt) * (__itemsize)];      \
         static struct ext4_bcache __name = {                        \
                 .cnt     = __cnt,                                   \
                 .itemsize  = __itemsize,                            \
                 .lru_ctr   = 0,                                     \
-                .refctr    = __name##_refctr,                       \
-                .lru_id    = __name##_lru_id,                       \
-                .lba    = __name##_lba,                             \
-                .dirty    = __name##_dirty,                         \
-                .free_delay= __name##_free_delay,                   \
                 .data    = __name##_data,                           \
         }
 
--- a/lwext4/ext4_blockdev.c
+++ b/lwext4/ext4_blockdev.c
@@ -188,7 +188,7 @@
         return EIO;
 
     /*Doesn,t need to write.*/
-    if(b->dirty == false && !bdev->bc->dirty[b->cache_id]){
+    if(!b->dirty && !bdev->bc->dirty[b->cache_id]){
         ext4_bcache_free(bdev->bc, b, 0);
         return EOK;
     }
@@ -200,13 +200,14 @@
         return ext4_bcache_free(bdev->bc, b, bdev->cache_write_back);
     }
 
-    pba = (b->lb_id * bdev->lg_bsize) / bdev->ph_bsize;
-    pb_cnt = bdev->lg_bsize / bdev->ph_bsize;
-
     if(bdev->bc->refctr[b->cache_id] > 1){
         bdev->bc->dirty[b->cache_id] = true;
         return ext4_bcache_free(bdev->bc, b, 0);
     }
+
+
+    pba = (b->lb_id * bdev->lg_bsize) / bdev->ph_bsize;
+    pb_cnt = bdev->lg_bsize / bdev->ph_bsize;
 
     r = bdev->bwrite(bdev, b->data, pba, pb_cnt);
     bdev->bc->dirty[b->cache_id] = false;