Skip to content

Commit

Permalink
mm/page_ext: init page_ext early if there are no deferred struct pages
Browse files Browse the repository at this point in the history
page_ext must be initialized after all struct pages are initialized. 
Therefore, page_ext is initialized after page_alloc_init_late(), and can
optionally be initialized earlier via early_page_ext kernel parameter
which as a side effect also disables deferred struct pages.

Allow to automatically init page_ext early when there are no deferred
struct pages in order to be able to use page_ext during kernel boot and
track for example page allocations early.

[[email protected]: fix build with CONFIG_PAGE_EXTENSION=n]
  Link: https://lkml.kernel.org/r/[email protected]
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Pasha Tatashin <[email protected]>
Acked-by: Mike Rapoport (IBM) <[email protected]>
Acked-by: Vlastimil Babka <[email protected]>
Cc: Charan Teja Kalla <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Li Zhe <[email protected]>
Cc: Michal Hocko <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
soleen authored and akpm00 committed Feb 3, 2023
1 parent 64517d6 commit 7ec7096
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions include/linux/page_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ struct page_ext_operations {
bool need_shared_flags;
};

extern bool deferred_struct_pages;

#ifdef CONFIG_PAGE_EXTENSION

/*
Expand Down
6 changes: 3 additions & 3 deletions init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -855,8 +855,8 @@ static void __init mm_init(void)
pgtable_init();
debug_objects_mem_init();
vmalloc_init();
/* Should be run after vmap initialization */
if (early_page_ext_enabled())
/* If no deferred init page_ext now, as vmap is fully initialized */
if (!deferred_struct_pages)
page_ext_init();
/* Should be run before the first non-init thread is created */
init_espfix_bsp();
Expand Down Expand Up @@ -1628,7 +1628,7 @@ static noinline void __init kernel_init_freeable(void)
padata_init();
page_alloc_init_late();
/* Initialize page ext after all struct pages are initialized. */
if (!early_page_ext_enabled())
if (deferred_struct_pages)
page_ext_init();

do_basic_setup();
Expand Down
6 changes: 5 additions & 1 deletion mm/page_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ EXPORT_SYMBOL(nr_online_nodes);

int page_group_by_mobility_disabled __read_mostly;

bool deferred_struct_pages __meminitdata;

#ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT
/*
* During boot we initialize deferred pages on-demand, as needed, but once
Expand Down Expand Up @@ -6803,8 +6805,10 @@ void __meminit memmap_init_range(unsigned long size, int nid, unsigned long zone
if (context == MEMINIT_EARLY) {
if (overlap_memmap_init(zone, &pfn))
continue;
if (defer_init(nid, pfn, zone_end_pfn))
if (defer_init(nid, pfn, zone_end_pfn)) {
deferred_struct_pages = true;
break;
}
}

page = pfn_to_page(pfn);
Expand Down
2 changes: 1 addition & 1 deletion mm/page_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ unsigned long page_ext_size;
static unsigned long total_usage;
static struct page_ext *lookup_page_ext(const struct page *page);

bool early_page_ext;
bool early_page_ext __meminitdata;
static int __init setup_early_page_ext(char *str)
{
early_page_ext = true;
Expand Down

0 comments on commit 7ec7096

Please sign in to comment.