[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251014191727.788875-1-joshua.hahnjy@gmail.com>
Date: Tue, 14 Oct 2025 12:17:27 -0700
From: Joshua Hahn <joshua.hahnjy@...il.com>
To: Vlastimil Babka <vbabka@...e.cz>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
Chris Mason <clm@...com>,
Kiryl Shutsemau <kirill@...temov.name>,
"Liam R. Howlett" <Liam.Howlett@...cle.com>,
Brendan Jackman <jackmanb@...gle.com>,
David Hildenbrand <david@...hat.com>,
Johannes Weiner <hannes@...xchg.org>,
Lorenzo Stoakes <lorenzo.stoakes@...cle.com>,
Michal Hocko <mhocko@...e.com>,
Mike Rapoport <rppt@...nel.org>,
Suren Baghdasaryan <surenb@...gle.com>,
Zi Yan <ziy@...dia.com>,
linux-kernel@...r.kernel.org,
linux-mm@...ck.org,
kernel-team@...a.com
Subject: Re: [PATCH v5 0/3] mm/page_alloc: Batch callers of free_pcppages_bulk
On Tue, 14 Oct 2025 19:54:28 +0200 Vlastimil Babka <vbabka@...e.cz> wrote:
> On 10/14/25 16:50, Joshua Hahn wrote:
> > Changelog
> > =========
> > v4 --> v5:
> > - Wordsmithing
> > - Patches 1/3 and 2/3 were left untouched.
> > - Patch 3/3 no longer checks for the to_free == 0 case. It also now checks
> > for pcp->count > 0 as the condition inside the while loop, and the early
> > break checks for the opposite condition. Note that both to_free and
> > pcp->count can become negative due to high-order pages that are freed, so
> > we must check for (to_free <= 0 || pcp->count <= 0), instead of just
> > checking for == 0.
Hello Vlastimil,
> I don't see how that's possible?
> - to_free is decremented by to_free_batched = min(to_free, batch); so it
> can't go negative.
> - pcp->count indeed decrements by nr_pages but it should be exactly zero
> once pcp becomes empty. It's true that internally in free_pcppages_bulk()
> the count parameter (where we pass to_free_batched) can go negative, but
> that doesn't affect to_free_batched in the caller free_frozen_page_commit().
> So testing for <= is unnecessary and only looks weird?
You are totally right. For the first point, that must have been a slip up in
my mind, for some reason, I thought it could go negative after looking at
free_pcppages_bulk, but it obviously can't since we are taking the min as you
pointed out.
The same goes for pcp->count, I realize that it cannot become negative. I think
I was being too careful without really thinking too hard about what I was
protecting against. I'll send in a fixlet in 3/3 which should hopefully be
folded in.
Sorry about these mistakes, I think they could have been avoided had I
thought more about the code. I hope you have a great day!
Joshua
Powered by blists - more mailing lists