linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "NeilBrown" <neilb@suse.de>
To: "Yunsheng Lin" <linyunsheng@huawei.com>
Cc: "Qu Wenruo" <wqu@suse.com>, "Yishai Hadas" <yishaih@nvidia.com>,
	"Jason Gunthorpe" <jgg@ziepe.ca>,
	"Shameer Kolothum" <shameerali.kolothum.thodi@huawei.com>,
	"Kevin Tian" <kevin.tian@intel.com>,
	"Alex Williamson" <alex.williamson@redhat.com>,
	"Chris Mason" <clm@fb.com>, "Josef Bacik" <josef@toxicpanda.com>,
	"David Sterba" <dsterba@suse.com>, "Gao Xiang" <xiang@kernel.org>,
	"Chao Yu" <chao@kernel.org>, "Yue Hu" <zbestahu@gmail.com>,
	"Jeffle Xu" <jefflexu@linux.alibaba.com>,
	"Sandeep Dhavale" <dhavale@google.com>,
	"Carlos Maiolino" <cem@kernel.org>,
	"Darrick J. Wong" <djwong@kernel.org>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Jesper Dangaard Brouer" <hawk@kernel.org>,
	"Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Simon Horman" <horms@kernel.org>,
	"Trond Myklebust" <trondmy@kernel.org>,
	"Anna Schumaker" <anna@kernel.org>,
	"Chuck Lever" <chuck.lever@oracle.com>,
	"Jeff Layton" <jlayton@kernel.org>,
	"Olga Kornievskaia" <okorniev@redhat.com>,
	"Dai Ngo" <Dai.Ngo@oracle.com>, "Tom Talpey" <tom@talpey.com>,
	"Luiz Capitulino" <luizcap@redhat.com>,
	"Mel Gorman" <mgorman@techsingularity.net>,
	"Dave Chinner" <david@fromorbit.com>,
	kvm@vger.kernel.org, virtualization@lists.linux.dev,
	linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org,
	linux-erofs@lists.ozlabs.org, linux-xfs@vger.kernel.org,
	linux-mm@kvack.org, netdev@vger.kernel.org,
	linux-nfs@vger.kernel.org
Subject: Re: [PATCH v2] mm: alloc_pages_bulk: remove assumption of populating only NULL elements
Date: Fri, 07 Mar 2025 08:14:14 +1100	[thread overview]
Message-ID: <174129565467.33508.7106343513316364028@noble.neil.brown.name> (raw)
In-Reply-To: <f834a7cd-ca0a-4495-a787-134810aa0e4d@huawei.com>

On Thu, 06 Mar 2025, Yunsheng Lin wrote:
> On 2025/3/6 7:41, NeilBrown wrote:
> > On Wed, 05 Mar 2025, Yunsheng Lin wrote:
> >>
> >> For the existing btrfs and sunrpc case, I am agreed that there
> >> might be valid use cases too, we just need to discuss how to
> >> meet the requirements of different use cases using simpler, more
> >> unified and effective APIs.
> > 
> > We don't need "more unified".
> 
> What I meant about 'more unified' is how to avoid duplicated code as
> much as possible for two different interfaces with similar‌ functionality.
> 
> The best way I tried to avoid duplicated code as much as possible is
> to defragment the page_array before calling the alloc_pages_bulk()
> for the use case of btrfs and sunrpc so that alloc_pages_bulk() can
> be removed of the assumption populating only NULL elements, so that
> the API is simpler and more efficient.
> 
> > 
> > If there are genuinely two different use cases with clearly different
> > needs - even if only slightly different - then it is acceptable to have
> > two different interfaces.  Be sure to choose names which emphasise the
> > differences.
> 
> The best name I can come up with for the use case of btrfs and sunrpc
> is something like alloc_pages_bulk_refill(), any better suggestion about
> the naming?

I think alloc_pages_bulk_refill() is a good name.

So:
- alloc_pages_bulk() would be given an uninitialised array of page
  pointers and a required count and would return the number of pages
  that were allocated
- alloc_pages_bulk_refill() would be given an initialised array of page
  pointers some of which might be NULL.  It would attempt to allocate
  pages for the non-NULL pointers and return the total number of
  allocated pages in the array - just like the current
  alloc_pages_bulk().

sunrpc could usefully use both of these interfaces.

alloc_pages_bulk() could be implemented by initialising the array and
then calling alloc_pages_bulk_refill().  Or alloc_pages_bulk_refill()
could be implemented by compacting the pages and then calling
alloc_pages_bulk().
If we could duplicate the code and have two similar but different
functions.

The documentation for _refill() should make it clear that the pages
might get re-ordered.

Having looked at some of the callers I agree that the current interface
is not ideal for many of them, and that providing a simpler interface
would help.

Thanks,
NeilBrown


  reply	other threads:[~2025-03-06 21:14 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-28  9:44 Yunsheng Lin
2025-03-03 22:13 ` Chuck Lever
2025-03-04 12:04   ` Yunsheng Lin
2025-03-04  8:18 ` Dave Chinner
2025-03-04 12:09   ` Yunsheng Lin
2025-03-08  6:43     ` Dave Chinner
2025-03-09 13:40       ` Yunsheng Lin
2025-03-10  0:32         ` Gao Xiang
2025-03-10 12:31           ` Yunsheng Lin
2025-03-10 12:59             ` Gao Xiang
2025-03-11 22:55               ` NeilBrown
2025-03-12  1:45                 ` Gao Xiang
2025-03-12 12:05                   ` Yunsheng Lin
2025-03-12 12:41                     ` Gao Xiang
2025-03-04  9:17 ` Qu Wenruo
2025-03-05 12:17   ` Yunsheng Lin
2025-03-05 23:41     ` NeilBrown
2025-03-06 11:43       ` Yunsheng Lin
2025-03-06 21:14         ` NeilBrown [this message]
2025-03-07  9:23           ` Yunsheng Lin
2025-03-07 21:02             ` NeilBrown
2025-03-09 13:23               ` Yunsheng Lin
2025-03-10  0:10                 ` NeilBrown

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=174129565467.33508.7106343513316364028@noble.neil.brown.name \
    --to=neilb@suse.de \
    --cc=Dai.Ngo@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex.williamson@redhat.com \
    --cc=anna@kernel.org \
    --cc=cem@kernel.org \
    --cc=chao@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=clm@fb.com \
    --cc=davem@davemloft.net \
    --cc=david@fromorbit.com \
    --cc=dhavale@google.com \
    --cc=djwong@kernel.org \
    --cc=dsterba@suse.com \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jefflexu@linux.alibaba.com \
    --cc=jgg@ziepe.ca \
    --cc=jlayton@kernel.org \
    --cc=josef@toxicpanda.com \
    --cc=kevin.tian@intel.com \
    --cc=kuba@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=linyunsheng@huawei.com \
    --cc=luizcap@redhat.com \
    --cc=mgorman@techsingularity.net \
    --cc=netdev@vger.kernel.org \
    --cc=okorniev@redhat.com \
    --cc=pabeni@redhat.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=tom@talpey.com \
    --cc=trondmy@kernel.org \
    --cc=virtualization@lists.linux.dev \
    --cc=wqu@suse.com \
    --cc=xiang@kernel.org \
    --cc=yishaih@nvidia.com \
    --cc=zbestahu@gmail.com \
    /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