Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67E9C369985 for ; Wed, 21 Jan 2026 10:57:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768993041; cv=none; b=JU7ETGeON+CQOuGyzbRnf13AGDtrBnvyGMqDgYWg1negGwmSkKEjrqjIFW5UsEJtjG/jXgbrzbKqQjwtKF5hQHpjCQoWhi/uePhL7kL4UTr+xerCglECJ0hXb8AiYW2UthNTQtF2al7142YJDbBd/D2We78bCwUsi64Fg6lQwZ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768993041; c=relaxed/simple; bh=kSsanur6k8BBLl+X9lAGyE9yvyzFkVpuz+jLIxRAcQ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HVSKFI8Yfzre3sBElAC1OLtPT23UFZ2yV/sEmoOrq6PeLeIezBnpkdhSaHln3u9WcFEX37lcJIdaT9SVmvVm0TC+534XRW7pvYm5/Gv2RK4QOUfExU67p3VI88xjODidRQeJlH11j57is5NmWY8a0M3g47ImFtzZt9K85SffjPI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dhbSS+MF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dhbSS+MF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE40CC19424; Wed, 21 Jan 2026 10:57:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768993041; bh=kSsanur6k8BBLl+X9lAGyE9yvyzFkVpuz+jLIxRAcQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dhbSS+MFfdy7PgAZG/+/aqdwYALEdZmdCsL/qIs4rJANNV1ERhxZ1W8J/eaBH5Qsz MaQAqN5+ADGwggZNUdcAcmoo5psJj8tYj7r0L5C2xJDya7B8FopurKfEZRLujVmFAb njEncAbYevrIkb3JGoEFaRsY4vWrN+b6d12uRQdHn+Sr3dkIxoEgfMJSxkoLLGNu/g 32dM6bth2VSmVOVqOk2fgKtez9RjR62yAST9W52BbARnwFF/ee0JX7E5TQ1Ha5egnq 0uJ2wSQ9pb38yLwP3e3M3rHkF2SeymsxYRo9w2W/LyE/VmUQ/uyw3CQp8Qz7dJYfqn Xa+PyMFHS5xPQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Joshua Hahn , Chris Mason , Andrew Morton , Johannes Weiner , Vlastimil Babka , Brendan Jackman , "Kirill A. Shutemov" , Michal Hocko , SeongJae Park , Suren Baghdasaryan , Zi Yan , Sasha Levin Subject: [PATCH 6.18.y 2/3] mm/page_alloc: batch page freeing in decay_pcp_high Date: Wed, 21 Jan 2026 05:57:15 -0500 Message-ID: <20260121105716.1440359-2-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260121105716.1440359-1-sashal@kernel.org> References: <2026012040-zombie-camisole-a4c0@gregkh> <20260121105716.1440359-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Joshua Hahn [ Upstream commit fc4b909c368f3a7b08c895dd5926476b58e85312 ] 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 Suggested-by: Chris Mason Suggested-by: Andrew Morton Co-developed-by: Johannes Weiner Reviewed-by: Vlastimil Babka Cc: Brendan Jackman Cc: "Kirill A. Shutemov" Cc: Michal Hocko Cc: SeongJae Park Cc: Suren Baghdasaryan Cc: Zi Yan Signed-off-by: Andrew Morton Stable-dep-of: 038a102535eb ("mm/page_alloc: prevent pcp corruption with SMP=n") Signed-off-by: Sasha Levin --- mm/page_alloc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 5bb9e57581365..374245b2e1ab8 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2554,7 +2554,7 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order, */ bool decay_pcp_high(struct zone *zone, struct per_cpu_pages *pcp) { - int high_min, to_drain, batch; + int high_min, to_drain, to_drain_batched, batch; bool todo = false; high_min = READ_ONCE(pcp->high_min); @@ -2572,11 +2572,14 @@ bool decay_pcp_high(struct zone *zone, struct per_cpu_pages *pcp) } to_drain = pcp->count - pcp->high; - if (to_drain > 0) { + while (to_drain > 0) { + to_drain_batched = min(to_drain, batch); spin_lock(&pcp->lock); - free_pcppages_bulk(zone, to_drain, pcp, 0); + free_pcppages_bulk(zone, to_drain_batched, pcp, 0); spin_unlock(&pcp->lock); todo = true; + + to_drain -= to_drain_batched; } return todo; -- 2.51.0