Skip to content

Commit 800f105

Browse files
kirylakpm00
authored andcommitted
mm/page_alloc: fix memory accept before watermarks gets initialized
Watermarks are initialized during the postcore initcall. Until then, all watermarks are set to zero. This causes cond_accept_memory() to incorrectly skip memory acceptance because a watermark of 0 is always met. This can lead to a premature OOM on boot. To ensure progress, accept one MAX_ORDER page if the watermark is zero. Link: https://lkml.kernel.org/r/20250310082855.2587122-1-kirill.shutemov@linux.intel.com Fixes: dcdfdd4 ("mm: Add support for unaccepted memory") Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Tested-by: Farrah Chen <farrah.chen@intel.com> Reported-by: Farrah Chen <farrah.chen@intel.com> Acked-by: Vlastimil Babka <vbabka@suse.cz> Reviewed-by: Pankaj Gupta <pankaj.gupta@amd.com> Cc: Ashish Kalra <ashish.kalra@amd.com> Cc: David Hildenbrand <david@redhat.com> Cc: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com> Cc: Mel Gorman <mgorman@techsingularity.net> Cc: "Mike Rapoport (IBM)" <rppt@kernel.org> Cc: Thomas Lendacky <thomas.lendacky@amd.com> Cc: <stable@vger.kernel.org> [6.5+] Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent b9c0e49 commit 800f105

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

mm/page_alloc.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7004,7 +7004,7 @@ static inline bool has_unaccepted_memory(void)
70047004

70057005
static bool cond_accept_memory(struct zone *zone, unsigned int order)
70067006
{
7007-
long to_accept;
7007+
long to_accept, wmark;
70087008
bool ret = false;
70097009

70107010
if (!has_unaccepted_memory())
@@ -7013,8 +7013,18 @@ static bool cond_accept_memory(struct zone *zone, unsigned int order)
70137013
if (list_empty(&zone->unaccepted_pages))
70147014
return false;
70157015

7016+
wmark = promo_wmark_pages(zone);
7017+
7018+
/*
7019+
* Watermarks have not been initialized yet.
7020+
*
7021+
* Accepting one MAX_ORDER page to ensure progress.
7022+
*/
7023+
if (!wmark)
7024+
return try_to_accept_memory_one(zone);
7025+
70167026
/* How much to accept to get to promo watermark? */
7017-
to_accept = promo_wmark_pages(zone) -
7027+
to_accept = wmark -
70187028
(zone_page_state(zone, NR_FREE_PAGES) -
70197029
__zone_watermark_unusable_free(zone, order, 0) -
70207030
zone_page_state(zone, NR_UNACCEPTED));

0 commit comments

Comments
 (0)