From: Pankaj Gupta <pankaj.gupta@amd.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Vlastimil Babka <vbabka@kernel.org>,
Johannes Weiner <hannes@cmpxchg.org>
Cc: Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
Brendan Jackman <brendan.jackman@linux.dev>,
Zi Yan <ziy@nvidia.com>, "Kiryl Shutsemau" <kas@kernel.org>,
Tom Lendacky <thomas.lendacky@amd.com>,
"Farrah Chen" <farrah.chen@intel.com>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>, <pankaj.gupta.linux@gmail.com>,
Pankaj Gupta <pankaj.gupta@amd.com>
Subject: [PATCH 2/2] mm/page_alloc: do not accept memory proactively before watermarks are set
Date: Mon, 30 Nov 2026 11:26:41 -0600 [thread overview]
Message-ID: <20261130172641.237214-3-pankaj.gupta@amd.com> (raw)
In-Reply-To: <20261130172641.237214-1-pankaj.gupta@amd.com>
Zone watermarks are set in init_per_zone_wmark_min(), a postcore
initcall. Until then promo_wmark_pages() is 0, and
accept_memory_to_wmark() accepts one MAX_PAGE_ORDER page on every call
to ensure progress.
get_page_from_freelist() and alloc_pages_bulk() call it for every zone
before they try to allocate, so every early page allocation accepts
4 MiB, needed or not. This defeats lazy acceptance.
Make accept_memory_to_wmark() do nothing while the watermarks are 0 and
move the "accept one MAX_PAGE_ORDER page" fallback to a new helper,
accept_memory_for_alloc(), which is called where the watermark check or
the allocation has failed.
SEV-SNP guest with 19 GiB of memory, memory left unaccepted after boot,
before and after this change:
before after
4 vCPUs 3.1 GiB 14.7 GiB
64 vCPUs 2.8 GiB 13.9 GiB
This also reduces the boot time of the guest.
Fixes: 800f1059c99e ("mm/page_alloc: fix memory accept before watermarks gets initialized")
Signed-off-by: Pankaj Gupta <pankaj.gupta@amd.com>
---
mm/page_alloc.c | 43 ++++++++++++++++++++++++++++++++++---------
1 file changed, 34 insertions(+), 9 deletions(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index adba323ba894..0ca638c0da46 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -301,6 +301,8 @@ static unsigned long alloc_stall_warn_jiffies = INITIAL_JIFFIES;
static bool page_contains_unaccepted(struct page *page, unsigned int order);
static bool accept_memory_to_wmark(struct zone *zone, unsigned int order,
int alloc_flags);
+static bool accept_memory_for_alloc(struct zone *zone, unsigned int order,
+ int alloc_flags);
static bool __free_unaccepted(struct page *page);
int page_group_by_mobility_disabled __read_mostly;
@@ -3927,7 +3929,7 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags,
if (!zone_watermark_fast(zone, order, mark,
ac->highest_zoneidx, alloc_flags,
gfp_mask)) {
- if (accept_memory_to_wmark(zone, order, alloc_flags))
+ if (accept_memory_for_alloc(zone, order, alloc_flags))
goto try_this_zone;
/*
@@ -3964,7 +3966,7 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags,
return page;
} else {
- if (accept_memory_to_wmark(zone, order, alloc_flags))
+ if (accept_memory_for_alloc(zone, order, alloc_flags))
goto try_this_zone;
/* Try again if zone has deferred pages */
@@ -5295,7 +5297,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid,
break;
}
- if (accept_memory_to_wmark(zone, 0, alloc_flags))
+ if (accept_memory_for_alloc(zone, 0, alloc_flags))
goto retry_this_zone;
/* Try again if zone has deferred pages */
@@ -8052,13 +8054,8 @@ static bool accept_memory_to_wmark(struct zone *zone, unsigned int order,
wmark = promo_wmark_pages(zone);
- /*
- * Watermarks have not been initialized yet.
- *
- * Accepting one MAX_PAGE_ORDER page to ensure progress.
- */
if (!wmark)
- return try_to_accept_memory_one(zone);
+ return false;
/* How much to accept to get to promo watermark? */
to_accept = wmark -
@@ -8076,6 +8073,28 @@ static bool accept_memory_to_wmark(struct zone *zone, unsigned int order,
return ret;
}
+/*
+ * Accept memory after the watermark check or the allocation itself has failed
+ * for @zone.
+ *
+ * Returns true if memory was accepted and the allocation should be retried.
+ */
+static bool accept_memory_for_alloc(struct zone *zone, unsigned int order,
+ int alloc_flags)
+{
+ if (list_empty(&zone->unaccepted_pages))
+ return false;
+
+ /* Bailout, since try_to_accept_memory_one() needs to take a lock */
+ if (alloc_flags & ALLOC_NOLOCK)
+ return false;
+
+ if (!promo_wmark_pages(zone))
+ return try_to_accept_memory_one(zone);
+
+ return accept_memory_to_wmark(zone, order, alloc_flags);
+}
+
static bool __free_unaccepted(struct page *page)
{
struct zone *zone = page_zone(page);
@@ -8107,6 +8126,12 @@ static bool accept_memory_to_wmark(struct zone *zone, unsigned int order,
return false;
}
+static bool accept_memory_for_alloc(struct zone *zone, unsigned int order,
+ int alloc_flags)
+{
+ return false;
+}
+
static bool __free_unaccepted(struct page *page)
{
BUILD_BUG();
--
2.34.1
prev parent reply other threads:[~2026-11-30 17:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 17:26 [PATCH 0/2] mm/page_alloc: fix lazy memory acceptance " Pankaj Gupta
2026-11-30 17:26 ` [PATCH 1/2] mm/page_alloc: rename cond_accept_memory() to accept_memory_to_wmark() Pankaj Gupta
2026-11-30 17:26 ` Pankaj Gupta [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130172641.237214-3-pankaj.gupta@amd.com \
--to=pankaj.gupta@amd.com \
--cc=akpm@linux-foundation.org \
--cc=brendan.jackman@linux.dev \
--cc=farrah.chen@intel.com \
--cc=hannes@cmpxchg.org \
--cc=kas@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=pankaj.gupta.linux@gmail.com \
--cc=surenb@google.com \
--cc=thomas.lendacky@amd.com \
--cc=vbabka@kernel.org \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®