[SRU][N/O:linux-intel][PATCH 4/4] mm/page_alloc: Fix memory accept before watermarks gets initialized

Thibault Ferrante thibault.ferrante at canonical.com
Tue Mar 18 16:30:05 UTC 2025


From: "Kirill A. Shutemov" <kirill.shutemov at linux.intel.com>

BugLink: https://bugs.launchpad.net/bugs/2103530

Watermarks are initialized in the postcore initcall. Until then, all
watermarks are set to zero. This causes cond_accept_memory() to falsely
skip memory acceptance as we always hit a watermark of 0.

To ensure progress, accept one MAX_ORDER page if the watermark is zero.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov at linux.intel.com>
(cherry picked from commit cd0dac021b8d50ac3162cbd017fbb73c226c3dd1 https://github.com/intel/kernel-downstream)
Signed-off-by: Thibault Ferrante <thibault.ferrante at canonical.com>
---
 mm/page_alloc.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 024cb5b843c6e..22dfa51f87b6c 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -6989,7 +6989,7 @@ static bool try_to_accept_memory_one(struct zone *zone)
 
 static bool cond_accept_memory(struct zone *zone, unsigned int order)
 {
-	long to_accept;
+	long to_accept, wmark;
 	bool ret = false;
 
 	if (!has_unaccepted_memory())
@@ -6998,8 +6998,18 @@ static bool cond_accept_memory(struct zone *zone, unsigned int order)
 	if (list_empty(&zone->unaccepted_pages))
 		return false;
 
+	wmark = promo_wmark_pages(zone);
+
+	/*
+	 * Watermarks have not been initialized yet.
+	 *
+	 * Accepting one MAX_ORDER page to ensure progress.
+	 */
+	if (!wmark)
+		return try_to_accept_memory_one(zone);
+
 	/* How much to accept to get to promo watermark? */
-	to_accept = promo_wmark_pages(zone) -
+	to_accept = wmark -
 		    (zone_page_state(zone, NR_FREE_PAGES) -
 		    __zone_watermark_unusable_free(zone, order, 0) -
 		    zone_page_state(zone, NR_UNACCEPTED));
-- 
2.45.2




More information about the kernel-team mailing list