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/[email protected] Signed-off-by: Joshua Hahn <[email protected]> Suggested-by: Chris Mason <[email protected]> Suggested-by: Andrew Morton <[email protected]> Co-developed-by: Johannes Weiner <[email protected]> Reviewed-by: Vlastimil Babka <[email protected]> Cc: Brendan Jackman <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Cc: Michal Hocko <[email protected]> Cc: SeongJae Park <[email protected]> Cc: Suren Baghdasaryan <[email protected]> Cc: Zi Yan <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Stable-dep-of: 038a102 ("mm/page_alloc: prevent pcp corruption with SMP=n") Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
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)