From: Ernest Borowski iomap_write_delalloc_ifs_punch() calls ->punch() once for every clean block of a dirty folio. A file system that reserves delayed allocation space in units larger than a block can release a unit only when one call covers it whole. ntfs reserves whole clusters and uses 512 byte blocks, so with 1 KiB clusters a buffered write into a hole that fails after zeroing the first cluster of a 4 KiB folio leaves the other three clusters of that folio reserved, and writeback later allocates them. Pass each run of contiguous clean blocks to ->punch() in one call. XFS and ext4 punch any range they are given, so for them this only means fewer calls. "ntfs: punch out the delalloc reservation of a failed buffered write" later in this series needs this, so it goes to stable with it. Cc: stable@vger.kernel.org Signed-off-by: Ernest Borowski --- fs/iomap/buffered-io.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 25915c0f5e..b6dd56f1bd 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1364,6 +1364,9 @@ static void iomap_write_delalloc_ifs_punch(struct inode *inode, * blocks within a folio which are marked uptodate * but not dirty. In that case it is necessary to punch * out such blocks to avoid leaking any delalloc blocks. + * Pass each run of clean blocks in one call: a file system + * that reserves space in units larger than a block can only + * release a unit that it sees whole. */ ifs = folio->private; if (!ifs) @@ -1374,9 +1377,13 @@ static void iomap_write_delalloc_ifs_punch(struct inode *inode, last_blk = offset_in_folio(folio, last_byte) >> blkbits; while ((first_blk = ifs_next_clean_block(folio, first_blk, last_blk)) <= last_blk) { - punch(inode, folio_pos(folio) + (first_blk << blkbits), - 1 << blkbits, iomap); - first_blk++; + loff_t pos = folio_pos(folio) + (first_blk << blkbits); + unsigned int next_blk; + + next_blk = ifs_next_dirty_block(folio, first_blk + 1, last_blk); + punch(inode, pos, (loff_t)(next_blk - first_blk) << blkbits, + iomap); + first_blk = next_blk; } } -- 2.56.1