[PATCH v1] erofs-utils: mkfs: Implement 'dsunit' alignment on blobdev

Friendy Su friendy.su at sony.com
Wed Aug 20 17:23:52 AEST 2025


Set proper 'dsunit' to let file body align on huge page on blobdev,

where 'dsunit' * 'blocksize' = huge page size (2M).

When do mmap() a file mounted with dax=always, aligning on huge page
makes kernel map huge page(2M) per page fault exception, compared with
mapping normal page(4K) per page fault.

This greatly improves mmap() performance by reducing times of page
fault being triggered.

Signed-off-by: Friendy Su <friendy.su at sony.com>
Reviewed-by: Yuezhang Mo <Yuezhang.Mo at sony.com>
Reviewed-by: Daniel Palmer <daniel.palmer at sony.com>
---
 lib/blobchunk.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/lib/blobchunk.c b/lib/blobchunk.c
index bbc69cf..e47afb5 100644
--- a/lib/blobchunk.c
+++ b/lib/blobchunk.c
@@ -309,6 +309,21 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd,
 	minextblks = BLK_ROUND_UP(sbi, inode->i_size);
 	interval_start = 0;
 
+	/* Align file on 'dsunit' */
+	if (sbi->bmgr->dsunit > 1) {
+		off_t off = lseek(blobfile, 0, SEEK_CUR);
+
+		erofs_dbg("Try to round up 0x%llx to align on %d blocks (dsunit)",
+				off, sbi->bmgr->dsunit);
+		off = roundup(off, sbi->bmgr->dsunit * erofs_blksiz(sbi));
+		if (lseek(blobfile, off, SEEK_SET) != off) {
+			ret = -errno;
+			erofs_err("lseek to blobdev 0x%llx error", off);
+			goto err;
+		}
+		erofs_dbg("Aligned on 0x%llx", off);
+	}
+
 	for (pos = 0; pos < inode->i_size; pos += len) {
 #ifdef SEEK_DATA
 		off_t offset = lseek(fd, pos + startoff, SEEK_DATA);
-- 
2.34.1



More information about the Linux-erofs mailing list