public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Add FL_WRITE_ZEROES to XFS, fix krealloc on xfs_uuid_table
@ 2025-10-21 14:17 Lukas Herbolt
  2025-10-21 14:17 ` [PATCH] xfs: add FALLOC_FL_WRITE_ZEROES to XFS code base Lukas Herbolt
  2025-10-21 14:17 ` [PATCH 2/2] xfs: Remove WARN_ONCE if xfs_uuid_table grows over 2x PAGE_SIZE Lukas Herbolt
  0 siblings, 2 replies; 29+ messages in thread
From: Lukas Herbolt @ 2025-10-21 14:17 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, Lukas Herbolt

[PATCH 1/2] xfs: add FALLOC_FL_WRITE_ZEROES to XFS code base
Add support for FALLOC_FL_WRITE_ZEROES if the underlying device enable
the unmap write zeroes operation.

Inspired by the Ext4 implementation of the FALLOC_FL_WRITE_ZEROES. It
can speed up some patterns on specific hardware.

time ( ./fallocate -l 360M /mnt/test.file; dd if=/dev/zero of=/mnt/test \
bs=1M count=360 conv=notrunc,nocreat oflag=direct,dsync)

360+0 records in
360+0 records out
377487360 bytes (377 MB, 360 MiB) copied, 22.0027 s, 17.2 MB/s

real    0m22.114s
user    0m0.006s
sys     0m3.085s

time (./fallocate -wl 360M /mnt/test.file; dd if=/dev/zero of=/mnt/test \
bs=1M count=360 conv=notrunc,nocreat oflag=direct,dsync );
360+0 records in
360+0 records out
377487360 bytes (377 MB, 360 MiB) copied, 2.02512 s, 186 MB/s

real    0m6.384s
user    0m0.002s
sys     0m5.823s

v2 changes:
use xfs_inode_buftarg to determine if the underlying device supports unmap 
write zeroes
v1 patch: 
https://lore.kernel.org/linux-xfs/20251002122823.1875398-2-lukas@herbolt.com/

[PATCH 2/2] xfs: Remove WARN_ONCE if xfs_uuid_table grows over 2x PAGE_SIZE.
Currently using krealloc prints warning if the order is 2x PAGE_SIZE on 
x86_64 it's being trigered when we mount 511 XFS. Use kvrealloc instead.

Lukas Herbolt (2):
  xfs: add FALLOC_FL_WRITE_ZEROES to XFS code base
  xfs: Remove WARN_ONCE if xfs_uuid_table grows over 2x PAGE_SIZE.

 fs/xfs/xfs_bmap_util.c |  6 +++---
 fs/xfs/xfs_bmap_util.h |  4 ++--
 fs/xfs/xfs_file.c      | 25 ++++++++++++++++++-------
 fs/xfs/xfs_mount.c     |  2 +-
 4 files changed, 24 insertions(+), 13 deletions(-)

-- 
2.51.0


