[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251001155523.2470826-1-joshua.hahnjy@gmail.com>
Date: Wed, 1 Oct 2025 08:55:23 -0700
From: Joshua Hahn <joshua.hahnjy@...il.com>
To: Vlastimil Babka <vbabka@...e.cz>
Cc: kernel test robot <oliver.sang@...el.com>,
oe-lkp@...ts.linux.dev,
lkp@...el.com,
Chris Mason <clm@...com>,
Johannes Weiner <hannes@...xchg.org>,
linux-mm@...ck.org,
Andrew Morton <akpm@...ux-foundation.org>,
Kiryl Shutsemau <kirill@...temov.name>,
Brendan Jackman <jackmanb@...gle.com>,
Michal Hocko <mhocko@...e.com>,
Suren Baghdasaryan <surenb@...gle.com>,
Zi Yan <ziy@...dia.com>,
linux-kernel@...r.kernel.org,
kernel-team@...a.com
Subject: Re: [PATCH v2 4/4] mm/page_alloc: Batch page freeing in free_frozen_page_commit
Hi Vlastimil,
Thank you for your feedback!
On Wed, 1 Oct 2025 12:04:50 +0200 Vlastimil Babka <vbabka@...e.cz> wrote:
> On 9/29/25 5:17 PM, Joshua Hahn wrote:
> > On Sun, 28 Sep 2025 13:17:37 +0800 kernel test robot <oliver.sang@...el.com> wrote:
> >
> > Hello Kernel Test Robot,
> >
> >> Hello,
> >>
> >> kernel test robot noticed "WARNING:bad_unlock_balance_detected" on:
[...snip...]
> >> [ 414.880298][ T7549] WARNING: bad unlock balance detected!
> >> [ 414.881071][ T7549] 6.17.0-rc6-00147-g7e86100bfb0d #1 Not tainted
> >> [ 414.881924][ T7549] -------------------------------------
> >> [ 414.882695][ T7549] date/7549 is trying to release lock (&pcp->lock) at:
> >> [ 414.883649][ T7549] free_frozen_page_commit+0x425/0x9d0
> >> [ 414.884764][ T7549] but there are no more locks to release!
> >> [ 414.885539][ T7549]
> >> [ 414.885539][ T7549] other info that might help us debug this:
> >> [ 414.886704][ T7549] 2 locks held by date/7549:
> >> [ 414.887353][ T7549] #0: ffff888104f29940 (&mm->mmap_lock){++++}-{4:4}, at: exit_mmap (include/linux/seqlock.h:431 include/linux/mmap_lock.h:88 include/linux/mmap_lock.h:398 mm/mmap.c:1288)
> >> [ 414.888591][ T7549] #1: ffff8883ae40e858 (&pcp->lock){+.+.}-{3:3}, at: free_frozen_page_commit+0x46a/0x9d0
> >
> > So based on this, it seems like I must have overlooked a pretty important
> > consideration here. When I unlock the pcp, it allows both the zone and pcp
> > lock to be picked up by another task (pcp lock less likely), but it also
> > means that this process can be migrated to a different CPU, where it will
> > be trying to unlock & acquire a completely different pcp.
>
> Yes.
>
> > For me the most simple solution looks to be migrate_disable() and
> > migrate_enable() in the function to ensure that this task is bound to the
> > CPU it originally started runing on.
> >
> > I'm not sure how this will affect performance, but I think in terms of
>
> It is somewhat expensive, I'd rather avoid if possible.
>
> > desired behavior it does seem like this is the correct way to do it.
>
> I'd rather detect this happened (new pcp doesn't match old pcp after a
> relock) and either give up (should be rare enough hopefully so won't
> cause much imbalance) or recalculate how much to free on the other cpu
> and continue there (probably subtract how much we already did so we
> don't end up unlucky flushing all kinds of cpus "forever").
I think this idea makes sense. Since I am dropping patch 2/4, the remaining
call sites here will be in decay_pcp_high and free_frozen_page_commit.
Here, I think it makes sense to just give up when it realizes it's on a
different CPU. If the new CPU should have pages flushed, then it will be
flushed by either the next call to free_frozen_page_commit (like in
free_unref_folios) or in the case of __free_frozen_pages, it doesn't really
make sense to flush a pcp that isn't related to the current caller.
One concern that I do have is that now it is possible to flush less pages
than the current behavior, since before it was guaranteed that the
specified number of pages will have been flushed. But like you suggested,
hopefully this is rare enough that we don't see it happen. FWIW, I have
not seen this happen before during my testing, the first time I saw it
was in the kernel test robot report, so hopefully it's not very likely.
Thank you for the idea Vlastimil. I'll make these changes in v3!
I hope you have a great day!
Joshua
Powered by blists - more mailing lists