Skip to content

Commit 790d305

Browse files
kirylgregkh
authored andcommitted
mm/page_alloc: fix memory accept before watermarks gets initialized
commit 800f105 upstream. 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> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 404d85a commit 790d305

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

mm/page_alloc.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6653,7 +6653,7 @@ static bool try_to_accept_memory_one(struct zone *zone)
66536653

66546654
static bool cond_accept_memory(struct zone *zone, unsigned int order)
66556655
{
6656-
long to_accept;
6656+
long to_accept, wmark;
66576657
bool ret = false;
66586658

66596659
if (!has_unaccepted_memory())
@@ -6662,8 +6662,18 @@ static bool cond_accept_memory(struct zone *zone, unsigned int order)
66626662
if (list_empty(&zone->unaccepted_pages))
66636663
return false;
66646664

6665+
wmark = high_wmark_pages(zone);
6666+
6667+
/*
6668+
* Watermarks have not been initialized yet.
6669+
*
6670+
* Accepting one MAX_ORDER page to ensure progress.
6671+
*/
6672+
if (!wmark)
6673+
return try_to_accept_memory_one(zone);
6674+
66656675
/* How much to accept to get to high watermark? */
6666-
to_accept = high_wmark_pages(zone) -
6676+
to_accept = wmark -
66676677
(zone_page_state(zone, NR_FREE_PAGES) -
66686678
__zone_watermark_unusable_free(zone, order, 0) -
66696679
zone_page_state(zone, NR_UNACCEPTED));

0 commit comments

Comments
 (0)