^ permalink raw reply	[flat|nested] 29+ messages in thread
* [PATCH] xfs: add FALLOC_FL_WRITE_ZEROES to XFS code base
@ 2026-02-12 13:12 Lukas Herbolt
  2026-02-12 13:15 ` Lukas Herbolt
  0 siblings, 1 reply; 29+ messages in thread
From: Lukas Herbolt @ 2026-02-12 13:12 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, Lukas Herbolt

Add support for FALLOC_FL_WRITE_ZEROES if the underlying device enable
the unmap write zeroes operation.

Signed-off-by: Lukas Herbolt <lukas@herbolt.com>
---
 fs/xfs/xfs_bmap_util.c | 10 ++++++++--
 fs/xfs/xfs_bmap_util.h |  2 +-
 fs/xfs/xfs_file.c      | 39 ++++++++++++++++++++++++++-------------
 3 files changed, 35 insertions(+), 16 deletions(-)

diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 2208a720ec3f..942d35743b82 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -642,11 +642,17 @@ xfs_free_eofblocks(
 	return error;
 }
 
+/*
+ * Callers can specify bmapi_flags, if XFS_BMAPI_ZERO is used there are no
+ * further checks whether the hard ware supports and it can fallback to
+ * software zeroing.
+ */
 int
 xfs_alloc_file_space(
 	struct xfs_inode	*ip,
 	xfs_off_t		offset,
-	xfs_off_t		len)
+	xfs_off_t		len,
+	uint32_t		bmapi_flags)
 {
 	xfs_mount_t		*mp = ip->i_mount;
 	xfs_off_t		count;
@@ -748,7 +754,7 @@ xfs_alloc_file_space(
 		 * will eventually reach the requested range.
 		 */
 		error = xfs_bmapi_write(tp, ip, startoffset_fsb,
-				allocatesize_fsb, XFS_BMAPI_PREALLOC, 0, imapp,
+				allocatesize_fsb, bmapi_flags, 0, imapp,
 				&nimaps);
 		if (error) {
 			if (error != -ENOSR)
diff --git a/fs/xfs/xfs_bmap_util.h b/fs/xfs/xfs_bmap_util.h
index c477b3361630..2895cc97a572 100644
--- a/fs/xfs/xfs_bmap_util.h
+++ b/fs/xfs/xfs_bmap_util.h
@@ -56,7 +56,7 @@ int	xfs_bmap_last_extent(struct xfs_trans *tp, struct xfs_inode *ip,
 
 /* preallocation and hole punch interface */
 int	xfs_alloc_file_space(struct xfs_inode *ip, xfs_off_t offset,
-		xfs_off_t len);
+		xfs_off_t len, uint32_t bmapi_flags);
 int	xfs_free_file_space(struct xfs_inode *ip, xfs_off_t offset,
 		xfs_off_t len, struct xfs_zone_alloc_ctx *ac);
 int	xfs_collapse_file_space(struct xfs_inode *, xfs_off_t offset,
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 7874cf745af3..2535db43ff25 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -1293,6 +1293,7 @@ xfs_falloc_zero_range(
 	unsigned int		blksize = i_blocksize(inode);
 	loff_t			new_size = 0;
 	int			error;
+	uint32_t                bmapi_flags;
 
 	trace_xfs_zero_file_space(ip);
 
@@ -1300,18 +1301,27 @@ xfs_falloc_zero_range(
 	if (error)
 		return error;
 
-	if (xfs_falloc_force_zero(ip, ac)) {
-		error = xfs_zero_range(ip, offset, len, ac, NULL);
-	} else {
-		error = xfs_free_file_space(ip, offset, len, ac);
-		if (error)
-			return error;
 
-		len = round_up(offset + len, blksize) -
-			round_down(offset, blksize);
-		offset = round_down(offset, blksize);
-		error = xfs_alloc_file_space(ip, offset, len);
+	if (mode & FALLOC_FL_WRITE_ZEROES) {
+		if (xfs_is_always_cow_inode(ip) ||
+		    !bdev_write_zeroes_unmap_sectors(
+			xfs_inode_buftarg(ip)->bt_bdev))
+			return -EOPNOTSUPP;
+		bmapi_flags = XFS_BMAPI_ZERO;
+	} else {
+		if (xfs_falloc_force_zero(ip, ac)) {
+			error = xfs_zero_range(ip, offset, len, ac, NULL);
+			goto set_filesize;
+		}
+		bmapi_flags = XFS_BMAPI_PREALLOC;
 	}
+
+	len = round_up(offset + len, blksize) - round_down(offset, blksize);
+	offset = round_down(offset, blksize);
+
+	error = xfs_alloc_file_space(ip, offset, len, bmapi_flags);
+
+set_filesize:
 	if (error)
 		return error;
 	return xfs_falloc_setsize(file, new_size);
@@ -1336,7 +1346,8 @@ xfs_falloc_unshare_range(
 	if (error)
 		return error;
 
-	error = xfs_alloc_file_space(XFS_I(inode), offset, len);
+	error = xfs_alloc_file_space(XFS_I(inode), offset, len,
+			XFS_BMAPI_PREALLOC);
 	if (error)
 		return error;
 	return xfs_falloc_setsize(file, new_size);
@@ -1364,7 +1375,8 @@ xfs_falloc_allocate_range(
 	if (error)
 		return error;
 
-	error = xfs_alloc_file_space(XFS_I(inode), offset, len);
+	error = xfs_alloc_file_space(XFS_I(inode), offset, len,
+			XFS_BMAPI_PREALLOC);
 	if (error)
 		return error;
 	return xfs_falloc_setsize(file, new_size);
@@ -1374,7 +1386,7 @@ xfs_falloc_allocate_range(
 		(FALLOC_FL_ALLOCATE_RANGE | FALLOC_FL_KEEP_SIZE |	\
 		 FALLOC_FL_PUNCH_HOLE |	FALLOC_FL_COLLAPSE_RANGE |	\
 		 FALLOC_FL_ZERO_RANGE |	FALLOC_FL_INSERT_RANGE |	\
-		 FALLOC_FL_UNSHARE_RANGE)
+		 FALLOC_FL_UNSHARE_RANGE | FALLOC_FL_WRITE_ZEROES)
 
 STATIC long
 __xfs_file_fallocate(
@@ -1417,6 +1429,7 @@ __xfs_file_fallocate(
 	case FALLOC_FL_INSERT_RANGE:
 		error = xfs_falloc_insert_range(file, offset, len);
 		break;
+	case FALLOC_FL_WRITE_ZEROES:
 	case FALLOC_FL_ZERO_RANGE:
 		error = xfs_falloc_zero_range(file, mode, offset, len, ac);
 		break;

base-commit: 05f7e89ab9731565d8a62e3b5d1ec206485eeb0b
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 29+ messages in thread
* [PATCH] xfs: add FALLOC_FL_WRITE_ZEROES to XFS code base
@ 2026-02-25  8:37 Lukas Herbolt
  2026-02-25  8:41 ` Lukas Herbolt
  0 siblings, 1 reply; 29+ messages in thread
