In order to prepare for the upcoming space allocation speedup. Signed-off-by: Gao Xiang <hsiang...@linux.alibaba.com> --- include/erofs/cache.h | 4 ++-- lib/cache.c | 27 +++++++++++++-------------- 2 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/include/erofs/cache.h b/include/erofs/cache.h index 6ff80ab..bdf6460 100644 --- a/include/erofs/cache.h +++ b/include/erofs/cache.h @@ -48,7 +48,7 @@ struct erofs_buffer_head { struct erofs_buffer_block { struct list_head list; - struct list_head mapped_list; + struct list_head sibling; /* blocks of the same waterline */ erofs_blk_t blkaddr; int type; @@ -60,7 +60,7 @@ struct erofs_bufmgr { struct erofs_sb_info *sbi; /* buckets for all mapped buffer blocks to boost up allocation */ - struct list_head mapped_buckets[META + 1][EROFS_MAX_BLOCK_SIZE]; + struct list_head watermeter[META + 1][EROFS_MAX_BLOCK_SIZE]; struct erofs_buffer_block blkh; erofs_blk_t tail_blkaddr, metablkcnt; diff --git a/lib/cache.c b/lib/cache.c index f9aa6eb..c7243b5 100644 --- a/lib/cache.c +++ b/lib/cache.c @@ -41,15 +41,15 @@ struct erofs_bufmgr *erofs_buffer_init(struct erofs_sb_info *sbi, bufmgr->blkh.blkaddr = NULL_ADDR; bufmgr->last_mapped_block = &bufmgr->blkh; - for (i = 0; i < ARRAY_SIZE(bufmgr->mapped_buckets); i++) - for (j = 0; j < ARRAY_SIZE(bufmgr->mapped_buckets[0]); j++) - init_list_head(&bufmgr->mapped_buckets[i][j]); + for (i = 0; i < ARRAY_SIZE(bufmgr->watermeter); i++) + for (j = 0; j < (1 << sbi->blkszbits); j++) + init_list_head(&bufmgr->watermeter[i][j]); bufmgr->tail_blkaddr = startblk; bufmgr->sbi = sbi; return bufmgr; } -static void erofs_bupdate_mapped(struct erofs_buffer_block *bb) +static void erofs_update_bwatermeter(struct erofs_buffer_block *bb) { struct erofs_bufmgr *bmgr = bb->buffers.fsprivate; struct erofs_sb_info *sbi = bmgr->sbi; @@ -58,10 +58,10 @@ static void erofs_bupdate_mapped(struct erofs_buffer_block *bb) if (bb->blkaddr == NULL_ADDR) return; - bkt = bmgr->mapped_buckets[bb->type] + + bkt = bmgr->watermeter[bb->type] + (bb->buffers.off & (erofs_blksiz(sbi) - 1)); - list_del(&bb->mapped_list); - list_add_tail(&bb->mapped_list, bkt); + list_del(&bb->sibling); + list_add_tail(&bb->sibling, bkt); } /* return occupied bytes in specific buffer block if succeed */ @@ -116,7 +116,7 @@ static int __erofs_battach(struct erofs_buffer_block *bb, /* need to update the tail_blkaddr */ if (tailupdate) bmgr->tail_blkaddr = blkaddr + bb->buffers.nblocks; - erofs_bupdate_mapped(bb); + erofs_update_bwatermeter(bb); } return ((alignedoffset + incr + blkmask) & blkmask) + 1; } @@ -165,12 +165,11 @@ static int erofs_bfind_for_attach(struct erofs_bufmgr *bmgr, used_before = rounddown(blksiz - (size + inline_ext), alignsize); for (; used_before; --used_before) { - struct list_head *bt = bmgr->mapped_buckets[type] + used_before; + struct list_head *bt = bmgr->watermeter[type] + used_before; if (list_empty(bt)) continue; - cur = list_first_entry(bt, struct erofs_buffer_block, - mapped_list); + cur = list_first_entry(bt, struct erofs_buffer_block, sibling); /* last mapped block can be expended, don't handle it here */ if (list_next_entry(cur, list)->blkaddr == NULL_ADDR) { @@ -279,7 +278,7 @@ struct erofs_buffer_head *erofs_balloc(struct erofs_bufmgr *bmgr, &bmgr->last_mapped_block->list); else list_add_tail(&bb->list, &bmgr->blkh.list); - init_list_head(&bb->mapped_list); + init_list_head(&bb->sibling); bh = malloc(sizeof(struct erofs_buffer_head)); if (!bh) { @@ -343,7 +342,7 @@ static void __erofs_mapbh(struct erofs_buffer_block *bb) } } bmgr->last_mapped_block = bb; - erofs_bupdate_mapped(bb); + erofs_update_bwatermeter(bb); } blkaddr = bb->blkaddr + bb->buffers.nblocks; @@ -382,7 +381,7 @@ static void erofs_bfree(struct erofs_buffer_block *bb) if (bb == bmgr->last_mapped_block) bmgr->last_mapped_block = list_prev_entry(bb, list); - list_del(&bb->mapped_list); + list_del(&bb->sibling); list_del(&bb->list); free(bb); } -- 2.43.5