[PATCH] mm: fix pcp count beyond pcp high in pcplist allocation

From: Chen Wandun
Date: Mon Oct 24 2022 - 13:27:25 EST


Nowadays there are several orders in pcplist, Function __rmqueue_pcplist
would alloc pcp batch pages to refill pcplist, when list of target order
if empty meanwhile other lists is not all empty, that result in pcp count
beyond pcp high after allocation. This behaviour can be easily observed by
adding debugging information in __rmqueue_pcplist.

Fix this by recalculate the batch pages to be allocated.

Fixes: 44042b449872 ("mm/page_alloc: allow high-order pages to be stored on the per-cpu lists")
Signed-off-by: Chen Wandun <chenwandun@xxxxxxxxxx>
---
mm/page_alloc.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 39f846d098f5..93e18b6de2f3 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3742,6 +3742,7 @@ struct page *__rmqueue_pcplist(struct zone *zone, unsigned int order,
do {
if (list_empty(list)) {
int batch = READ_ONCE(pcp->batch);
+ int high = READ_ONCE(pcp->high);
int alloced;

/*
@@ -3753,6 +3754,7 @@ struct page *__rmqueue_pcplist(struct zone *zone, unsigned int order,
*/
if (batch > 1)
batch = max(batch >> order, 2);
+ batch = min(batch, (high - pcp->count) >> order);
alloced = rmqueue_bulk(zone, order,
batch, list,
migratetype, alloc_flags);
--
2.25.1