From: Lukas Herbolt @ 2026-02-25  8:37 UTC (permalink / raw)
  To: linux-xfs, djwong; +Cc: cem, hch, Lukas Herbolt

Add support for FALLOC_FL_WRITE_ZEROES if the underlying device enable
the unmap write zeroes operation.

Signed-off-by: Lukas Herbolt <lukas@herbolt.com>
---
 fs/xfs/xfs_bmap_util.c |  5 +++--
 fs/xfs/xfs_bmap_util.h |  2 +-
 fs/xfs/xfs_file.c      | 43 +++++++++++++++++++++++++++++-------------
 3 files changed, 34 insertions(+), 16 deletions(-)

diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 2208a720ec3f..0c1b1fa82f8b 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -646,7 +646,8 @@ int
 xfs_alloc_file_space(
 	struct xfs_inode	*ip,
 	xfs_off_t		offset,
-	xfs_off_t		len)
+	xfs_off_t		len,
+	uint32_t		bmapi_flags)
 {
 	xfs_mount_t		*mp = ip->i_mount;
 	xfs_off_t		count;
@@ -748,7 +749,7 @@ xfs_alloc_file_space(
 		 * will eventually reach the requested range.
 		 */
 		error = xfs_bmapi_write(tp, ip, startoffset_fsb,
-				allocatesize_fsb, XFS_BMAPI_PREALLOC, 0, imapp,
+				allocatesize_fsb, bmapi_flags, 0, imapp,
 				&nimaps);
 		if (error) {
 			if (error != -ENOSR)
diff --git a/fs/xfs/xfs_bmap_util.h b/fs/xfs/xfs_bmap_util.h
index c477b3361630..2895cc97a572 100644
--- a/fs/xfs/xfs_bmap_util.h
+++ b/fs/xfs/xfs_bmap_util.h
@@ -56,7 +56,7 @@ int	xfs_bmap_last_extent(struct xfs_trans *tp, struct xfs_inode *ip,
 
 /* preallocation and hole punch interface */
 int	xfs_alloc_file_space(struct xfs_inode *ip, xfs_off_t offset,
-		xfs_off_t len);
+		xfs_off_t len, uint32_t bmapi_flags);
 int	xfs_free_file_space(struct xfs_inode *ip, xfs_off_t offset,
 		xfs_off_t len, struct xfs_zone_alloc_ctx *ac);
 int	xfs_collapse_file_space(struct xfs_inode *, xfs_off_t offset,
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 7874cf745af3..1ba4f449edb3 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -1293,6 +1293,7 @@ xfs_falloc_zero_range(
 	unsigned int		blksize = i_blocksize(inode);
 	loff_t			new_size = 0;
 	int			error;
+	uint32_t                bmapi_flags;
 
 	trace_xfs_zero_file_space(ip);
 
@@ -1300,18 +1301,31 @@ xfs_falloc_zero_range(
 	if (error)
 		return error;
 
-	if (xfs_falloc_force_zero(ip, ac)) {
-		error = xfs_zero_range(ip, offset, len, ac, NULL);
-	} else {
-		error = xfs_free_file_space(ip, offset, len, ac);
-		if (error)
-			return error;
 
-		len = round_up(offset + len, blksize) -
-			round_down(offset, blksize);
-		offset = round_down(offset, blksize);
-		error = xfs_alloc_file_space(ip, offset, len);
+	if (mode & FALLOC_FL_WRITE_ZEROES) {
+		if (xfs_is_always_cow_inode(ip) ||
+		    !bdev_write_zeroes_unmap_sectors(
+				xfs_inode_buftarg(ip)->bt_bdev))
+			return -EOPNOTSUPP;
+		bmapi_flags = XFS_BMAPI_ZERO;
+	} else {
+		if (xfs_falloc_force_zero(ip, ac)) {
+			error = xfs_zero_range(ip, offset, len, ac, NULL);
+			goto set_filesize;
+		} else {
+			error = xfs_free_file_space(ip, offset, len, ac);
+			if (error)
+				return error;
+		}
+		bmapi_flags = XFS_BMAPI_PREALLOC;
 	}
+
+	len = round_up(offset + len, blksize) - round_down(offset, blksize);
+	offset = round_down(offset, blksize);
+
+	error = xfs_alloc_file_space(ip, offset, len, bmapi_flags);
+
+set_filesize:
 	if (error)
 		return error;
 	return xfs_falloc_setsize(file, new_size);
@@ -1336,7 +1350,8 @@ xfs_falloc_unshare_range(
 	if (error)
 		return error;
 
-	error = xfs_alloc_file_space(XFS_I(inode), offset, len);
+	error = xfs_alloc_file_space(XFS_I(inode), offset, len,
+			XFS_BMAPI_PREALLOC);
 	if (error)
 		return error;
 	return xfs_falloc_setsize(file, new_size);
@@ -1364,7 +1379,8 @@ xfs_falloc_allocate_range(
 	if (error)
 		return error;
 
-	error = xfs_alloc_file_space(XFS_I(inode), offset, len);
+	error = xfs_alloc_file_space(XFS_I(inode), offset, len,
+			XFS_BMAPI_PREALLOC);
 	if (error)
 		return error;
 	return xfs_falloc_setsize(file, new_size);
@@ -1374,7 +1390,7 @@ xfs_falloc_allocate_range(
 		(FALLOC_FL_ALLOCATE_RANGE | FALLOC_FL_KEEP_SIZE |	\
 		 FALLOC_FL_PUNCH_HOLE |	FALLOC_FL_COLLAPSE_RANGE |	\
 		 FALLOC_FL_ZERO_RANGE |	FALLOC_FL_INSERT_RANGE |	\
-		 FALLOC_FL_UNSHARE_RANGE)
+		 FALLOC_FL_UNSHARE_RANGE | FALLOC_FL_WRITE_ZEROES)
 
 STATIC long
 __xfs_file_fallocate(
@@ -1417,6 +1433,7 @@ __xfs_file_fallocate(
 	case FALLOC_FL_INSERT_RANGE:
 		error = xfs_falloc_insert_range(file, offset, len);
 		break;
+	case FALLOC_FL_WRITE_ZEROES:
 	case FALLOC_FL_ZERO_RANGE:
 		error = xfs_falloc_zero_range(file, mode, offset, len, ac);
 		break;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2026-02-25  8:41 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-21 14:17 [PATCH 0/2] Add FL_WRITE_ZEROES to XFS, fix krealloc on xfs_uuid_table Lukas Herbolt
2025-10-21 14:17 ` [PATCH] xfs: add FALLOC_FL_WRITE_ZEROES to XFS code base Lukas Herbolt
2025-10-21 15:55   ` Darrick J. Wong
2025-10-22  5:00   ` Christoph Hellwig
2025-10-22  7:13     ` Zhang Yi
2025-10-22  7:15       ` Christoph Hellwig
2025-10-22  7:27         ` Zhang Yi
2025-10-29 17:53           ` [PATCH v3] " Lukas Herbolt
2025-10-29 18:22             ` Darrick J. Wong
2025-10-30  7:27               ` Christoph Hellwig
2025-11-12 21:02                 ` [PATCH v4] " Lukas Herbolt
2025-11-13  6:59                   ` Christoph Hellwig
2025-11-14  8:55                     ` [PATCH v5] " Lukas Herbolt
2025-11-14  8:57                       ` Christoph Hellwig
2025-11-14 16:44                       ` Darrick J. Wong
2025-11-14 16:45                         ` Christoph Hellwig
2025-11-18  9:05                           ` lukas
2025-12-15 11:48                           ` [PATCH v6] " Lukas Herbolt
2025-12-15 14:28                             ` Christoph Hellwig
2025-10-30  7:29             ` [PATCH v3] " Christoph Hellwig
2025-10-21 14:17 ` [PATCH 2/2] xfs: Remove WARN_ONCE if xfs_uuid_table grows over 2x PAGE_SIZE Lukas Herbolt
2025-10-21 15:56   ` Darrick J. Wong
2025-10-21 22:02   ` Dave Chinner
2025-10-26 17:49     ` lukas
2025-10-22  4:53   ` Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2026-02-12 13:12 [PATCH] xfs: add FALLOC_FL_WRITE_ZEROES to XFS code base Lukas Herbolt
2026-02-12 13:15 ` Lukas Herbolt
2026-02-25  8:37 Lukas Herbolt
2026-02-25  8:41 ` Lukas Herbolt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox