Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/page_alloc: batch page freeing in decay_pcp_high

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>

authored by

Joshua Hahn and committed by
Andrew Morton
fc4b909c 0acc67c4

+6 -3
+6 -3
mm/page_alloc.c
··· 2559 2559 */ 2560 2560 bool decay_pcp_high(struct zone *zone, struct per_cpu_pages *pcp) 2561 2561 { 2562 - int high_min, to_drain, batch; 2562 + int high_min, to_drain, to_drain_batched, batch; 2563 2563 bool todo = false; 2564 2564 2565 2565 high_min = READ_ONCE(pcp->high_min); ··· 2577 2577 } 2578 2578 2579 2579 to_drain = pcp->count - pcp->high; 2580 - if (to_drain > 0) { 2580 + while (to_drain > 0) { 2581 + to_drain_batched = min(to_drain, batch); 2581 2582 spin_lock(&pcp->lock); 2582 - free_pcppages_bulk(zone, to_drain, pcp, 0); 2583 + free_pcppages_bulk(zone, to_drain_batched, pcp, 0); 2583 2584 spin_unlock(&pcp->lock); 2584 2585 todo = true; 2586 + 2587 + to_drain -= to_drain_batched; 2585 2588 } 2586 2589 2587 2590 return todo;