Skip to content

Commit 2205634

Browse files
joshuahahngregkh
authored andcommitted
mm/page_alloc: batch page freeing in decay_pcp_high
[ Upstream commit fc4b909 ] It is possible for pcp->count - pcp->high to exceed pcp->batch by a lot. When this happens, we should perform batching to ensure that free_pcppages_bulk isn't called with too many pages to free at once and starve out other threads that need the pcp or zone lock. Since we are still only freeing the difference between the initial pcp->count and pcp->high values, there should be no change to how many pages are freed. Link: https://lkml.kernel.org/r/20251014145011.3427205-3-joshua.hahnjy@gmail.com Signed-off-by: Joshua Hahn <joshua.hahnjy@gmail.com> Suggested-by: Chris Mason <clm@fb.com> Suggested-by: Andrew Morton <akpm@linux-foundation.org> Co-developed-by: Johannes Weiner <hannes@cmpxchg.org> Reviewed-by: Vlastimil Babka <vbabka@suse.cz> Cc: Brendan Jackman <jackmanb@google.com> Cc: "Kirill A. Shutemov" <kirill@shutemov.name> Cc: Michal Hocko <mhocko@suse.com> Cc: SeongJae Park <sj@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Zi Yan <ziy@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Stable-dep-of: 038a102 ("mm/page_alloc: prevent pcp corruption with SMP=n") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 48273ed commit 2205634

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

mm/page_alloc.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,7 +2365,7 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order,
23652365
*/
23662366
bool decay_pcp_high(struct zone *zone, struct per_cpu_pages *pcp)
23672367
{
2368-
int high_min, to_drain, batch;
2368+
int high_min, to_drain, to_drain_batched, batch;
23692369
bool todo = false;
23702370

23712371
high_min = READ_ONCE(pcp->high_min);
@@ -2383,11 +2383,14 @@ bool decay_pcp_high(struct zone *zone, struct per_cpu_pages *pcp)
23832383
}
23842384

23852385
to_drain = pcp->count - pcp->high;
2386-
if (to_drain > 0) {
2386+
while (to_drain > 0) {
2387+
to_drain_batched = min(to_drain, batch);
23872388
spin_lock(&pcp->lock);
2388-
free_pcppages_bulk(zone, to_drain, pcp, 0);
2389+
free_pcppages_bulk(zone, to_drain_batched, pcp, 0);
23892390
spin_unlock(&pcp->lock);
23902391
todo = true;
2392+
2393+
to_drain -= to_drain_batched;
23912394
}
23922395

23932396
return todo;

0 commit comments

Comments
 (0)