]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
xfs: add a fast path to xfs_buf_zero when b_addr is set
authorChristoph Hellwig <hch@lst.de>
Mon, 10 Mar 2025 13:19:05 +0000 (14:19 +0100)
committerCarlos Maiolino <cem@kernel.org>
Mon, 10 Mar 2025 13:29:44 +0000 (14:29 +0100)
No need to walk the page list if bp->b_addr is valid.  That also means
b_offset doesn't need to be taken into account in the unmapped loop as
b_offset is only set for kmem backed buffers which are always mapped.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
fs/xfs/xfs_buf.c

index 5d560e9073f4236f8f03830a1485a00cc234c22c..ba0bdff3ad5742b3bae8a2b517bfddde6f7bac7a 100644 (file)
@@ -1633,13 +1633,18 @@ xfs_buf_zero(
 {
        size_t                  bend;
 
+       if (bp->b_addr) {
+               memset(bp->b_addr + boff, 0, bsize);
+               return;
+       }
+
        bend = boff + bsize;
        while (boff < bend) {
                struct page     *page;
                int             page_index, page_offset, csize;
 
-               page_index = (boff + bp->b_offset) >> PAGE_SHIFT;
-               page_offset = (boff + bp->b_offset) & ~PAGE_MASK;
+               page_index = boff >> PAGE_SHIFT;
+               page_offset = boff & ~PAGE_MASK;
                page = bp->b_pages[page_index];
                csize = min_t(size_t, PAGE_SIZE - page_offset,
                                      BBTOB(bp->b_length) - boff);