@@ -883,7 +883,7 @@ static void __meminit free_pagetable(struct page *page, int order)
if (PageReserved(page)) {
__ClearPageReserved(page);
- magic = (unsigned long)page->freelist;
+ magic = page_bootmem_type(page);
if (magic == SECTION_INFO || magic == MIX_SECTION_INFO) {
while (nr_pages--)
put_page_bootmem(page++);
@@ -6,7 +6,7 @@
#include <linux/mm.h>
/*
- * Types for free bootmem stored in page->lru.next. These have to be in
+ * Types for free bootmem stored in page->freelist. These have to be in
* some random range in unsigned long space for debugging purposes.
*/
enum {
@@ -17,6 +17,20 @@ enum {
MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE = NODE_INFO,
};
+#define BOOTMEM_TYPE_BITS (ilog2(MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE) + 1)
+#define BOOTMEM_TYPE_MAX ((1UL << BOOTMEM_TYPE_BITS) - 1)
+#define BOOTMEM_INFO_MAX (ULONG_MAX >> BOOTMEM_TYPE_BITS)
+
+static inline unsigned long page_bootmem_type(struct page *page)
+{
+ return (unsigned long)page->freelist & BOOTMEM_TYPE_MAX;
+}
+
+static inline unsigned long page_bootmem_info(struct page *page)
+{
+ return (unsigned long)page->freelist >> BOOTMEM_TYPE_BITS;
+}
+
#ifdef CONFIG_HAVE_BOOTMEM_INFO_NODE
void __init register_page_bootmem_info_node(struct pglist_data *pgdat);
@@ -30,7 +44,7 @@ static inline void free_vmemmap_page(struct page *page)
/* bootmem page has reserved flag in the reserve_bootmem_region */
if (PageReserved(page)) {
- unsigned long magic = (unsigned long)page->freelist;
+ unsigned long magic = page_bootmem_type(page);
if (magic == SECTION_INFO || magic == MIX_SECTION_INFO)
put_page_bootmem(page);
@@ -12,9 +12,9 @@
void get_page_bootmem(unsigned long info, struct page *page, unsigned long type)
{
- page->freelist = (void *)type;
- SetPagePrivate(page);
- set_page_private(page, info);
+ BUG_ON(info > BOOTMEM_INFO_MAX);
+ BUG_ON(type > BOOTMEM_TYPE_MAX);
+ page->freelist = (void *)((info << BOOTMEM_TYPE_BITS) | type);
page_ref_inc(page);
}
@@ -22,14 +22,12 @@ void put_page_bootmem(struct page *page)
{
unsigned long type;
- type = (unsigned long) page->freelist;
+ type = page_bootmem_type(page);
BUG_ON(type < MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE ||
type > MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE);
if (page_ref_dec_return(page) == 1) {
page->freelist = NULL;
- ClearPagePrivate(page);
- set_page_private(page, 0);
INIT_LIST_HEAD(&page->lru);
free_reserved_page(page);
}
@@ -101,6 +99,8 @@ void __init register_page_bootmem_info_node(struct pglist_data *pgdat)
int node = pgdat->node_id;
struct page *page;
+ BUILD_BUG_ON(MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE > BOOTMEM_TYPE_MAX);
+
nr_pages = PAGE_ALIGN(sizeof(struct pglist_data)) >> PAGE_SHIFT;
page = virt_to_page(pgdat);
@@ -740,12 +740,12 @@ static void free_map_bootmem(struct page *memmap)
>> PAGE_SHIFT;
for (i = 0; i < nr_pages; i++, page++) {
- magic = (unsigned long) page->freelist;
+ magic = page_bootmem_type(page);
BUG_ON(magic == NODE_INFO);
maps_section_nr = pfn_to_section_nr(page_to_pfn(page));
- removing_section_nr = page_private(page);
+ removing_section_nr = page_bootmem_info(page);
/*
* When this function is called, the removing section is
The page->private shares storage with page->ptl. In the later patch, we will use the page->ptl. So here we combine bootmem info and type into page->freelist so that we can do not use page->private. Signed-off-by: Muchun Song <songmuchun@bytedance.com> --- arch/x86/mm/init_64.c | 2 +- include/linux/bootmem_info.h | 18 ++++++++++++++++-- mm/bootmem_info.c | 12 ++++++------ mm/sparse.c | 4 ++-- 4 files changed, 25 insertions(+), 11 deletions(-)