mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@suse.com>
To: Yosry Ahmed <yosry@kernel.org>
Cc: akpm@linux-foundation.org, mgorman@techsingularity.net,
	david@redhat.com, vbabka@suse.cz, hannes@cmpxchg.org,
	quic_pkondeti@quicinc.com, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH V3 3/3] mm: page_alloc: drain pcp lists before oom kill
Date: Wed, 9 Sep 2026 09:36:10 +0200	[thread overview]
Message-ID: <aqEMagbMGPlkuP2P@tiehlicka> (raw)
In-Reply-To: <CAO9r8zOaAGHXK6FZ0PM9sJL2zH4fQe5kh+W2TBNL90YZV2detQ@mail.gmail.com>

On Mon 07-09-26 01:49:39, Yosry Ahmed wrote:
> On Mon, Sep 7, 2026 at 12:26 AM Michal Hocko <mhocko@suse.com> wrote:
> >
> > On Fri 04-09-26 09:35:55, Yosry Ahmed wrote:
> > > On Fri, Sep 4, 2026 at 9:27 AM Michal Hocko <mhocko@suse.com> wrote:
> > [...]
> > > > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> > > > > index 8d79f76cdd0e1..98e9079240ad5 100644
> > > > > --- a/mm/page_alloc.c
> > > > > +++ b/mm/page_alloc.c
> > > > > @@ -4592,11 +4592,12 @@ __alloc_pages_direct_reclaim(gfp_t gfp_mask,
> > > > > unsigned int order,
> > > > >         psi_memstall_enter(&pflags);
> > > > >         *did_some_progress = __perform_reclaim(gfp_mask, order, ac);
> > > > >         if (unlikely(!(*did_some_progress)))
> > > > > -               goto out;
> > > > > +               goto drain;
> > > > >
> > > > >  retry:
> > > > >         page = get_page_from_freelist(gfp_mask, order, alloc_flags, ac);
> > > > >
> > > > > +drain:
> > > > >         /*
> > > > >          * If an allocation failed after direct reclaim, it could be because
> > > > >          * pages are pinned on the per-cpu lists or in high alloc reserves.
> > > > > @@ -4608,7 +4609,6 @@ __alloc_pages_direct_reclaim(gfp_t gfp_mask,
> > > > > unsigned int order,
> > > > >                 drained = true;
> > > > >                 goto retry;
> > > > >         }
> > > > > -out:
> > > > >         psi_memstall_leave(&pflags);
> > > >
> > > > Ideally if we can make the function call less hairy. Maybe we want to
> > > > make draining part of the reclaim as the last resort when normal reclaim
> > > > fails.
> > >
> > > Do you mean do the draining in __perform_reclaim(), or deeper into the
> > > reclaim stack?
> > >
> > > The thing is that __alloc_pages_direct_reclaim() currently drains when
> > > __perform_reclaim() fails to make any progress and we still cannot
> > > allocate. The change above makes it drain if it cannot allocate after
> > > __perform_reclaim(), regardless of progress. So if you want to move it
> > > into __perform_reclaim(), we'll have it in both places.
> > >
> > > Or maybe I just don't understand what you meant :)
> >
> > Sorry for not being clear enough. I meant to pull draining out of
> > __alloc_pages_direct_reclaim and instead have it somewhere in the
> > reclaim path. It is not entirely clear to me  where at the moment but we
> > do not need to have the same behavior as now. The idea behind the code
> > is to not drain way too much. Maybe we want to drain when dropping the
> > priority down to 0.
> 
> If we want to maintain the current behavior of only doing this for
> direct reclaim (not kswapd, cgroup reclaim, or proactive reclaim),
> then I was going to suggest adding it to do_try_to_free_pages().
> However, we bail before priority reaches 0 if we are able to make
> progress or compaction is ready.
> 
> Also, I think in do_try_to_free_pages() we don't have enough context
> to decide if we need to drain the pcplists. Looking at the comment in
> __alloc_pages_direct_reclaim(), we specifically drain the pcplists if
> the allocation fails after reclaim makes progress to make sure all
> reclaimed pages (e.g. in other CPUs' pcplists) are made available to
> the allocation. So I think it fits better in the allocation path, so
> that we only drain if we cannot allocate after direct reclaim.
> 
> I think the main issue is that we only drain today if we know direct
> reclaim made progress, so it potentially freed some pages to pcplists.
> However, it is possible that reclaim did not make progress but there
> were already pages on the pcplists (e.g. freed concurrently or were
> already there). I don't think the right place to do this is reclaim
> path.
> 
> I personally think either Charan's original patch (draining in
> should_reclaim_retry()), or the diff I proposed upthread (draining in
> __alloc_pages_direct_reclaim()) are probably the best places. Please
> let me know if you still disagree.

In that case should_reclaim_retry seems a better fitting fix. 
Thanks!
-- 
Michal Hocko
SUSE Labs

  reply	other threads:[~2026-09-09  7:36 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-05 12:50 [PATCH V2 0/3] mm: page_alloc: fixes for early oom kills Charan Teja Kalla
2023-11-05 12:50 ` [PATCH V2 1/3] mm: page_alloc: unreserve highatomic page blocks before oom Charan Teja Kalla
2023-11-09 10:29   ` Michal Hocko
2023-11-05 12:50 ` [PATCH V2 2/3] mm: page_alloc: correct high atomic reserve calculations Charan Teja Kalla
2023-11-16  9:59   ` Mel Gorman
2023-11-16 12:52     ` Michal Hocko
2023-11-17 16:19       ` Mel Gorman
2023-11-05 12:50 ` [PATCH V3 3/3] mm: page_alloc: drain pcp lists before oom kill Charan Teja Kalla
2023-11-05 12:55   ` Charan Teja Kalla
2023-11-09 10:33   ` Michal Hocko
2023-11-10 16:36     ` Charan Teja Kalla
2023-11-14 10:48       ` Michal Hocko
2023-11-14 16:36         ` Charan Teja Kalla
2023-11-15 14:09           ` Michal Hocko
2023-11-16  6:00             ` Charan Teja Kalla
2023-11-16 12:55               ` Michal Hocko
2023-11-17  5:43                 ` Charan Teja Kalla
2024-01-25 16:36           ` Zach O'Keefe
2024-01-26 10:47             ` Charan Teja Kalla
2024-01-26 10:57               ` Michal Hocko
2024-01-26 22:51                 ` Zach O'Keefe
2024-01-29 15:04                   ` Michal Hocko
2024-02-06 23:15                     ` Zach O'Keefe
2026-09-02 16:49   ` Yosry Ahmed
2026-09-02 16:56     ` Yosry Ahmed
2026-09-03  7:27     ` Michal Hocko
2026-09-03 14:03       ` Yosry Ahmed
2026-09-04 11:21         ` Michal Hocko
2026-09-04 16:09           ` Yosry Ahmed
2026-09-04 16:27             ` Michal Hocko
2026-09-04 16:35               ` Yosry Ahmed
2026-09-07  7:26                 ` Michal Hocko
2026-09-07  8:49                   ` Yosry Ahmed
2026-09-09  7:36                     ` Michal Hocko [this message]
2026-09-10  7:21                       ` Yosry Ahmed

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=aqEMagbMGPlkuP2P@tiehlicka \
    --to=mhocko@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=quic_pkondeti@quicinc.com \
    --cc=vbabka@suse.cz \
    --cc=yosry@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

all inboxes | Powered by JetHome®