All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC 0/2] add FALLOC_FL_WRITE_ZEROES support to xfs
@ 2026-02-27 14:08 Pankaj Raghav
  2026-02-27 14:08 ` [RFC 1/2] xfs: add flags field to xfs_alloc_file_space Pankaj Raghav
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Pankaj Raghav @ 2026-02-27 14:08 UTC (permalink / raw)
  To: linux-xfs
  Cc: bfoster, dchinner, Darrick J . Wong, p.raghav, gost.dev,
	pankaj.raghav, andres, cem, hch, lucas

The benefits of FALLOC_FL_WRITE_ZEROES was already discussed as a part
of Zhang Yi's initial patches[1]. Postgres developer Andres also
mentioned they would like to use this feature in Postgres [2].

Lukas Herbolt sent a patch recently that adds this support but I found
some issues with them[3]. I independtly started working on these patches
a while back as well, so I thought maybe I will send a RFC version of
this support.

I have implemented this support similar to what ext4 is doing: write unwritten
extents first, increase the size of the file, then zero out those extents
with XFS_BMAPI_CONVERT with XFS_BMAPI_ZERO. This seems to be working
correctly without changing any of the core infrastructure. But I am not
sure if this is the most efficient way of doing it in XFS or if there
are some corner cases I am missing, so any feedback is welcome.

[1] https://lore.kernel.org/linux-fsdevel/20250619111806.3546162-1-yi.zhang@huaweicloud.com/
[2] https://lore.kernel.org/linux-fsdevel/20260217055103.GA6174@lst.de/T/#m7935b9bab32bb5ff372507f84803b8753ad1c814
[3] https://lore.kernel.org/linux-xfs/wmxdwtvahubdga73cgzprqtj7fxyjgx5kxvr4cobtl6ski2i6y@ic2g3bfymkwi/

=== Testing ===:

void test_fallocate(const char *filename, int mode, const char *mode_name) {
    int fd;

    printf("Testing %s on %s...\n", mode_name, filename);

    unlink(filename);

    fd = open(filename, O_RDWR | O_CREAT, 0666);
    if (fd < 0) {
        perror("open failed");
        return;
    }

    if (fallocate(fd, mode, 0, TEST_SIZE) == 0) {
        printf(" -> fallocate(%s) succeeded!\n", mode_name);
    } else {
        printf(" -> fallocate(%s) failed: %s\n", mode_name, strerror(errno));
    }

    close(fd);

    /* Dump extent info using xfs_io */
    char cmd[256];
    snprintf(cmd, sizeof(cmd), "xfs_io -c 'bmap -vvp' %s", filename);
    printf("=== Extents for %s ===\n", filename);
    system(cmd);
    printf("\n");
}

int main() {
    printf("Starting fallocate tests...\n");
    printf("------------------------------------------------\n\n");

    test_fallocate("test_zero_range.bin", FALLOC_FL_ZERO_RANGE, "FALLOC_FL_ZERO_RANGE");
    test_fallocate("test_write_zeroes.bin", FALLOC_FL_WRITE_ZEROES, "FALLOC_FL_WRITE_ZEROES");

    printf("Test complete.\n");
    return 0;
}

This is the output:

root@debian:/mnt# ~/home/write_zeroes /mnt/hello
Starting fallocate tests...
------------------------------------------------

Testing FALLOC_FL_ZERO_RANGE on test_zero_range.bin...
 -> fallocate(FALLOC_FL_ZERO_RANGE) succeeded!
=== Extents for test_zero_range.bin ===
test_zero_range.bin:
 EXT: FILE-OFFSET      BLOCK-RANGE      AG AG-OFFSET        TOTAL FLAGS
   0: [0..20479]:      20672..41151      0 (20672..41151)   20480 010000
 FLAG Values:
    0100000 Shared extent
    0010000 Unwritten preallocated extent
    0001000 Doesn't begin on stripe unit
    0000100 Doesn't end   on stripe unit
    0000010 Doesn't begin on stripe width
    0000001 Doesn't end   on stripe width

Testing FALLOC_FL_WRITE_ZEROES on test_write_zeroes.bin...
 -> fallocate(FALLOC_FL_WRITE_ZEROES) succeeded!
=== Extents for test_write_zeroes.bin ===
test_write_zeroes.bin:
 EXT: FILE-OFFSET      BLOCK-RANGE      AG AG-OFFSET        TOTAL FLAGS
   0: [0..20479]:      41152..61631      0 (41152..61631)   20480 000000
 FLAG Values:
    0100000 Shared extent
    0010000 Unwritten preallocated extent
    0001000 Doesn't begin on stripe unit
    0000100 Doesn't end   on stripe unit
    0000010 Doesn't begin on stripe width
    0000001 Doesn't end   on stripe width

Pankaj Raghav (2):
  xfs: add flags field to xfs_alloc_file_space
  xfs: add support for FALLOC_FL_WRITE_ZEROES

 fs/xfs/xfs_bmap_util.c |  5 ++--
 fs/xfs/xfs_bmap_util.h |  2 +-
 fs/xfs/xfs_file.c      | 64 +++++++++++++++++++++++++++++++++++++++---
 3 files changed, 64 insertions(+), 7 deletions(-)


base-commit: 4d750717498bbc1d8801281c32453a5f23d0bbe8
-- 
2.50.1


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

end of thread, other threads:[~2026-03-04 19:58 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-27 14:08 [RFC 0/2] add FALLOC_FL_WRITE_ZEROES support to xfs Pankaj Raghav
2026-02-27 14:08 ` [RFC 1/2] xfs: add flags field to xfs_alloc_file_space Pankaj Raghav
2026-03-03 15:24   ` Christoph Hellwig
2026-03-04  8:20     ` Pankaj Raghav (Samsung)
2026-03-04  8:31       ` Pankaj Raghav (Samsung)
2026-03-04  9:31       ` Carlos Maiolino
2026-03-04  9:46         ` Pankaj Raghav
2026-03-04 14:39           ` Lukas Herbolt
2026-03-04 19:57             ` Pankaj Raghav (Samsung)
2026-02-27 14:08 ` [RFC 2/2] xfs: add support for FALLOC_FL_WRITE_ZEROES Pankaj Raghav
2026-02-27 16:26 ` [RFC 0/2] add FALLOC_FL_WRITE_ZEROES support to xfs Pankaj Raghav (Samsung)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.