Skip to contentSkip to conversation

erofs-utils: lib: introduce z_erofs_fragments_tofh()

PATCH New Gao Xiang 1 participant 6 messages Jun 3, 2025 – Jun 9, 2025 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/5 erofs-utils: lib: introduce z_erofs_fragments_tofh()

Introduce a separate z_erofs_fragments_tofh() to get the tail hash in order to prepare for the upcoming multi-threaded fragment improvement.

---
 include/erofs/fragments.h |  3 +-
 lib/compress.c            | 38 ++++++++++----------
 lib/fragments.c           | 75 ++++++++++++++++++---------------------
 3 files changed, 57 insertions(+), 59 deletions(-)
include/erofs/fragments.h +2 -1
index a57b63c..75f1055 100644
@@ -15,7 +15,8 @@ extern "C"
 extern const char *erofs_frags_packedname;
 #define EROFS_PACKED_INODE	erofs_frags_packedname
 
-int z_erofs_fragments_dedupe(struct erofs_inode *inode, int fd, u32 *tofcrc);
+u32 z_erofs_fragments_tofh(struct erofs_inode *inode, int fd, erofs_off_t fpos);
+int z_erofs_fragments_dedupe(struct erofs_inode *inode, int fd, u32 tofh);
 
 int z_erofs_pack_file_from_fd(struct erofs_inode *inode, int fd, u32 tofcrc);
 int z_erofs_pack_fragments(struct erofs_inode *inode, void *data,
lib/compress.c +20 -18
index d046112..a260dc4 100644
@@ -46,7 +46,7 @@ struct z_erofs_compress_ictx {		/* inode context */
 	int fd;
 	u64 fpos;
 
-	u32 tof_chksum;
+	u32 tofh;
 	bool fix_dedupedfrag;
 	bool fragemitted;
 	bool dedupe;
@@ -626,7 +626,7 @@ nocompression:
 		   (!inode->fragment_size || ictx->fix_dedupedfrag)) {
 frag_packing:
 		ret = z_erofs_pack_fragments(inode, ctx->queue + ctx->head,
-					     len, ictx->tof_chksum);
+					     len, ictx->tofh);
 		if (ret < 0)
 			return ret;
 		e->plen = 0;	/* indicate a fragment */
@@ -1103,7 +1103,7 @@ int z_erofs_compress_segment(struct z_erofs_compress_sctx *ctx,
 	DBG_BUGON(offset != -1 && frag && inode->fragment_size);
 	if (offset != -1 && frag && !inode->fragment_size &&
 	    cfg.c_fragdedupe != FRAGDEDUPE_OFF) {
-		ret = z_erofs_fragments_dedupe(inode, fd, &ictx->tof_chksum);
+		ret = z_erofs_fragments_dedupe(inode, fd, ictx->tofh);
 		if (ret < 0)
 			return ret;
 		if (inode->fragment_size > ctx->remaining)
@@ -1622,21 +1622,23 @@ void *erofs_begin_compressed_file(struct erofs_inode *inode, int fd, u64 fpos)
 	inode->z_algorithmtype[0] = ictx->ccfg->algorithmtype;
 	inode->z_algorithmtype[1] = 0;
 
-	/*
-	 * Handle tails in advance to avoid writing duplicated
-	 * parts into the packed inode.
-	 */
-	if (cfg.c_fragments && !erofs_is_packed_inode(inode) &&
-	    ictx == &g_ictx && cfg.c_fragdedupe != FRAGDEDUPE_OFF) {
-		ret = z_erofs_fragments_dedupe(inode, fd, &ictx->tof_chksum);
-		if (ret < 0)
-			goto err_free_ictx;
+	if (cfg.c_fragments && !erofs_is_packed_inode(inode)) {
+		ictx->tofh = z_erofs_fragments_tofh(inode, fd, fpos);
+		if (ictx == &g_ictx && cfg.c_fragdedupe != FRAGDEDUPE_OFF) {
+			/*
+			 * Handle tails in advance to avoid writing duplicated
+			 * parts into the packed inode.
+			 */
+			ret = z_erofs_fragments_dedupe(inode, fd, ictx->tofh);
+			if (ret < 0)
+				goto err_free_ictx;
 
-		if (cfg.c_fragdedupe == FRAGDEDUPE_INODE &&
-		    inode->fragment_size < inode->i_size) {
-			erofs_dbg("Discard the sub-inode tail fragment of %s",
-				  inode->i_srcpath);
-			inode->fragment_size = 0;
+			if (cfg.c_fragdedupe == FRAGDEDUPE_INODE &&
+			    inode->fragment_size < inode->i_size) {
+				erofs_dbg("Discard the sub-inode tail fragment of %s",
+					  inode->i_srcpath);
+				inode->fragment_size = 0;
+			}
 		}
 	}
 	ictx->inode = inode;
@@ -1647,7 +1649,7 @@ void *erofs_begin_compressed_file(struct erofs_inode *inode, int fd, u64 fpos)
 	ictx->dedupe = false;
 
 	if (all_fragments && !inode->fragment_size) {
-		ret = z_erofs_pack_file_from_fd(inode, fd, ictx->tof_chksum);
+		ret = z_erofs_pack_file_from_fd(inode, fd, ictx->tofh);
 		if (ret)
 			goto err_free_idata;
 	}
lib/fragments.c +35 -40

132 lines not on this page · raw message

Signature · 1 line
2.43.5
author
#1 lore raw

PATCH 2/5 erofs-utils: lib: keep full data until the fragment is committed

In order to fulfill reproducible builds, let's write all fragments to disk in a specific order, which strictly follows to the committing order.

---
 include/erofs/fragments.h |   9 +-
 include/erofs/internal.h  |   1 +
 lib/compress.c            |  26 ++-
 lib/fragments.c           | 345 ++++++++++++++++++++++++--------------
 4 files changed, 241 insertions(+), 140 deletions(-)
include/erofs/fragments.h +5 -4
index 75f1055..112f002 100644
@@ -16,11 +16,12 @@ extern const char *erofs_frags_packedname;
 #define EROFS_PACKED_INODE	erofs_frags_packedname
 
 u32 z_erofs_fragments_tofh(struct erofs_inode *inode, int fd, erofs_off_t fpos);
-int z_erofs_fragments_dedupe(struct erofs_inode *inode, int fd, u32 tofh);
+int erofs_fragment_findmatch(struct erofs_inode *inode, int fd, u32 tofh);
 
-int z_erofs_pack_file_from_fd(struct erofs_inode *inode, int fd, u32 tofcrc);
-int z_erofs_pack_fragments(struct erofs_inode *inode, void *data,
-			   unsigned int len, u32 tofcrc);
+int erofs_pack_file_from_fd(struct erofs_inode *inode, int fd, u32 tofcrc);
+int erofs_fragment_pack(struct erofs_inode *inode, void *data,
+			erofs_off_t pos, erofs_off_t len, u32 tofh, bool tail);
+int erofs_fragment_commit(struct erofs_inode *inode, u32 tofh);
 int erofs_flush_packed_inode(struct erofs_sb_info *sbi);
 int erofs_packedfile(struct erofs_sb_info *sbi);
 
include/erofs/internal.h +1 -0
index 90bee07..73845f1 100644
@@ -272,6 +272,7 @@ struct erofs_inode {
 			union {
 				unsigned int z_idataoff;
 				erofs_off_t fragmentoff;
+				void *fragment;
 			};
 #define z_idata_size	idata_size
 		};
lib/compress.c +12 -14
index a260dc4..706a756 100644
@@ -526,11 +526,8 @@ static bool z_erofs_fixup_deduped_fragment(struct z_erofs_compress_sctx *ctx)
 		return false;
 	}
 
-	inode->fragmentoff += inode->fragment_size - newsize;
 	inode->fragment_size = newsize;
-
-	erofs_dbg("Reducing fragment size to %llu at %llu",
-		  inode->fragment_size | 0ULL, inode->fragmentoff | 0ULL);
+	erofs_dbg("Reducing fragment size to %llu", inode->fragment_size | 0ULL);
 
 	/* it's the end */
 	DBG_BUGON(ctx->tail - ctx->head + ctx->remaining != newsize);
@@ -625,8 +622,8 @@ nocompression:
 		   compressedsize < ctx->pclustersize &&
 		   (!inode->fragment_size || ictx->fix_dedupedfrag)) {
 frag_packing:
-		ret = z_erofs_pack_fragments(inode, ctx->queue + ctx->head,
-					     len, ictx->tofh);
+		ret = erofs_fragment_pack(inode, ctx->queue + ctx->head,
+					  ~0ULL, len, ictx->tofh, false);
 		if (ret < 0)
 			return ret;
 		e->plen = 0;	/* indicate a fragment */
@@ -1103,7 +1100,7 @@ int z_erofs_compress_segment(struct z_erofs_compress_sctx *ctx,
 	DBG_BUGON(offset != -1 && frag && inode->fragment_size);
 	if (offset != -1 && frag && !inode->fragment_size &&
 	    cfg.c_fragdedupe != FRAGDEDUPE_OFF) {
-		ret = z_erofs_fragments_dedupe(inode, fd, ictx->tofh);
+		ret = erofs_fragment_findmatch(inode, fd, ictx->tofh);
 		if (ret < 0)
 			return ret;
 		if (inode->fragment_size > ctx->remaining)
@@ -1172,6 +1169,9 @@ int erofs_commit_compressed_file(struct z_erofs_compress_ictx *ictx,
 	int ret;
 
 	if (inode->fragment_size) {
+		ret = erofs_fragment_commit(inode, ictx->tofh);
+		if (ret)
+			goto err_free_idata;
 		inode->z_advise |= Z_EROFS_ADVISE_FRAGMENT_PCLUSTER;
 		erofs_sb_set_fragments(inode->sbi);
 	}
@@ -1210,12 +1210,10 @@ int erofs_commit_compressed_file(struct z_erofs_compress_ictx *ictx,
 		legacymetasize = Z_EROFS_LEGACY_MAP_HEADER_SIZE;
 	}
 
-	if (ptotal) {
+	if (ptotal)
 		(void)erofs_bh_balloon(bh, ptotal);
-	} else {
-		if (!cfg.c_fragments && !cfg.c_dedupe)
-			DBG_BUGON(!inode->idata_size);
-	}
+	else if (!cfg.c_fragments && !cfg.c_dedupe)
+		DBG_BUGON(!inode->idata_size);
 
 	erofs_info("compressed %s (%llu bytes) into %llu bytes",
 		   inode->i_srcpath, inode->i_size | 0ULL, ptotal | 0ULL);
@@ -1629,7 +1627,7 @@ void *erofs_begin_compressed_file(struct erofs_inode *inode, int fd, u64 fpos)
 			 * Handle tails in advance to avoid writing duplicated
 			 * parts into the packed inode.
 			 */
-			ret = z_erofs_fragments_dedupe(inode, fd, ictx->tofh);
+			ret = erofs_fragment_findmatch(inode, fd, ictx->tofh);
 			if (ret < 0)
 				goto err_free_ictx;
 
@@ -1649,7 +1647,7 @@ void *erofs_begin_compressed_file(struct erofs_inode *inode, int fd, u64 fpos)
 	ictx->dedupe = false;
 
 	if (all_fragments && !inode->fragment_size) {
-		ret = z_erofs_pack_file_from_fd(inode, fd, ictx->tofh);
+		ret = erofs_pack_file_from_fd(inode, fd, ictx->tofh);
 		if (ret)
 			goto err_free_idata;
 	}
lib/fragments.c +223 -122

479 lines not on this page · raw message

Signature · 1 line
2.43.5
author
#2 lore raw

PATCH v2 2/5 erofs-utils: lib: keep full data until the fragment is committed

In order to fulfill reproducible builds, let's write all fragments to disk in a specific order, which strictly follows to the committing order.

---
changes since v1:
- limit the total fragment length too to address some rare race leading to unreproducible builds;

 include/erofs/fragments.h |   9 +-
 include/erofs/internal.h  |   1 +
 lib/compress.c            |  26 ++-
 lib/fragments.c           | 350 +++++++++++++++++++++++++-------------
 4 files changed, 246 insertions(+), 140 deletions(-)
include/erofs/fragments.h +5 -4
index 75f1055..112f002 100644
@@ -16,11 +16,12 @@ extern const char *erofs_frags_packedname;
 #define EROFS_PACKED_INODE	erofs_frags_packedname
 
 u32 z_erofs_fragments_tofh(struct erofs_inode *inode, int fd, erofs_off_t fpos);
-int z_erofs_fragments_dedupe(struct erofs_inode *inode, int fd, u32 tofh);
+int erofs_fragment_findmatch(struct erofs_inode *inode, int fd, u32 tofh);
 
-int z_erofs_pack_file_from_fd(struct erofs_inode *inode, int fd, u32 tofcrc);
-int z_erofs_pack_fragments(struct erofs_inode *inode, void *data,
-			   unsigned int len, u32 tofcrc);
+int erofs_pack_file_from_fd(struct erofs_inode *inode, int fd, u32 tofcrc);
+int erofs_fragment_pack(struct erofs_inode *inode, void *data,
+			erofs_off_t pos, erofs_off_t len, u32 tofh, bool tail);
+int erofs_fragment_commit(struct erofs_inode *inode, u32 tofh);
 int erofs_flush_packed_inode(struct erofs_sb_info *sbi);
 int erofs_packedfile(struct erofs_sb_info *sbi);
 
include/erofs/internal.h +1 -0
index 90bee07..73845f1 100644
@@ -272,6 +272,7 @@ struct erofs_inode {
 			union {
 				unsigned int z_idataoff;
 				erofs_off_t fragmentoff;
+				void *fragment;
 			};
 #define z_idata_size	idata_size
 		};
lib/compress.c +12 -14
index a260dc4..706a756 100644
@@ -526,11 +526,8 @@ static bool z_erofs_fixup_deduped_fragment(struct z_erofs_compress_sctx *ctx)
 		return false;
 	}
 
-	inode->fragmentoff += inode->fragment_size - newsize;
 	inode->fragment_size = newsize;
-
-	erofs_dbg("Reducing fragment size to %llu at %llu",
-		  inode->fragment_size | 0ULL, inode->fragmentoff | 0ULL);
+	erofs_dbg("Reducing fragment size to %llu", inode->fragment_size | 0ULL);
 
 	/* it's the end */
 	DBG_BUGON(ctx->tail - ctx->head + ctx->remaining != newsize);
@@ -625,8 +622,8 @@ nocompression:
 		   compressedsize < ctx->pclustersize &&
 		   (!inode->fragment_size || ictx->fix_dedupedfrag)) {
 frag_packing:
-		ret = z_erofs_pack_fragments(inode, ctx->queue + ctx->head,
-					     len, ictx->tofh);
+		ret = erofs_fragment_pack(inode, ctx->queue + ctx->head,
+					  ~0ULL, len, ictx->tofh, false);
 		if (ret < 0)
 			return ret;
 		e->plen = 0;	/* indicate a fragment */
@@ -1103,7 +1100,7 @@ int z_erofs_compress_segment(struct z_erofs_compress_sctx *ctx,
 	DBG_BUGON(offset != -1 && frag && inode->fragment_size);
 	if (offset != -1 && frag && !inode->fragment_size &&
 	    cfg.c_fragdedupe != FRAGDEDUPE_OFF) {
-		ret = z_erofs_fragments_dedupe(inode, fd, ictx->tofh);
+		ret = erofs_fragment_findmatch(inode, fd, ictx->tofh);
 		if (ret < 0)
 			return ret;
 		if (inode->fragment_size > ctx->remaining)
@@ -1172,6 +1169,9 @@ int erofs_commit_compressed_file(struct z_erofs_compress_ictx *ictx,
 	int ret;
 
 	if (inode->fragment_size) {
+		ret = erofs_fragment_commit(inode, ictx->tofh);
+		if (ret)
+			goto err_free_idata;
 		inode->z_advise |= Z_EROFS_ADVISE_FRAGMENT_PCLUSTER;
 		erofs_sb_set_fragments(inode->sbi);
 	}
@@ -1210,12 +1210,10 @@ int erofs_commit_compressed_file(struct z_erofs_compress_ictx *ictx,
 		legacymetasize = Z_EROFS_LEGACY_MAP_HEADER_SIZE;
 	}
 
-	if (ptotal) {
+	if (ptotal)
 		(void)erofs_bh_balloon(bh, ptotal);
-	} else {
-		if (!cfg.c_fragments && !cfg.c_dedupe)
-			DBG_BUGON(!inode->idata_size);
-	}
+	else if (!cfg.c_fragments && !cfg.c_dedupe)
+		DBG_BUGON(!inode->idata_size);
 
 	erofs_info("compressed %s (%llu bytes) into %llu bytes",
 		   inode->i_srcpath, inode->i_size | 0ULL, ptotal | 0ULL);
@@ -1629,7 +1627,7 @@ void *erofs_begin_compressed_file(struct erofs_inode *inode, int fd, u64 fpos)
 			 * Handle tails in advance to avoid writing duplicated
 			 * parts into the packed inode.
 			 */
-			ret = z_erofs_fragments_dedupe(inode, fd, ictx->tofh);
+			ret = erofs_fragment_findmatch(inode, fd, ictx->tofh);
 			if (ret < 0)
 				goto err_free_ictx;
 
@@ -1649,7 +1647,7 @@ void *erofs_begin_compressed_file(struct erofs_inode *inode, int fd, u64 fpos)
 	ictx->dedupe = false;
 
 	if (all_fragments && !inode->fragment_size) {
-		ret = z_erofs_pack_file_from_fd(inode, fd, ictx->tofh);
+		ret = erofs_pack_file_from_fd(inode, fd, ictx->tofh);
 		if (ret)
 			goto err_free_idata;
 	}
lib/fragments.c +228 -122

484 lines not on this page · raw message

Signature · 1 line
2.43.5
author
#3 lore raw

PATCH 3/5 erofs-utils: lib: introduce per-FS compression context

In reply to Gao Xiang

Add a per-FS context for the compression process to maintain multi-bucket fragment queues.

---
 include/erofs/compress.h |  2 +-
 include/erofs/internal.h |  2 ++
 lib/compress.c           | 49 +++++++++++++++++++++++++++-------------
 mkfs/main.c              |  2 +-
 4 files changed, 37 insertions(+), 18 deletions(-)
include/erofs/compress.h +1 -1
index c9831a7..4731a8b 100644
@@ -25,7 +25,7 @@ int erofs_write_compressed_file(struct z_erofs_compress_ictx *ictx);
 
 int z_erofs_compress_init(struct erofs_sb_info *sbi,
 			  struct erofs_buffer_head *bh);
-int z_erofs_compress_exit(void);
+int z_erofs_compress_exit(struct erofs_sb_info *sbi);
 
 const char *z_erofs_list_supported_algorithms(int i, unsigned int *mask);
 const struct erofs_algorithm *z_erofs_list_available_compressors(int *i);
include/erofs/internal.h +2 -0
index 73845f1..e89a1e4 100644
@@ -82,6 +82,7 @@ struct erofs_xattr_prefix_item {
 
 struct erofs_mkfs_dfops;
 struct erofs_packed_inode;
+struct z_erofs_mgr;
 
 struct erofs_sb_info {
 	struct erofs_sb_lz4_info lz4;
@@ -141,6 +142,7 @@ struct erofs_sb_info {
 	struct erofs_mkfs_dfops *mkfs_dfops;
 #endif
 	struct erofs_bufmgr *bmgr;
+	struct z_erofs_mgr *zmgr;
 	struct erofs_packed_inode *packedinode;
 	bool useqpl;
 };
lib/compress.c +33 -16

102 lines not on this page · raw message

mkfs/main.c +1 -1
index 2907789..b2eff9d 100644
@@ -1491,7 +1491,7 @@ int main(int argc, char **argv)
 exit:
 	if (root)
 		erofs_iput(root);
-	z_erofs_compress_exit();
+	z_erofs_compress_exit(&g_sbi);
 	z_erofs_dedupe_exit();
 	z_erofs_dedupe_ext_exit();
 	blklst = erofs_blocklist_close();
Signature · 1 line
2.43.5
author
#4 lore raw

PATCH 4/5 erofs-utils: mkfs: add multi-bucket fragment queues

In reply to Gao Xiang

Group fragments into multiple buckets using their hashed tail-data digest, enabling parallel compression of different buckets.

---
 lib/compress.c | 88 ++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 71 insertions(+), 17 deletions(-)
lib/compress.c +71 -17
index cbc51ca..b6e0c12 100644
@@ -59,7 +59,10 @@ struct z_erofs_compress_ictx {		/* inode context */
 };
 
 struct z_erofs_compress_sctx {		/* segment context */
-	struct list_head extents;
+	union {
+		struct list_head extents;
+		struct list_head sibling;
+	};
 	struct z_erofs_compress_ictx *ictx;
 
 	u8 *queue;
@@ -104,11 +107,18 @@ struct erofs_compress_work {
 };
 
 static struct {
-	struct erofs_workqueue wq, fwq;
+	struct erofs_workqueue wq;
 	struct erofs_compress_work *idle;
 	pthread_mutex_t mutex;
 	bool hasfwq;
 } z_erofs_mt_ctrl;
+
+struct z_erofs_compress_fslot {
+	struct list_head pending;
+	pthread_mutex_t lock;
+	bool inprogress;
+};
+
 #endif
 
 /* compressing configuration specified by users */
@@ -120,6 +130,9 @@ struct erofs_compress_cfg {
 
 struct z_erofs_mgr {
 	struct erofs_compress_cfg ccfg[EROFS_MAX_COMPR_CFGS];
+#ifdef EROFS_MT_ENABLED
+	struct z_erofs_compress_fslot fslot[1024];
+#endif
 };
 
 static bool z_erofs_mt_enabled;
@@ -1364,6 +1377,32 @@ out:
 	pthread_mutex_unlock(&ictx->mutex);
 }
 
+void z_erofs_mt_f_workfn(struct erofs_work *work, void *tlsp)
+{
+	struct erofs_compress_work *cwork = (struct erofs_compress_work *)work;
+	struct erofs_sb_info *sbi = cwork->ctx.ictx->inode->sbi;
+	u32 tofh = cwork->ctx.ictx->tofh;
+	struct z_erofs_compress_fslot *fs = &sbi->zmgr->fslot[tofh & 1023];
+
+	while (1) {
+		z_erofs_mt_workfn(work, tlsp);
+		pthread_mutex_lock(&fs->lock);
+
+		if (list_empty(&fs->pending)) {
+			fs->inprogress = false;
+			pthread_mutex_unlock(&fs->lock);
+			break;
+		}
+		cwork = list_first_entry(&fs->pending,
+					 struct erofs_compress_work,
+					 ctx.sibling);
+		list_del(&cwork->ctx.sibling);
+		pthread_mutex_unlock(&fs->lock);
+		init_list_head(&cwork->ctx.extents);
+		work = &cwork->work;
+	}
+}
+
 int z_erofs_merge_segment(struct z_erofs_compress_ictx *ictx,
 			  struct z_erofs_compress_sctx *sctx)
 {
@@ -1463,19 +1502,32 @@ int z_erofs_mt_compress(struct z_erofs_compress_ictx *ictx)
 		cur->dict_size = ccfg->handle.dict_size;
 		cur->errcode = 1;	/* mark as "in progress" */
 
-		cur->work.fn = z_erofs_mt_workfn;
 		if (i >= nsegs - 1) {
 			cur->ctx.remaining = inode->i_size -
 					inode->fragment_size - (u64)i * segsz;
 
-			if (z_erofs_mt_ctrl.hasfwq) {
-				erofs_queue_work(&z_erofs_mt_ctrl.fwq,
+			if (z_erofs_mt_ctrl.hasfwq && ictx->tofh != ~0U) {
+				struct z_erofs_mgr *zmgr = inode->sbi->zmgr;
+				struct z_erofs_compress_fslot *fs =
+					&zmgr->fslot[ictx->tofh & 1023];
+
+				pthread_mutex_lock(&fs->lock);
+				if (fs->inprogress) {
+					list_add_tail(&cur->ctx.sibling,
+						      &fs->pending);
+				} else {
+					fs->inprogress = true;
+					cur->work.fn = z_erofs_mt_f_workfn;
+					erofs_queue_work(&z_erofs_mt_ctrl.wq,
 						 &cur->work);
+				}
+				pthread_mutex_unlock(&fs->lock);
 				continue;
 			}
 		} else {
 			cur->ctx.remaining = segsz;
 		}
+		cur->work.fn = z_erofs_mt_workfn;
 		erofs_queue_work(&z_erofs_mt_ctrl.wq, &cur->work);
 	}
 	ictx->mtworks = head;
@@ -1548,15 +1600,8 @@ static int z_erofs_mt_init(void)
 		erofs_warn("multi-threaded dedupe is NOT implemented for now");
 		cfg.c_mt_workers = 0;
 	} else {
-		if (cfg.c_fragments && workers > 1) {
-			ret = erofs_alloc_workqueue(&z_erofs_mt_ctrl.fwq, 1, 32,
-						    z_erofs_mt_wq_tls_alloc,
-						    z_erofs_mt_wq_tls_free);
-			if (ret)
-				return ret;
+		if (cfg.c_fragments && workers > 1)
 			z_erofs_mt_ctrl.hasfwq = true;
-			--workers;
-		}
 
 		ret = erofs_alloc_workqueue(&z_erofs_mt_ctrl.wq, workers,
 					    workers << 2,
@@ -1930,7 +1975,19 @@ int z_erofs_compress_init(struct erofs_sb_info *sbi, struct erofs_buffer_head *s
 	}
 
 	z_erofs_mt_enabled = false;
-	return z_erofs_mt_init();
+	ret = z_erofs_mt_init();
+	if (ret)
+		return ret;
+
+#ifdef EROFS_MT_ENABLED
+	if (z_erofs_mt_ctrl.hasfwq) {
+		for (i = 0; i < ARRAY_SIZE(sbi->zmgr->fslot); ++i) {
+			init_list_head(&sbi->zmgr->fslot[i].pending);
+			pthread_mutex_init(&sbi->zmgr->fslot[i].lock, NULL);
+		}
+	}
+#endif
+	return 0;
 }
 
 int z_erofs_compress_exit(struct erofs_sb_info *sbi)
@@ -1951,9 +2008,6 @@ int z_erofs_compress_exit(struct erofs_sb_info *sbi)
 	if (z_erofs_mt_enabled) {
 #ifdef EROFS_MT_ENABLED
 		ret = erofs_destroy_workqueue(&z_erofs_mt_ctrl.wq);
-		if (ret)
-			return ret;
-		ret = erofs_destroy_workqueue(&z_erofs_mt_ctrl.fwq);
 		if (ret)
 			return ret;
 		while (z_erofs_mt_ctrl.idle) {
Signature · 1 line
2.43.5
author
#5 lore raw

PATCH 5/5 erofs-utils: change EROFS_TOF_HASHLEN to 64

In reply to Gao Xiang

The image build time of -Efragments will be greatly reduced.

Processors:   Intel(R) Xeon(R) Platinum 8163 CPU @ 2.50GHz (96 cores)
Memory:       384 GiB
Mkfs options: -zlzma,6 -Efragments -C1048576
 __________________________________________________________________________________
|______ Testset _____|________|_______ Vanilla _________|_________ After __________|
|  CoreOS            |  Size  |__ 660484096 (630 MiB) __|___ 660475904 (630 MiB) __|
|____________________|_ Time _|_______ 4m12.249s _______|_______ 1m49.828s ________|
|  Fedora KIWI       |  Size  |_ 2554892288 (2437 MiB) _|__ 2554793984 (2436 MiB) _|
|____________________|_ Time _|_______ 19m8.141s _______|_______ 6m22.378s ________|

It is now preferred to use -Efragments over -Eall-fragments, since placing all data in the packed inode (-Eall-fragments) could introduce some performance penalty.

---
 lib/fragments.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/fragments.c +1 -1
index ce079af..1f24f70 100644
@@ -31,7 +31,7 @@ struct erofs_fragmentitem {
 };
 
 #define EROFS_FRAGMENT_INMEM_SZ_MAX	(256 * 1024)
-#define EROFS_TOF_HASHLEN		16
+#define EROFS_TOF_HASHLEN		64
 
 #define FRAGMENT_HASHSIZE		65536
 #define FRAGMENT_HASH(c)		((c) & (FRAGMENT_HASHSIZE - 1))
Signature · 1 line
2.43.5