From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,david@kernel.org,akpm@linux-foundation.org
Subject: + mm-provide-free_reserved_pages-removing-x86-variant.patch added to mm-unstable branch
Date: Thu, 16 Jul 2026 17:02:56 -0700 [thread overview]
Message-ID: <20260717000256.BA6831F000E9@smtp.kernel.org> (raw)
The patch titled
Subject: mm: provide free_reserved_pages(), removing x86 variant
has been added to the -mm mm-unstable branch. Its filename is
mm-provide-free_reserved_pages-removing-x86-variant.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-provide-free_reserved_pages-removing-x86-variant.patch
This patch will later appear in the mm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: "David Hildenbrand (Arm)" <david@kernel.org>
Subject: mm: provide free_reserved_pages(), removing x86 variant
Date: Thu, 16 Jul 2026 16:51:01 +0200
Let's extend free_reserved_page() in page_alloc.c to
free_reserved_pages(), dropping the custom x86 variant. The common-code
variant will consume an order, so adjust the x86 callers accordingly.
Make free_reserved_pages() assume that we are freeing ordinary high-order
pages, just with the special "reserved" flavor. The target use case for
now is freeing vmemmap PMD pages.
Set the refcount directly to 0 (instead of 1) and call
__free_frozen_pages(). Set the page count to 0 before clearing
PG_reserved, so someone checking PG_reserved (and not finding it set) to
then try grabbing a ref would not suddenly have that ref be dropped. That
is arguably cleaner and safer than the old way of doing it.
Add some kerneldoc. Use a single adjust_managed_page_count() call.
Link: https://lore.kernel.org/20260716-bootmem_info_part2-v2-2-4afc76c73d61@kernel.org
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Muchun Song <muchun.song@linux.dev>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: "Borislav Petkov (AMD)" <bp@alien8.de>
Cc: Brendan Jackman <jackmanb@google.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
arch/x86/mm/init_64.c | 8 +-------
include/linux/mm.h | 8 ++++++--
mm/page_alloc.c | 33 ++++++++++++++++++++++++++-------
3 files changed, 33 insertions(+), 16 deletions(-)
--- a/arch/x86/mm/init_64.c~mm-provide-free_reserved_pages-removing-x86-variant
+++ a/arch/x86/mm/init_64.c
@@ -1000,12 +1000,6 @@ int arch_add_memory(int nid, u64 start,
return add_pages(nid, start_pfn, nr_pages, params);
}
-static void free_reserved_pages(struct page *page, unsigned long nr_pages)
-{
- while (nr_pages--)
- free_reserved_page(page++);
-}
-
static void __meminit free_pagetable(struct page *page)
{
/* bootmem page has reserved flag */
@@ -1038,7 +1032,7 @@ static void __meminit free_vmemmap_pages
while (nr_pages--)
put_page_bootmem(page++);
} else {
- free_reserved_pages(page, nr_pages);
+ free_reserved_pages(page, order);
}
} else {
__free_pages(page, order);
--- a/include/linux/mm.h~mm-provide-free_reserved_pages-removing-x86-variant
+++ a/include/linux/mm.h
@@ -3996,8 +3996,12 @@ extern unsigned long free_reserved_area(
extern void adjust_managed_page_count(struct page *page, long count);
-/* Free the reserved page into the buddy system, so it gets managed. */
-void free_reserved_page(struct page *page);
+void free_reserved_pages(struct page *page, unsigned int order);
+
+static inline void free_reserved_page(struct page *page)
+{
+ free_reserved_pages(page, 0);
+}
static inline void mark_page_reserved(struct page *page)
{
--- a/mm/page_alloc.c~mm-provide-free_reserved_pages-removing-x86-variant
+++ a/mm/page_alloc.c
@@ -6389,15 +6389,34 @@ void adjust_managed_page_count(struct pa
}
EXPORT_SYMBOL(adjust_managed_page_count);
-void free_reserved_page(struct page *page)
+/**
+ * free_reserved_pages - free reserved pages
+ * @page: First page to free.
+ * @order: The page order to free.
+ *
+ * Free pages allocated through memblock during boot, letting the buddy
+ * manage them from now on.
+ *
+ * @page must be naturally aligned to the order and the order must not
+ * exceed MAX_PAGE_ORDER. All pages must be reserved.
+ */
+void free_reserved_pages(struct page *page, unsigned int order)
{
- clear_page_tag_ref(page);
- ClearPageReserved(page);
- init_page_count(page);
- __free_page(page);
- adjust_managed_page_count(page, 1);
+ const unsigned long nr_pages = 1UL << order;
+ int i;
+
+ VM_WARN_ON_ONCE(!IS_ALIGNED(page_to_pfn(page), nr_pages));
+ VM_WARN_ON_ONCE(order > MAX_PAGE_ORDER);
+
+ for (i = 0; i < nr_pages; i++) {
+ clear_page_tag_ref(page + i);
+ set_page_count(page + i, 0);
+ ClearPageReserved(page + i);
+ }
+ adjust_managed_page_count(page, nr_pages);
+ __free_frozen_pages(page, order, FPI_NONE);
}
-EXPORT_SYMBOL(free_reserved_page);
+EXPORT_SYMBOL(free_reserved_pages);
static int page_alloc_cpu_dead(unsigned int cpu)
{
_
Patches currently in -mm which might be from david@kernel.org are
sparc-mm-drop-custom-pte_clear_not_present_full.patch
mm-drop-pte_clear_not_present_full.patch
mm-cleanup-clear_not_present_full_ptes-and-rename-to-clear_non_present_ptes.patch
x86-mm-drop-order-parameter-from-free_pagetable.patch
mm-provide-free_reserved_pages-removing-x86-variant.patch
s390-mm-use-free_reserved_pages-in-vmem_free_pages.patch
mm-bootmem_info-allow-calling-free_bootmem_page-on-pages-without-a-bootmem_type.patch
x86-mm-stop-marking-vmemmap-as-section_info.patch
x86-mm-stop-marking-page-tables-as-mix_section_info.patch
x86-mm-remove-config_have_bootmem_info_node.patch
mm-hugetlb_vmemmap-remove-bootmem_info-leftovers.patch
mm-sparse-remove-bootmem_infoh-include.patch
mm-bootmem_info-remove-config_have_bootmem_info_node.patch
mm-standardize-printing-for-pgtable-entries.patch
reply other threads:[~2026-07-17 0:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260717000256.BA6831F000E9@smtp.kernel.org \
--to=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=mm-commits@vger.kernel.org \
/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