Skip to content

Commit baea249

Browse files
joshuahahngregkh
authored andcommitted
mm/page_alloc: batch page freeing in decay_pcp_high
commit fc4b909 upstream. 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 2a72a8d commit baea249

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
@@ -2554,7 +2554,7 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order,
25542554
*/
25552555
bool decay_pcp_high(struct zone *zone, struct per_cpu_pages *pcp)
25562556
{
2557-
int high_min, to_drain, batch;
2557+
int high_min, to_drain, to_drain_batched, batch;
25582558
bool todo = false;
25592559

25602560
high_min = READ_ONCE(pcp->high_min);
@@ -2572,11 +2572,14 @@ bool decay_pcp_high(struct zone *zone, struct per_cpu_pages *pcp)
25722572
}
25732573

25742574
to_drain = pcp->count - pcp->high;
2575-
if (to_drain > 0) {
2575+
while (to_drain > 0) {
2576+
to_drain_batched = min(to_drain, batch);
25762577
spin_lock(&pcp->lock);
2577-
free_pcppages_bulk(zone, to_drain, pcp, 0);
2578+
free_pcppages_bulk(zone, to_drain_batched, pcp, 0);
25782579
spin_unlock(&pcp->lock);
25792580
todo = true;
2581+
2582+
to_drain -= to_drain_batched;
25802583
}
25812584

25822585
return todo;

0 commit comments

Comments
 (0)