public inbox for linux-doc@vger.kernel.org
 help / color / mirror / Atom feed
From: hanqi <hanqi@vivo.com>
To: "陈涛涛 Taotao Chen" <chentaotao@didiglobal.com>,
	"tytso@mit.edu" <tytso@mit.edu>,
	"hch@infradead.org" <hch@infradead.org>,
	"adilger.kernel@dilger.ca" <adilger.kernel@dilger.ca>,
	"willy@infradead.org" <willy@infradead.org>,
	"brauner@kernel.org" <brauner@kernel.org>,
	"jani.nikula@linux.intel.com" <jani.nikula@linux.intel.com>,
	"rodrigo.vivi@intel.com" <rodrigo.vivi@intel.com>,
	"tursulin@ursulin.net" <tursulin@ursulin.net>,
	"airlied@gmail.com" <airlied@gmail.com>
Cc: "linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
	"linux-ext4@vger.kernel.org" <linux-ext4@vger.kernel.org>,
	"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
	"intel-gfx@lists.freedesktop.org"
	<intel-gfx@lists.freedesktop.org>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"chentao325@qq.com" <chentao325@qq.com>,
	"frank.li@vivo.com" <frank.li@vivo.com>
Subject: Re: [PATCH v4 4/5] mm/filemap: add write_begin_get_folio() helper function
Date: Mon, 7 Jul 2025 19:48:34 +0800	[thread overview]
Message-ID: <a4cc7c59-2dfd-497e-9f20-b12ea86a1baa@vivo.com> (raw)
In-Reply-To: <20250707070023.206725-5-chentaotao@didiglobal.com>



在 2025/7/7 15:00, 陈涛涛 Taotao Chen 写道:
> From: Taotao Chen <chentaotao@didiglobal.com>
>
> Add write_begin_get_folio() to simplify the common folio lookup logic
> used by filesystem ->write_begin() implementations.
>
> This helper wraps __filemap_get_folio() with common flags such as
> FGP_WRITEBEGIN, conditional FGP_DONTCACHE, and set folio order based
> on the write length.
>
> Part of a series refactoring address_space_operations write_begin and
> write_end callbacks to use struct kiocb for passing write context and
> flags.
>
> Signed-off-by: Taotao Chen <chentaotao@didiglobal.com>
> ---
>   include/linux/pagemap.h |  3 +++
>   mm/filemap.c            | 30 ++++++++++++++++++++++++++++++
>   2 files changed, 33 insertions(+)
>
> diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
> index e63fbfbd5b0f..cbf8539ba11b 100644
> --- a/include/linux/pagemap.h
> +++ b/include/linux/pagemap.h
> @@ -749,6 +749,9 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index,
>   		fgf_t fgp_flags, gfp_t gfp);
>   struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index,
>   		fgf_t fgp_flags, gfp_t gfp);
> +struct folio *write_begin_get_folio(const struct kiocb *iocb,
> +				    struct address_space *mapping,
> +				    pgoff_t index, size_t len);
>   
>   /**
>    * filemap_get_folio - Find and get a folio.
> diff --git a/mm/filemap.c b/mm/filemap.c
> index ba089d75fc86..9520f65c287a 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -2026,6 +2026,36 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index,
>   }
>   EXPORT_SYMBOL(__filemap_get_folio);
>   
> +
> +/**
> + * write_begin_get_folio - Get folio for write_begin with flags
> + * @iocb: kiocb passed from write_begin (may be NULL)
> + * @mapping: the address space to search in
> + * @index: page cache index
> + * @len: length of data being written
> + *
> + * This is a helper for filesystem write_begin() implementations.
> + * It wraps __filemap_get_folio(), setting appropriate flags in
> + * the write begin context.
> + *
> + * Returns a folio or an ERR_PTR.
> + */

hi, tao
I think it might be worth considering adding an fgf_t parameter to the
write_begin_get_folio() helper, since in some filesystems the fgp_flags
passed to __filemap_get_folio() in write_begin are not limited to just
FGP_WRITEBEGIN. Something like:
struct folio *write_begin_get_folio(const struct kiocb *iocb,
				    struct address_space *mapping,
				    pgoff_t index, size_t len,
                                     fgf_t fgp_flags)

> +struct folio *write_begin_get_folio(const struct kiocb *iocb,
> +				    struct address_space *mapping,
> +				    pgoff_t index, size_t len)
> +{
> +	fgf_t fgp_flags = FGP_WRITEBEGIN;
> +
> +	fgp_flags |= fgf_set_order(len);
> +
> +	if (iocb && iocb->ki_flags & IOCB_DONTCACHE)
> +		fgp_flags |= FGP_DONTCACHE;
> +
> +	return __filemap_get_folio(mapping, index, fgp_flags,
> +				   mapping_gfp_mask(mapping));
> +}
> +EXPORT_SYMBOL(write_begin_get_folio);
> +
>   static inline struct folio *find_get_entry(struct xa_state *xas, pgoff_t max,
>   		xa_mark_t mark)
>   {


  reply	other threads:[~2025-07-07 11:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-07  7:00 [PATCH v4 0/5] fs: refactor write_begin/write_end and add ext4 IOCB_DONTCACHE support 陈涛涛 Taotao Chen
2025-07-07  7:00 ` [PATCH v4 1/5] drm/i915: Use kernel_write() in shmem object create 陈涛涛 Taotao Chen
2025-07-07  7:00 ` [PATCH v4 2/5] drm/i915: Refactor shmem_pwrite() to use kiocb and write_iter 陈涛涛 Taotao Chen
2025-07-07  7:00 ` [PATCH v4 3/5] fs: change write_begin/write_end interface to take struct kiocb * 陈涛涛 Taotao Chen
2025-07-07  7:00 ` [PATCH v4 4/5] mm/filemap: add write_begin_get_folio() helper function 陈涛涛 Taotao Chen
2025-07-07 11:48   ` hanqi [this message]
2025-07-07 12:26     ` Matthew Wilcox
2025-07-07 14:54   ` Matthew Wilcox
2025-07-08  2:40     ` Taotao Chen
2025-07-07  7:00 ` [PATCH v4 5/5] ext4: support uncached buffered I/O 陈涛涛 Taotao Chen

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=a4cc7c59-2dfd-497e-9f20-b12ea86a1baa@vivo.com \
    --to=hanqi@vivo.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=airlied@gmail.com \
    --cc=brauner@kernel.org \
    --cc=chentao325@qq.com \
    --cc=chentaotao@didiglobal.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=frank.li@vivo.com \
    --cc=hch@infradead.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=tursulin@ursulin.net \
    --cc=tytso@mit.edu \
    --cc=willy@infradead.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