erofs-utils: lib: cache: get rid of required_ext
PATCH v2 1/4 erofs-utils: lib: cache: get rid of required_ext
It's never used and doesn't have clear meanings.
Signed-off-by Gao Xiang <[email protected]>
--- include/erofs/cache.h | 1 - lib/blobchunk.c | 4 ++-- lib/cache.c | 22 +++++++++------------- lib/compress.c | 4 ++-- lib/inode.c | 10 +++++----- lib/super.c | 2 +- lib/xattr.c | 2 +- 7 files changed, 20 insertions(+), 25 deletions(-)
include/erofs/cache.h +0 -1
@@ -120,7 +120,6 @@ int erofs_bh_balloon(struct erofs_buffer_head *bh, erofs_off_t incr);struct erofs_buffer_head *erofs_balloc (struct erofs_bufmgr *bmgr,int type,erofs_off_t size, -unsigned int required_ext,unsigned int inline_ext);struct erofs_buffer_head *erofs_battach (struct erofs_buffer_head *bh,int type,unsigned int size);
lib/blobchunk.c +2 -2
@@ -525,7 +525,7 @@ int erofs_mkfs_dump_blobs(struct erofs_sb_info *sbi)return 0 ; } - bh =erofs_balloc (sbi->bmgr,DATA , datablob_size,0 ,0 ); + bh =erofs_balloc (sbi->bmgr,DATA , datablob_size,0 );if (IS_ERR (bh))return PTR_ERR (bh);
@@ -647,7 +647,7 @@ int erofs_mkfs_init_devices(struct erofs_sb_info *sbi, unsigned int devices)return -ENOMEM ; bh_devt =erofs_balloc (sbi->bmgr,DEVT , -sizeof (struct erofs_deviceslot ) * devices,0 ,0 ); +sizeof (struct erofs_deviceslot ) * devices,0 );if (IS_ERR (bh_devt)) {free (sbi->devs);return PTR_ERR (bh_devt);
lib/cache.c +9 -13
@@ -127,7 +127,6 @@ int erofs_bh_balloon(struct erofs_buffer_head *bh, erofs_off_t incr)static int erofs_bfind_for_attach (struct erofs_bufmgr *bmgr,int type,erofs_off_t size, -unsigned int required_ext,unsigned int inline_ext,unsigned int alignsize,struct erofs_buffer_block **bbp)
@@ -137,7 +136,7 @@ static int erofs_bfind_for_attach(struct erofs_bufmgr *bmgr,unsigned int used0, used_before, usedmax, used;int ret; - used0 = ((size + required_ext) & (blksiz -1 )) + inline_ext; + used0 = (size & (blksiz -1 )) + inline_ext;/* inline data should be in the same fs block */ if (used0 > blksiz)return -ENOSPC ;
@@ -151,11 +150,10 @@ static int erofs_bfind_for_attach(struct erofs_bufmgr *bmgr, bb =NULL ;/* try to find a most-fit mapped buffer block first */ -if (size + required_ext + inline_ext >= blksiz) +if (size + inline_ext >= blksiz) goto skip_mapped; - used_before =rounddown (blksiz - - (size + required_ext + inline_ext), alignsize); + used_before =rounddown (blksiz - (size + inline_ext), alignsize);for (; used_before; --used_before) {struct list_head *bt = bmgr->mapped_buckets[type] + used_before;
@@ -175,14 +173,14 @@ static int erofs_bfind_for_attach(struct erofs_bufmgr *bmgr,DBG_BUGON (used_before != (cur->buffers.off & (blksiz -1 ))); ret =__erofs_battach (cur,NULL , size, alignsize, - required_ext + inline_ext, true); + inline_ext, true);if (ret <0 ) {DBG_BUGON (1 );continue ; }/* should contain all data in the current block */ - used = ret + required_ext + inline_ext; + used = ret + inline_ext;DBG_BUGON (used > blksiz); bb = cur;
@@ -207,11 +205,11 @@ skip_mapped:continue ; ret =__erofs_battach (cur,NULL , size, alignsize, - required_ext + inline_ext, true); + inline_ext, true);if (ret <0 )continue ; - used = ((ret + required_ext) & (blksiz -1 )) + inline_ext; + used = (ret & (blksiz -1 )) + inline_ext;/* should contain inline data in current block */ if (used > blksiz)
@@ -235,7 +233,6 @@ skip_mapped:struct erofs_buffer_head *erofs_balloc (struct erofs_bufmgr *bmgr,int type,erofs_off_t size, -unsigned int required_ext,unsigned int inline_ext) {struct erofs_buffer_block *bb;
@@ -251,7 +248,7 @@ struct erofs_buffer_head *erofs_balloc(struct erofs_bufmgr *bmgr, alignsize = ret;/* try to find if we could reuse an allocated buffer block */ - ret =erofs_bfind_for_attach (bmgr, type, size, required_ext, inline_ext, + ret =erofs_bfind_for_attach (bmgr, type, size, inline_ext, alignsize, &bb);if (ret)return ERR_PTR (ret);
@@ -285,8 +282,7 @@ struct erofs_buffer_head *erofs_balloc(struct erofs_bufmgr *bmgr, } } - ret =__erofs_battach (bb, bh, size, alignsize, - required_ext + inline_ext, false); + ret =__erofs_battach (bb, bh, size, alignsize, inline_ext, false);if (ret <0 ) {free (bh);return ERR_PTR (ret);
lib/compress.c +2 -2
@@ -1378,7 +1378,7 @@ int erofs_mt_write_compressed_file(struct z_erofs_compress_ictx *ictx)pthread_cond_wait (&ictx->cond, &ictx->mutex);pthread_mutex_unlock (&ictx->mutex); - bh =erofs_balloc (sbi->bmgr,DATA ,0 ,0 ,0 ); + bh =erofs_balloc (sbi->bmgr,DATA ,0 ,0 );if (IS_ERR (bh)) { ret =PTR_ERR (bh); goto out;
@@ -1544,7 +1544,7 @@ int erofs_write_compressed_file(struct z_erofs_compress_ictx *ictx)#endif /* allocate main data buffer */ - bh =erofs_balloc (inode->sbi->bmgr,DATA ,0 ,0 ,0 ); + bh =erofs_balloc (inode->sbi->bmgr,DATA ,0 ,0 );if (IS_ERR (bh)) { ret =PTR_ERR (bh); goto err_free_idata;
lib/inode.c +5 -5
@@ -189,7 +189,7 @@ int erofs_allocate_inode_bh_data(struct erofs_inode *inode, erofs_blk_t nblocks)/* allocate main data buffer */ type =S_ISDIR (inode->i_mode) ?DIRA :DATA ; - bh =erofs_balloc (bmgr, type,erofs_pos (inode->sbi, nblocks),0 ,0 ); + bh =erofs_balloc (bmgr, type,erofs_pos (inode->sbi, nblocks),0 );if (IS_ERR (bh))return PTR_ERR (bh);
@@ -777,7 +777,7 @@ static int erofs_prepare_inode_buffer(struct erofs_inode *inode) inode->datalayout =EROFS_INODE_FLAT_PLAIN ; } - bh =erofs_balloc (bmgr,INODE , inodesize,0 , inode->idata_size); + bh =erofs_balloc (bmgr,INODE , inodesize, inode->idata_size);if (bh ==ERR_PTR (-ENOSPC )) {int ret;
@@ -790,7 +790,7 @@ noinline: ret =erofs_prepare_tail_block (inode);if (ret)return ret; - bh =erofs_balloc (bmgr,INODE , inodesize,0 ,0 ); + bh =erofs_balloc (bmgr,INODE , inodesize,0 );if (IS_ERR (bh))return PTR_ERR (bh);DBG_BUGON (inode->bh_inline);
@@ -871,7 +871,7 @@ static int erofs_write_tail_end(struct erofs_inode *inode)if (!bh) { bh =erofs_balloc (sbi->bmgr,DATA , -erofs_blksiz (sbi),0 ,0 ); +erofs_blksiz (sbi),0 );if (IS_ERR (bh))return PTR_ERR (bh); bh->op = &erofs_skip_write_bhops;
@@ -1186,7 +1186,7 @@ static int erofs_inode_reserve_data_blocks(struct erofs_inode *inode)struct erofs_buffer_head *bh;/* allocate data blocks */ - bh =erofs_balloc (sbi->bmgr,DATA , alignedsz,0 ,0 ); + bh =erofs_balloc (sbi->bmgr,DATA , alignedsz,0 );if (IS_ERR (bh))return PTR_ERR (bh);
lib/super.c +1 -1
@@ -211,7 +211,7 @@ struct erofs_buffer_head *erofs_reserve_sb(struct erofs_bufmgr *bmgr)struct erofs_buffer_head *bh;int err; - bh =erofs_balloc (bmgr,META ,0 ,0 ,0 ); + bh =erofs_balloc (bmgr,META ,0 ,0 );if (IS_ERR (bh)) {erofs_err ("failed to allocate super: %s" ,erofs_strerror (PTR_ERR (bh)));
lib/xattr.c +1 -1
@@ -924,7 +924,7 @@ int erofs_build_shared_xattrs_from_path(struct erofs_sb_info *sbi, const char *preturn -ENOMEM ; } - bh =erofs_balloc (sbi->bmgr,XATTR , shared_xattrs_size,0 ,0 ); + bh =erofs_balloc (sbi->bmgr,XATTR , shared_xattrs_size,0 );if (IS_ERR (bh)) {free (sorted_n);free (buf);
Signature · 1 line
2.43.5
PATCH v2 2/4 erofs-utils: lib: move block boundary check into __erofs_battach()
It should be guaranteed when buffers are attached, rather than scattered everywhere.
Signed-off-by Gao Xiang <[email protected]>
--- lib/cache.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
lib/cache.c +13 -13
@@ -69,7 +69,7 @@ static int __erofs_battach(struct erofs_buffer_block *bb,struct erofs_buffer_head *bh, erofs_off_t incr, unsigned int alignsize, - unsigned int extrasize, + unsigned int inline_ext, bool dryrun) { struct erofs_bufmgr *bmgr = bb->buffers.fsprivate;
@@ -78,11 +78,16 @@ static int __erofs_battach(struct erofs_buffer_block *bb,const unsigned int blkmask = blksiz -1 ;erofs_off_t boff = bb->buffers.off;const erofs_off_t alignedoffset =roundup (boff, alignsize); -const int oob =cmpsgn (roundup (((boff -1 ) & blkmask) +1 , alignsize) + - incr + extrasize, blksiz);bool tailupdate = false;erofs_blk_t blkaddr; +int oob; +/* inline data must never span block boundaries */ +if (erofs_blkoff (sbi, alignedoffset + incr + blkmask) + + inline_ext > blkmask) +return -ENOSPC ; + + oob =cmpsgn ((alignedoffset & blkmask) + incr + inline_ext, blksiz);if (oob >=0 ) {/* the next buffer block should be NULL_ADDR all the time */ if (oob &&list_next_entry (bb, list)->blkaddr !=NULL_ADDR )
@@ -111,7 +116,7 @@ static int __erofs_battach(struct erofs_buffer_block *bb,BLK_ROUND_UP (sbi, boff);erofs_bupdate_mapped (bb); } -return ((alignedoffset + incr -1 ) & blkmask) +1 ; +return ((alignedoffset + incr + blkmask) & blkmask) +1 ; }int erofs_bh_balloon (struct erofs_buffer_head *bh,erofs_off_t incr)
@@ -179,12 +184,10 @@ static int erofs_bfind_for_attach(struct erofs_bufmgr *bmgr,continue ; } + usedmax = ret + inline_ext;/* should contain all data in the current block */ - used = ret + inline_ext; -DBG_BUGON (used > blksiz); - +DBG_BUGON (usedmax > blksiz); bb = cur; - usedmax = used;break ; }
@@ -209,11 +212,8 @@ skip_mapped:if (ret <0 )continue ; - used = (ret & (blksiz -1 )) + inline_ext; - -/* should contain inline data in current block */ -if (used > blksiz) -continue ; + used = ret + inline_ext; +DBG_BUGON (used > blksiz);/* * remaining should be smaller than before or
Signature · 1 line
2.43.5
PATCH v2 3/4 erofs: support buffer block reservation
In reply to Gao XiangIn order to support data alignment, add support for recording multiple block reservations.
Signed-off-by Gao Xiang <[email protected]>
--- include/erofs/cache.h | 11 +++++++---- lib/cache.c | 32 ++++++++++++++++---------------- 2 files changed, 23 insertions(+), 20 deletions(-)
include/erofs/cache.h +7 -4
@@ -35,11 +35,14 @@ struct erofs_bhops {struct erofs_buffer_head {struct list_head list; -struct erofs_buffer_block *block; - +union { +struct { +struct erofs_buffer_block *block; +const struct erofs_bhops *op; + }; +erofs_blk_t nblocks; + };erofs_off_t off; -const struct erofs_bhops *op; -void *fsprivate; };
lib/cache.c +16 -16
@@ -74,8 +74,7 @@ static int __erofs_battach(struct erofs_buffer_block *bb, {struct erofs_bufmgr *bmgr = bb->buffers.fsprivate;struct erofs_sb_info *sbi = bmgr->sbi; -const unsigned int blksiz =erofs_blksiz (sbi); -const unsigned int blkmask = blksiz -1 ; +const unsigned int blkmask =erofs_blksiz (sbi) -1 ;erofs_off_t boff = bb->buffers.off;const erofs_off_t alignedoffset =roundup (boff, alignsize);bool tailupdate = false;
@@ -87,7 +86,8 @@ static int __erofs_battach(struct erofs_buffer_block *bb, + inline_ext > blkmask)return -ENOSPC ; - oob =cmpsgn ((alignedoffset & blkmask) + incr + inline_ext, blksiz); + oob =cmpsgn (roundup (boff, alignsize) + incr + inline_ext, + bb->buffers.nblocks << sbi->blkszbits);if (oob >=0 ) {/* the next buffer block should be NULL_ADDR all the time */ if (oob &&list_next_entry (bb, list)->blkaddr !=NULL_ADDR )
@@ -96,7 +96,7 @@ static int __erofs_battach(struct erofs_buffer_block *bb, blkaddr = bb->blkaddr;if (blkaddr !=NULL_ADDR ) { tailupdate = (bmgr->tail_blkaddr == blkaddr + -BLK_ROUND_UP (sbi, boff)); + bb->buffers.nblocks);if (oob && !tailupdate)return -EINVAL ; }
@@ -110,10 +110,11 @@ static int __erofs_battach(struct erofs_buffer_block *bb, } boff = alignedoffset + incr; bb->buffers.off = boff; + bb->buffers.nblocks =max_t (erofs_blk_t, bb->buffers.nblocks, +BLK_ROUND_UP (sbi, boff));/* need to update the tail_blkaddr */ if (tailupdate) - bmgr->tail_blkaddr = blkaddr + -BLK_ROUND_UP (sbi, boff); + bmgr->tail_blkaddr = blkaddr + bb->buffers.nblocks;erofs_bupdate_mapped (bb); }return ((alignedoffset + incr + blkmask) & blkmask) +1 ;
@@ -266,6 +267,7 @@ struct erofs_buffer_head *erofs_balloc(struct erofs_bufmgr *bmgr, bb->type = type; bb->blkaddr =NULL_ADDR ; bb->buffers.off =0 ; + bb->buffers.nblocks =0 ; bb->buffers.fsprivate = bmgr;init_list_head (&bb->buffers.list);if (type ==DATA )
@@ -319,7 +321,7 @@ struct erofs_buffer_head *erofs_battach(struct erofs_buffer_head *bh,return nbh; } -static erofs_blk_t __erofs_mapbh (struct erofs_buffer_block *bb) +static void __erofs_mapbh (struct erofs_buffer_block *bb) {struct erofs_bufmgr *bmgr = bb->buffers.fsprivate;erofs_blk_t blkaddr;
@@ -330,10 +332,9 @@ static erofs_blk_t __erofs_mapbh(struct erofs_buffer_block *bb)erofs_bupdate_mapped (bb); } - blkaddr = bb->blkaddr +BLK_ROUND_UP (bmgr->sbi, bb->buffers.off); + blkaddr = bb->blkaddr + bb->buffers.nblocks;if (blkaddr > bmgr->tail_blkaddr) bmgr->tail_blkaddr = blkaddr; -return blkaddr; } erofs_blk_t erofs_mapbh(struct erofs_bufmgr *bmgr,
@@ -353,7 +354,7 @@ erofs_blk_t erofs_mapbh(struct erofs_bufmgr *bmgr,break ;DBG_BUGON (t->blkaddr !=NULL_ADDR ); - (void )__erofs_mapbh (t); +__erofs_mapbh (t); }while (t != bb);return bmgr->tail_blkaddr; }
@@ -389,7 +390,8 @@ int erofs_bflush(struct erofs_bufmgr *bmgr,if (p == bb)break ; - blkaddr =__erofs_mapbh (p); +__erofs_mapbh (p); + blkaddr = p->blkaddr +BLK_ROUND_UP (sbi, p->buffers.off);list_for_each_entry_safe (bh, nbh, &p->buffers.list, list) {if (bh->op == &erofs_skip_write_bhops) {
@@ -412,8 +414,7 @@ int erofs_bflush(struct erofs_bufmgr *bmgr, padding, true);if (p->type !=DATA ) - bmgr->metablkcnt += -BLK_ROUND_UP (sbi, p->buffers.off); + bmgr->metablkcnt += p->buffers.nblocks;erofs_dbg ("block %u to %u flushed" , p->blkaddr, blkaddr -1 );erofs_bfree (p); }
@@ -424,13 +425,12 @@ void erofs_bdrop(struct erofs_buffer_head *bh, bool tryrevoke) {struct erofs_buffer_block *const bb = bh->block;struct erofs_bufmgr *bmgr = bb->buffers.fsprivate; -struct erofs_sb_info *sbi = bmgr->sbi;const erofs_blk_t blkaddr = bh->block->blkaddr;bool rollback = false;/* tail_blkaddr could be rolled back after revoking all bhs */ if (tryrevoke && blkaddr !=NULL_ADDR && - bmgr->tail_blkaddr == blkaddr +BLK_ROUND_UP (sbi, bb->buffers.off)) + bmgr->tail_blkaddr == blkaddr + bb->buffers.nblocks) rollback = true; bh->op = &erofs_drop_directly_bhops;
@@ -440,7 +440,7 @@ void erofs_bdrop(struct erofs_buffer_head *bh, bool tryrevoke)return ;if (!rollback && bb->type !=DATA ) - bmgr->metablkcnt +=BLK_ROUND_UP (sbi, bb->buffers.off); + bmgr->metablkcnt += bb->buffers.nblocks;erofs_bfree (bb);if (rollback) bmgr->tail_blkaddr = blkaddr;
Signature · 1 line
2.43.5
PATCH v2 4/4 erofs-utils: mkfs: support data alignment
In reply to Gao XiangThe underlay block storage could work in a stripe-like manner to improve performance and space efficiency.
EROFS on-disk layout is flexible enough for such use cases.
Cc Changpeng Liu <[email protected]>
Signed-off-by Gao Xiang <[email protected]>
--- include/erofs/cache.h | 3 +++ lib/cache.c | 25 ++++++++++++++++++++----- man/mkfs.erofs.1 | 3 +++ mkfs/main.c | 11 +++++++++++ 4 files changed, 37 insertions(+), 5 deletions(-)
include/erofs/cache.h +3 -0
@@ -67,6 +67,9 @@ struct erofs_bufmgr {/* last mapped buffer block to accelerate erofs_mapbh() */ struct erofs_buffer_block *last_mapped_block; + +/* align data block addresses to multiples of `dsunit` */ +unsigned int dsunit; }; static inline const int get_alignsize(struct erofs_sb_info *sbi, int type,
lib/cache.c +20 -5
@@ -156,10 +156,15 @@ static int erofs_bfind_for_attach(struct erofs_bufmgr *bmgr, bb =NULL ;/* try to find a most-fit mapped buffer block first */ -if (size + inline_ext >= blksiz) + +if (__erofs_unlikely (bmgr->dsunit >1 )) { + used_before = blksiz - alignsize; + }else if (size + inline_ext >= blksiz) { goto skip_mapped; + }else { + used_before =rounddown (blksiz - (size + inline_ext), alignsize); + } - used_before =rounddown (blksiz - (size + inline_ext), alignsize);for (; used_before; --used_before) {struct list_head *bt = bmgr->mapped_buckets[type] + used_before;
@@ -181,7 +186,7 @@ static int erofs_bfind_for_attach(struct erofs_bufmgr *bmgr, ret =__erofs_battach (cur,NULL , size, alignsize, inline_ext, true);if (ret <0 ) { -DBG_BUGON (1 ); +DBG_BUGON (!(bmgr->dsunit >1 ));continue ; }
@@ -324,10 +329,20 @@ struct erofs_buffer_head *erofs_battach(struct erofs_buffer_head *bh,static void __erofs_mapbh (struct erofs_buffer_block *bb) {struct erofs_bufmgr *bmgr = bb->buffers.fsprivate; -erofs_blk_t blkaddr; +erofs_blk_t blkaddr = bmgr->tail_blkaddr;if (bb->blkaddr ==NULL_ADDR ) { - bb->blkaddr = bmgr->tail_blkaddr; + bb->blkaddr = blkaddr; +if (__erofs_unlikely (bmgr->dsunit >1 ) && bb->type ==DATA ) { +struct erofs_buffer_block *pb =list_prev_entry (bb, list); + + bb->blkaddr =roundup (blkaddr, bmgr->dsunit); +if (pb != &bmgr->blkh && + pb->blkaddr + pb->buffers.nblocks >= blkaddr) { +DBG_BUGON (pb->blkaddr + pb->buffers.nblocks > blkaddr); + pb->buffers.nblocks = bb->blkaddr - pb->blkaddr; + } + } bmgr->last_mapped_block = bb;erofs_bupdate_mapped (bb); }
man/mkfs.erofs.1 +3 -0
@@ -149,6 +149,9 @@ the given primary algorithm, alternative algorithms can be specified with are extended regular expressions, matched against absolute paths within the output filesystem, with no leading /. .TP +.BI "\-\-dsunit=" # +Align all data block addresses to multiples of #. +.TP .BI "\-\-exclude-path=" path Ignore file that matches the exact literal path. You may give multiple
mkfs/main.c +11 -0
@@ -86,6 +86,7 @@ static struct option long_options[] = { {"all-time", no_argument, NULL, 526}, {"sort", required_argument, NULL, 527}, {"hard-dereference", no_argument, NULL, 528}, + {"dsunit", required_argument, NULL, 529}, {0, 0, 0, 0}, };
@@ -162,6 +163,7 @@ static void usage(int argc, char **argv)" --blobdev=X specify an extra device X to store chunked data\n" " --chunksize=# generate chunk-based files with #-byte chunks\n" " --clean=X run full clean build (default) or:\n" +" --dsunit=# align all data block addresses to multiples of #\n" " --incremental=X run incremental build\n" " (X = data|rvsp; data=full data, rvsp=space is allocated\n" " and filled with zeroes)\n"
@@ -243,6 +245,7 @@ static unsigned int rebuild_src_count;static LIST_HEAD (rebuild_src_list);static u8 fixeduuid[16 ];static bool valid_fixeduuid; +static unsigned int dsunit;static int erofs_mkfs_feat_set_legacy_compress (bool en,const char *val,unsigned int vallen)
@@ -856,6 +859,13 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])case 528 : cfg.c_hard_dereference = true;break ; +case 529 : + dsunit =strtoul (optarg, &endptr,0 ); +if (*endptr !='\0' ) { +erofs_err ("invalid dsunit %s" , optarg); +return -EINVAL ; + } +break ;case 'V' :version ();exit (0 );
@@ -1318,6 +1328,7 @@ int main(int argc, char **argv) } sb_bh =NULL ; } + g_sbi.bmgr->dsunit = dsunit;/* Use the user-defined UUID or generate one for clean builds */ if (valid_fixeduuid)
Signature · 1 line
2.43.5