From: "Darrick J. Wong" <djwong@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Carlos Maiolino <cem@kernel.org>,
Dave Chinner <dchinner@redhat.com>,
linux-xfs@vger.kernel.org
Subject: Re: [PATCH 11/12] xfs: cleanup mapping tmpfs folios into the buffer cache
Date: Wed, 5 Mar 2025 10:34:51 -0800 [thread overview]
Message-ID: <20250305183451.GL2803749@frogsfrogsfrogs> (raw)
In-Reply-To: <20250305140532.158563-12-hch@lst.de>
On Wed, Mar 05, 2025 at 07:05:28AM -0700, Christoph Hellwig wrote:
> Directly assign b_addr based on the tmpfs folios without a detour
> through pages, reuse the folio_put path used for non-tmpfs buffers
> and replace all references to pages in comments with folios.
>
> Partially based on a patch from Dave Chinner <dchinner@redhat.com>.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Seems fine to me, so
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
--D
> ---
> fs/xfs/xfs_buf.c | 6 ++----
> fs/xfs/xfs_buf_mem.c | 34 ++++++++++------------------------
> fs/xfs/xfs_buf_mem.h | 6 ++----
> 3 files changed, 14 insertions(+), 32 deletions(-)
>
> diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
> index f28ca5cb5bd8..c7f4cafda705 100644
> --- a/fs/xfs/xfs_buf.c
> +++ b/fs/xfs/xfs_buf.c
> @@ -206,9 +206,7 @@ xfs_buf_free(
> if (!xfs_buftarg_is_mem(bp->b_target) && size >= PAGE_SIZE)
> mm_account_reclaimed_pages(howmany(size, PAGE_SHIFT));
>
> - if (xfs_buftarg_is_mem(bp->b_target))
> - xmbuf_unmap_page(bp);
> - else if (is_vmalloc_addr(bp->b_addr))
> + if (is_vmalloc_addr(bp->b_addr))
> vfree(bp->b_addr);
> else if (bp->b_flags & _XBF_KMEM)
> kfree(bp->b_addr);
> @@ -275,7 +273,7 @@ xfs_buf_alloc_backing_mem(
> struct folio *folio;
>
> if (xfs_buftarg_is_mem(bp->b_target))
> - return xmbuf_map_page(bp);
> + return xmbuf_map_backing_mem(bp);
>
> /* Assure zeroed buffer for non-read cases. */
> if (!(flags & XBF_READ))
> diff --git a/fs/xfs/xfs_buf_mem.c b/fs/xfs/xfs_buf_mem.c
> index b207754d2ee0..b4ffd80b7cb6 100644
> --- a/fs/xfs/xfs_buf_mem.c
> +++ b/fs/xfs/xfs_buf_mem.c
> @@ -74,7 +74,7 @@ xmbuf_alloc(
>
> /*
> * We don't want to bother with kmapping data during repair, so don't
> - * allow highmem pages to back this mapping.
> + * allow highmem folios to back this mapping.
> */
> mapping_set_gfp_mask(inode->i_mapping, GFP_KERNEL);
>
> @@ -127,14 +127,13 @@ xmbuf_free(
> kfree(btp);
> }
>
> -/* Directly map a shmem page into the buffer cache. */
> +/* Directly map a shmem folio into the buffer cache. */
> int
> -xmbuf_map_page(
> +xmbuf_map_backing_mem(
> struct xfs_buf *bp)
> {
> struct inode *inode = file_inode(bp->b_target->bt_file);
> struct folio *folio = NULL;
> - struct page *page;
> loff_t pos = BBTOB(xfs_buf_daddr(bp));
> int error;
>
> @@ -159,30 +158,17 @@ xmbuf_map_page(
> return -EIO;
> }
>
> - page = folio_file_page(folio, pos >> PAGE_SHIFT);
> -
> /*
> - * Mark the page dirty so that it won't be reclaimed once we drop the
> - * (potentially last) reference in xmbuf_unmap_page.
> + * Mark the folio dirty so that it won't be reclaimed once we drop the
> + * (potentially last) reference in xfs_buf_free.
> */
> - set_page_dirty(page);
> - unlock_page(page);
> + folio_set_dirty(folio);
> + folio_unlock(folio);
>
> - bp->b_addr = page_address(page);
> + bp->b_addr = folio_address(folio);
If tmpfs gives us a large folio, don't we need to add offset_in_folio to
b_addr? Or does this just work and xfs/801 (aka force the use of
hugepages on tmpfs) passes with no complaints?
--D
> return 0;
> }
>
> -/* Unmap a shmem page that was mapped into the buffer cache. */
> -void
> -xmbuf_unmap_page(
> - struct xfs_buf *bp)
> -{
> - ASSERT(xfs_buftarg_is_mem(bp->b_target));
> -
> - put_page(virt_to_page(bp->b_addr));
> - bp->b_addr = NULL;
> -}
> -
> /* Is this a valid daddr within the buftarg? */
> bool
> xmbuf_verify_daddr(
> @@ -196,7 +182,7 @@ xmbuf_verify_daddr(
> return daddr < (inode->i_sb->s_maxbytes >> BBSHIFT);
> }
>
> -/* Discard the page backing this buffer. */
> +/* Discard the folio backing this buffer. */
> static void
> xmbuf_stale(
> struct xfs_buf *bp)
> @@ -211,7 +197,7 @@ xmbuf_stale(
> }
>
> /*
> - * Finalize a buffer -- discard the backing page if it's stale, or run the
> + * Finalize a buffer -- discard the backing folio if it's stale, or run the
> * write verifier to detect problems.
> */
> int
> diff --git a/fs/xfs/xfs_buf_mem.h b/fs/xfs/xfs_buf_mem.h
> index eed4a7b63232..67d525cc1513 100644
> --- a/fs/xfs/xfs_buf_mem.h
> +++ b/fs/xfs/xfs_buf_mem.h
> @@ -19,16 +19,14 @@ int xmbuf_alloc(struct xfs_mount *mp, const char *descr,
> struct xfs_buftarg **btpp);
> void xmbuf_free(struct xfs_buftarg *btp);
>
> -int xmbuf_map_page(struct xfs_buf *bp);
> -void xmbuf_unmap_page(struct xfs_buf *bp);
> bool xmbuf_verify_daddr(struct xfs_buftarg *btp, xfs_daddr_t daddr);
> void xmbuf_trans_bdetach(struct xfs_trans *tp, struct xfs_buf *bp);
> int xmbuf_finalize(struct xfs_buf *bp);
> #else
> # define xfs_buftarg_is_mem(...) (false)
> -# define xmbuf_map_page(...) (-ENOMEM)
> -# define xmbuf_unmap_page(...) ((void)0)
> # define xmbuf_verify_daddr(...) (false)
> #endif /* CONFIG_XFS_MEMORY_BUFS */
>
> +int xmbuf_map_backing_mem(struct xfs_buf *bp);
> +
> #endif /* __XFS_BUF_MEM_H__ */
> --
> 2.45.2
>
>
next prev parent reply other threads:[~2025-03-05 18:34 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-05 14:05 use folios and vmalloc for buffer cache backing memory v2 Christoph Hellwig
2025-03-05 14:05 ` [PATCH 01/12] xfs: unmapped buffer item size straddling mismatch Christoph Hellwig
2025-03-05 14:05 ` [PATCH 02/12] xfs: add a fast path to xfs_buf_zero when b_addr is set Christoph Hellwig
2025-03-05 14:05 ` [PATCH 03/12] xfs: remove xfs_buf.b_offset Christoph Hellwig
2025-03-05 14:05 ` [PATCH 04/12] xfs: remove xfs_buf_is_vmapped Christoph Hellwig
2025-03-05 14:05 ` [PATCH 05/12] xfs: refactor backing memory allocations for buffers Christoph Hellwig
2025-03-05 14:05 ` [PATCH 06/12] xfs: remove the kmalloc to page allocator fallback Christoph Hellwig
2025-03-05 18:18 ` Darrick J. Wong
2025-03-05 23:32 ` Christoph Hellwig
2025-03-05 21:02 ` Dave Chinner
2025-03-05 23:38 ` Christoph Hellwig
2025-03-05 14:05 ` [PATCH 07/12] xfs: convert buffer cache to use high order folios Christoph Hellwig
2025-03-05 18:20 ` Darrick J. Wong
2025-03-05 20:50 ` Dave Chinner
2025-03-05 23:33 ` Christoph Hellwig
2025-03-10 13:18 ` Christoph Hellwig
2025-03-05 14:05 ` [PATCH 08/12] xfs: kill XBF_UNMAPPED Christoph Hellwig
2025-03-05 14:05 ` [PATCH 09/12] xfs: buffer items don't straddle pages anymore Christoph Hellwig
2025-03-05 14:05 ` [PATCH 10/12] xfs: use vmalloc instead of vm_map_area for buffer backing memory Christoph Hellwig
2025-03-05 18:22 ` Darrick J. Wong
2025-03-05 21:20 ` Dave Chinner
2025-03-05 22:54 ` Darrick J. Wong
2025-03-05 23:28 ` Dave Chinner
2025-03-05 23:45 ` Christoph Hellwig
2025-03-05 23:35 ` Christoph Hellwig
2025-03-06 0:57 ` Dave Chinner
2025-03-06 1:40 ` Christoph Hellwig
2025-03-05 14:05 ` [PATCH 11/12] xfs: cleanup mapping tmpfs folios into the buffer cache Christoph Hellwig
2025-03-05 18:34 ` Darrick J. Wong [this message]
2025-03-05 14:05 ` [PATCH 12/12] xfs: trace what memory backs a buffer Christoph Hellwig
-- strict thread matches above, loose matches on Subject: below --
2025-03-10 13:19 use folios and vmalloc for buffer cache backing memory v3 Christoph Hellwig
2025-03-10 13:19 ` [PATCH 11/12] xfs: cleanup mapping tmpfs folios into the buffer cache Christoph Hellwig
2025-02-26 15:51 use folios and vmalloc for buffer cache backing memory Christoph Hellwig
2025-02-26 15:51 ` [PATCH 11/12] xfs: cleanup mapping tmpfs folios into the buffer cache Christoph Hellwig
2025-02-26 17:39 ` Darrick J. Wong
2025-03-04 14:11 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250305183451.GL2803749@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=cem@kernel.org \
--cc=dchinner@redhat.com \
--cc=hch@lst.de \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox