linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "NeilBrown" <neilb@suse.de>
To: "Yunsheng Lin" <yunshenglin0825@gmail.com>
Cc: "Yunsheng Lin" <linyunsheng@huawei.com>,
	"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: Mon, 10 Mar 2025 11:10:48 +1100	[thread overview]
Message-ID: <174156544867.33508.5386967459254083056@noble.neil.brown.name> (raw)
In-Reply-To: <7abb0e8c-f565-48f0-a393-8dabbabc3fe2@gmail.com>

On Mon, 10 Mar 2025, Yunsheng Lin wrote:
> On 3/8/2025 5:02 AM, NeilBrown wrote:
> 
> ...
> 
> >>
> >>>    allocated pages in the array - just like the current
> >>>    alloc_pages_bulk().
> >>
> >> I guess 'the total number of allocated pages in the array ' include
> >> the pages which are already in the array before calling the above
> >> API?
> > 
> > Yes - just what the current function does.
> > Though I don't know that we really need that detail.
> > I think there are three interesting return values:
> > 
> > - hard failure - don't bother trying again soon:   maybe -ENOMEM
> > - success - all pages are allocated:  maybe 0 (or 1?)
> > - partial success - at least one page allocated, ok to try again
> >    immediately - maybe -EAGAIN (or 0).
> 
> Yes, the above makes sense. And I guess returning '-ENOMEM' & '0' &
> '-EAGAIN' seems like a more explicit value.
> 
> > 
> >>
> 
> ...
> 
> >>
> > 
> > If I were do work on this (and I'm not, so you don't have to follow my
> > ideas) I would separate the bulk_alloc into several inline functions and
> > combine them into the different interfaces that you want.  This will
> > result in duplicated object code without duplicated source code.  The
> > object code should be optimal.
> 
> Thanks for the detailed suggestion, it seems feasible.
> If the 'add to a linked list' dispose was not removed in the [1],
> I guess it is worth trying.
> But I am not sure if it is still worth it at the cost of the above
> mentioned 'duplicated object code' considering the array defragmenting
> seem to be able to unify the dispose of 'add to end of array' and
> 'add to next hole in array'.
> 
> I guess I can try with the easier one using array defragmenting first,
> and try below if there is more complicated use case.

Your post observes a performance improvement - slight though it is.
I might be worth measuring the performance change for a case that
requires defragmenting to see how that compares.

Thanks,
NeilBrown


> 
> 1. 
> https://lore.kernel.org/all/f1c75db91d08cafd211eca6a3b199b629d4ffe16.1734991165.git.luizcap@redhat.com/
> 
> > 
> > The parts of the function are:
> >   - validity checks - fallback to single page allocation
> >   - select zone - fallback to single page allocation
> >   - allocate multiple pages in the zone and dispose of them
> >   - allocate a single page
> > 
> > The "dispose of them" is one of
> >    - add to a linked list
> >    - add to end of array
> >    - add to next hole in array
> > 
> > These three could be inline functions that the "allocate multiple pages"
> > and "allocate single page" functions call.  We can pass these as
> > function arguments and the compile will inline them.
> > I imagine these little function would take one page and return
> > a bool indicating if any more are wanted.
> > 
> > The three functions: alloc_bulk_array alloc_bulk_list
> > alloc_bulk_refill_array would each look like:
> > 
> >    validity checks: do we need to allocate anything?
> > 
> >    if want more than one page &&
> >       am allowed to do mulipage (e.g. not __GFP_ACCOUNT) &&
> >       zone = choose_zone() {
> >          alloc_multi_from_zone(zone, dispose_function)
> >    }
> >    if nothing allocated
> >       alloc_single_page(dispose_function)
> > 
> > Each would have a different dispose_function and the initial checks
> > would be quite different, as would the return value.
> > 
> > Thanks for working on this.
> > 
> > NeilBrown
> > 
> 
> 



      reply	other threads:[~2025-03-10  0:11 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
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 [this message]

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=174156544867.33508.5386967459254083056@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=yunshenglin0825@gmail.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