Re: revisiting alloc_pages_bulks semantics?
From: Christoph Hellwig
Date: Thu May 28 2026 - 05:03:33 EST
On Wed, May 27, 2026 at 09:58:11AM -0400, Chuck Lever wrote:
> On 5/27/26 8:19 AM, Christoph Hellwig wrote:
> > On Wed, May 27, 2026 at 12:06:08PM +0200, Vlastimil Babka (SUSE) wrote:
> >>> alloc_pages_bulks can do partial allocations for some reasons, and
> >>> users usually have a fallback by either looping and calling it again
> >>> or falling back to single page allocations. This sucks! Why can't
> >>> we get our usual try as hard as you can semantics, requiring
> >>> GFP_NORETRY or similar to relax it?
> >>
> >> If we do that, do we keep the possibility of partial success, i.e. return
> >> how many were allocated? Seems wasteful to suceed N-1 and then throw all
> >> away, if the caller can use a fallback only for the last one.
> >> Do some callers need all-or-nothing semantics? Should a flag indicate which
> >> one to use?
> >
> > A lot of callers (but not all) need all or nothing semantics. But
> > freeing already allocated pages is the not a major problem - the caller
> > just has to add a release_pages call if it didn't already have one
> > for cleaning up later failures.
>
> What the svc/nfsd thread is trying to avoid is sleeping uninterruptibly
> waiting for memory resources. That stalls server shutdown, among other
> things.
I'm not fully understanding the sentence. I guess you mean that
you want svc_thread_should_stop to intercept some memory allocation
waits?
> > I've added Chuck to the Cc list, but from memory sunrpc actually does
> > make use of this feature and he objected to previous attempts to
> > change it. So a first step would be to have a lower-level helper
> > that works as-is and a wrapper that zeroes the array, even if that
> > doesn't feel as efficient as it could be.
> If sunrpc is the only user, it might be sensible to hoist the "zero
> fill" capability into sunrpc.ko.
As far as I can tell it is the only one. But I don't really see
how you could implement that functionality outside the core, except
by falling back to single allocations, or looking for empty slots.
I'm curious what you think about willy's comment, or if there is
indeed a way to always use the pages from the beginning or end in
sunrpc.
> svc_rqst_release_pages() NULLs only the range
>
> [rq_respages, rq_next_page)
>
> after each RPC, so only that range contains NULL entries. Limit the
> rq_respages fill in svc_alloc_arg() to that range instead of
> scanning the full array.
Does it NULL the entire range, or part of it? Because if it is the
entire above range, you don't really need the check for NULL behavior
at all but just point the bulk allocation to this range.