2022-08-25 11:11:43

by lizhe.67

[permalink] [raw]
Subject: [PATCH v4] page_ext: introduce boot parameter 'early_page_ext'

From: Li Zhe <[email protected]>

In 'commit 2f1ee0913ce5 ("Revert "mm: use early_pfn_to_nid in page_ext_init"")',
we call page_ext_init() after page_alloc_init_late() to avoid some panic
problem. It seems that we cannot track early page allocations in current
kernel even if page structure has been initialized early.

This patch introduce a new boot parameter 'early_page_ext' to resolve this
problem. If we pass it to kernel, function page_ext_init() will be moved
up and feature 'deferred initialization of struct pages' will be disabled
to initialize the page allocator early and prevent from the panic problem
above. It can help us to catch early page allocations. This is useful
especially when we find that the free memory value is not the same right
after different kernel booting.

Suggested-by: Michal Hocko <[email protected]>
Signed-off-by: Li Zhe <[email protected]>
---
Changelogs:

v1->v2:
- use a cmd line parameter to move up function page_ext_init() instead of
using CONFIG_DEFERRED_STRUCT_PAGE_INIT
- fix oom problem[1]

v2->v3:
- move the judgment out of page_ext_init()

v3->v4:
- remove dependency on CONFIG_DEFERRED_STRUCT_PAGE_INIT
- modify descriptions in git log && kernel-parameters.txt

v1 patch: https://lore.kernel.org/lkml/[email protected]/T/
v2 patch: https://lore.kernel.org/lkml/[email protected]/T/
v3 patch: https://lore.kernel.org/linux-mm/[email protected]/T/

[1]: https://lore.kernel.org/linux-mm/YwHmXLu5txij+p35@xsang-OptiPlex-9020/

Documentation/admin-guide/kernel-parameters.txt | 8 ++++++++
include/linux/page_ext.h | 11 +++++++++++
init/main.c | 6 +++++-
mm/page_alloc.c | 2 ++
mm/page_ext.c | 8 ++++++++
5 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index d7f30902fda0..4f43fd5b324d 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1471,6 +1471,14 @@
Permit 'security.evm' to be updated regardless of
current integrity status.

+ early_page_ext [KNL] Enforces page_ext initialization to earlier
+ stages so cover more early boot allocations.
+ Please note that as side effect some optimizations
+ might be disabled to achieve that (e.g. parallelized
+ memory initialization is disabled) so the boot process
+ might take longer, especially on systems with a lot of
+ memory. Available with CONFIG_PAGE_EXTENSION=y.
+
failslab=
fail_usercopy=
fail_page_alloc=
diff --git a/include/linux/page_ext.h b/include/linux/page_ext.h
index fabb2e1e087f..884282a7f03a 100644
--- a/include/linux/page_ext.h
+++ b/include/linux/page_ext.h
@@ -36,9 +36,15 @@ struct page_ext {
unsigned long flags;
};

+extern bool early_page_ext;
extern unsigned long page_ext_size;
extern void pgdat_page_ext_init(struct pglist_data *pgdat);

+static inline bool early_page_ext_enabled(void)
+{
+ return early_page_ext;
+}
+
#ifdef CONFIG_SPARSEMEM
static inline void page_ext_init_flatmem(void)
{
@@ -67,6 +73,11 @@ static inline struct page_ext *page_ext_next(struct page_ext *curr)
#else /* !CONFIG_PAGE_EXTENSION */
struct page_ext;

+static inline bool early_page_ext_enabled(void)
+{
+ return false;
+}
+
static inline void pgdat_page_ext_init(struct pglist_data *pgdat)
{
}
diff --git a/init/main.c b/init/main.c
index 91642a4e69be..b5e75f3288d7 100644
--- a/init/main.c
+++ b/init/main.c
@@ -849,6 +849,9 @@ 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())
+ page_ext_init();
/* Should be run before the first non-init thread is created */
init_espfix_bsp();
/* Should be run after espfix64 is set up. */
@@ -1606,7 +1609,8 @@ static noinline void __init kernel_init_freeable(void)
padata_init();
page_alloc_init_late();
/* Initialize page ext after all struct pages are initialized. */
- page_ext_init();
+ if (!early_page_ext_enabled())
+ page_ext_init();

do_basic_setup();

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index e5486d47406e..e2faa52cd05d 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -482,6 +482,8 @@ defer_init(int nid, unsigned long pfn, unsigned long end_pfn)
{
static unsigned long prev_end_pfn, nr_initialised;

+ if (early_page_ext_enabled())
+ return false;
/*
* prev_end_pfn static that contains the end of previous zone
* No need to protect because called very early in boot before smp_init.
diff --git a/mm/page_ext.c b/mm/page_ext.c
index 3dc715d7ac29..6c28d623d951 100644
--- a/mm/page_ext.c
+++ b/mm/page_ext.c
@@ -85,6 +85,14 @@ unsigned long page_ext_size = sizeof(struct page_ext);

static unsigned long total_usage;

+bool early_page_ext __meminitdata;
+static int __init setup_early_page_ext(char *str)
+{
+ early_page_ext = true;
+ return 0;
+}
+early_param("early_page_ext", setup_early_page_ext);
+
static bool __init invoke_need_callbacks(void)
{
int i;
--
2.20.1


2022-08-25 11:35:05

by Michal Hocko

[permalink] [raw]
Subject: Re: [PATCH v4] page_ext: introduce boot parameter 'early_page_ext'

On Thu 25-08-22 18:27:14, [email protected] wrote:
> From: Li Zhe <[email protected]>
>
> In 'commit 2f1ee0913ce5 ("Revert "mm: use early_pfn_to_nid in page_ext_init"")',
> we call page_ext_init() after page_alloc_init_late() to avoid some panic
> problem. It seems that we cannot track early page allocations in current
> kernel even if page structure has been initialized early.
>
> This patch introduce a new boot parameter 'early_page_ext' to resolve this
> problem. If we pass it to kernel, function page_ext_init() will be moved
> up and feature 'deferred initialization of struct pages' will be disabled
> to initialize the page allocator early and prevent from the panic problem
> above. It can help us to catch early page allocations. This is useful
> especially when we find that the free memory value is not the same right
> after different kernel booting.
>
> Suggested-by: Michal Hocko <[email protected]>
> Signed-off-by: Li Zhe <[email protected]>

LGTM
Acked-by: Michal Hocko <[email protected]>
Thanks!

> ---
> Changelogs:
>
> v1->v2:
> - use a cmd line parameter to move up function page_ext_init() instead of
> using CONFIG_DEFERRED_STRUCT_PAGE_INIT
> - fix oom problem[1]
>
> v2->v3:
> - move the judgment out of page_ext_init()
>
> v3->v4:
> - remove dependency on CONFIG_DEFERRED_STRUCT_PAGE_INIT
> - modify descriptions in git log && kernel-parameters.txt
>
> v1 patch: https://lore.kernel.org/lkml/[email protected]/T/
> v2 patch: https://lore.kernel.org/lkml/[email protected]/T/
> v3 patch: https://lore.kernel.org/linux-mm/[email protected]/T/
>
> [1]: https://lore.kernel.org/linux-mm/YwHmXLu5txij+p35@xsang-OptiPlex-9020/
>
> Documentation/admin-guide/kernel-parameters.txt | 8 ++++++++
> include/linux/page_ext.h | 11 +++++++++++
> init/main.c | 6 +++++-
> mm/page_alloc.c | 2 ++
> mm/page_ext.c | 8 ++++++++
> 5 files changed, 34 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index d7f30902fda0..4f43fd5b324d 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -1471,6 +1471,14 @@
> Permit 'security.evm' to be updated regardless of
> current integrity status.
>
> + early_page_ext [KNL] Enforces page_ext initialization to earlier
> + stages so cover more early boot allocations.
> + Please note that as side effect some optimizations
> + might be disabled to achieve that (e.g. parallelized
> + memory initialization is disabled) so the boot process
> + might take longer, especially on systems with a lot of
> + memory. Available with CONFIG_PAGE_EXTENSION=y.
> +
> failslab=
> fail_usercopy=
> fail_page_alloc=
> diff --git a/include/linux/page_ext.h b/include/linux/page_ext.h
> index fabb2e1e087f..884282a7f03a 100644
> --- a/include/linux/page_ext.h
> +++ b/include/linux/page_ext.h
> @@ -36,9 +36,15 @@ struct page_ext {
> unsigned long flags;
> };
>
> +extern bool early_page_ext;
> extern unsigned long page_ext_size;
> extern void pgdat_page_ext_init(struct pglist_data *pgdat);
>
> +static inline bool early_page_ext_enabled(void)
> +{
> + return early_page_ext;
> +}
> +
> #ifdef CONFIG_SPARSEMEM
> static inline void page_ext_init_flatmem(void)
> {
> @@ -67,6 +73,11 @@ static inline struct page_ext *page_ext_next(struct page_ext *curr)
> #else /* !CONFIG_PAGE_EXTENSION */
> struct page_ext;
>
> +static inline bool early_page_ext_enabled(void)
> +{
> + return false;
> +}
> +
> static inline void pgdat_page_ext_init(struct pglist_data *pgdat)
> {
> }
> diff --git a/init/main.c b/init/main.c
> index 91642a4e69be..b5e75f3288d7 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -849,6 +849,9 @@ 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())
> + page_ext_init();
> /* Should be run before the first non-init thread is created */
> init_espfix_bsp();
> /* Should be run after espfix64 is set up. */
> @@ -1606,7 +1609,8 @@ static noinline void __init kernel_init_freeable(void)
> padata_init();
> page_alloc_init_late();
> /* Initialize page ext after all struct pages are initialized. */
> - page_ext_init();
> + if (!early_page_ext_enabled())
> + page_ext_init();
>
> do_basic_setup();
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index e5486d47406e..e2faa52cd05d 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -482,6 +482,8 @@ defer_init(int nid, unsigned long pfn, unsigned long end_pfn)
> {
> static unsigned long prev_end_pfn, nr_initialised;
>
> + if (early_page_ext_enabled())
> + return false;
> /*
> * prev_end_pfn static that contains the end of previous zone
> * No need to protect because called very early in boot before smp_init.
> diff --git a/mm/page_ext.c b/mm/page_ext.c
> index 3dc715d7ac29..6c28d623d951 100644
> --- a/mm/page_ext.c
> +++ b/mm/page_ext.c
> @@ -85,6 +85,14 @@ unsigned long page_ext_size = sizeof(struct page_ext);
>
> static unsigned long total_usage;
>
> +bool early_page_ext __meminitdata;
> +static int __init setup_early_page_ext(char *str)
> +{
> + early_page_ext = true;
> + return 0;
> +}
> +early_param("early_page_ext", setup_early_page_ext);
> +
> static bool __init invoke_need_callbacks(void)
> {
> int i;
> --
> 2.20.1

--
Michal Hocko
SUSE Labs

2022-08-25 12:42:30

by Vlastimil Babka

[permalink] [raw]
Subject: Re: [PATCH v4] page_ext: introduce boot parameter 'early_page_ext'

On 8/25/22 12:27, [email protected] wrote:
> From: Li Zhe <[email protected]>
>
> In 'commit 2f1ee0913ce5 ("Revert "mm: use early_pfn_to_nid in page_ext_init"")',
> we call page_ext_init() after page_alloc_init_late() to avoid some panic
> problem. It seems that we cannot track early page allocations in current
> kernel even if page structure has been initialized early.
>
> This patch introduce a new boot parameter 'early_page_ext' to resolve this
> problem. If we pass it to kernel, function page_ext_init() will be moved
> up and feature 'deferred initialization of struct pages' will be disabled
> to initialize the page allocator early and prevent from the panic problem
> above. It can help us to catch early page allocations. This is useful
> especially when we find that the free memory value is not the same right
> after different kernel booting.
>
> Suggested-by: Michal Hocko <[email protected]>
> Signed-off-by: Li Zhe <[email protected]>

Acked-by: Vlastimil Babka <[email protected]>

> ---
> Changelogs:
>
> v1->v2:
> - use a cmd line parameter to move up function page_ext_init() instead of
> using CONFIG_DEFERRED_STRUCT_PAGE_INIT
> - fix oom problem[1]
>
> v2->v3:
> - move the judgment out of page_ext_init()
>
> v3->v4:
> - remove dependency on CONFIG_DEFERRED_STRUCT_PAGE_INIT
> - modify descriptions in git log && kernel-parameters.txt
>
> v1 patch: https://lore.kernel.org/lkml/[email protected]/T/
> v2 patch: https://lore.kernel.org/lkml/[email protected]/T/
> v3 patch: https://lore.kernel.org/linux-mm/[email protected]/T/
>
> [1]: https://lore.kernel.org/linux-mm/YwHmXLu5txij+p35@xsang-OptiPlex-9020/
>
> Documentation/admin-guide/kernel-parameters.txt | 8 ++++++++
> include/linux/page_ext.h | 11 +++++++++++
> init/main.c | 6 +++++-
> mm/page_alloc.c | 2 ++
> mm/page_ext.c | 8 ++++++++
> 5 files changed, 34 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index d7f30902fda0..4f43fd5b324d 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -1471,6 +1471,14 @@
> Permit 'security.evm' to be updated regardless of
> current integrity status.
>
> + early_page_ext [KNL] Enforces page_ext initialization to earlier
> + stages so cover more early boot allocations.
> + Please note that as side effect some optimizations
> + might be disabled to achieve that (e.g. parallelized
> + memory initialization is disabled) so the boot process
> + might take longer, especially on systems with a lot of
> + memory. Available with CONFIG_PAGE_EXTENSION=y.
> +
> failslab=
> fail_usercopy=
> fail_page_alloc=
> diff --git a/include/linux/page_ext.h b/include/linux/page_ext.h
> index fabb2e1e087f..884282a7f03a 100644
> --- a/include/linux/page_ext.h
> +++ b/include/linux/page_ext.h
> @@ -36,9 +36,15 @@ struct page_ext {
> unsigned long flags;
> };
>
> +extern bool early_page_ext;
> extern unsigned long page_ext_size;
> extern void pgdat_page_ext_init(struct pglist_data *pgdat);
>
> +static inline bool early_page_ext_enabled(void)
> +{
> + return early_page_ext;
> +}
> +
> #ifdef CONFIG_SPARSEMEM
> static inline void page_ext_init_flatmem(void)
> {
> @@ -67,6 +73,11 @@ static inline struct page_ext *page_ext_next(struct page_ext *curr)
> #else /* !CONFIG_PAGE_EXTENSION */
> struct page_ext;
>
> +static inline bool early_page_ext_enabled(void)
> +{
> + return false;
> +}
> +
> static inline void pgdat_page_ext_init(struct pglist_data *pgdat)
> {
> }
> diff --git a/init/main.c b/init/main.c
> index 91642a4e69be..b5e75f3288d7 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -849,6 +849,9 @@ 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())
> + page_ext_init();
> /* Should be run before the first non-init thread is created */
> init_espfix_bsp();
> /* Should be run after espfix64 is set up. */
> @@ -1606,7 +1609,8 @@ static noinline void __init kernel_init_freeable(void)
> padata_init();
> page_alloc_init_late();
> /* Initialize page ext after all struct pages are initialized. */
> - page_ext_init();
> + if (!early_page_ext_enabled())
> + page_ext_init();
>
> do_basic_setup();
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index e5486d47406e..e2faa52cd05d 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -482,6 +482,8 @@ defer_init(int nid, unsigned long pfn, unsigned long end_pfn)
> {
> static unsigned long prev_end_pfn, nr_initialised;
>
> + if (early_page_ext_enabled())
> + return false;
> /*
> * prev_end_pfn static that contains the end of previous zone
> * No need to protect because called very early in boot before smp_init.
> diff --git a/mm/page_ext.c b/mm/page_ext.c
> index 3dc715d7ac29..6c28d623d951 100644
> --- a/mm/page_ext.c
> +++ b/mm/page_ext.c
> @@ -85,6 +85,14 @@ unsigned long page_ext_size = sizeof(struct page_ext);
>
> static unsigned long total_usage;
>
> +bool early_page_ext __meminitdata;
> +static int __init setup_early_page_ext(char *str)
> +{
> + early_page_ext = true;
> + return 0;
> +}
> +early_param("early_page_ext", setup_early_page_ext);
> +
> static bool __init invoke_need_callbacks(void)
> {
> int i;

2022-08-26 04:35:31

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH v4] page_ext: introduce boot parameter 'early_page_ext'

On Thu, 25 Aug 2022 18:27:14 +0800 [email protected] wrote:

> From: Li Zhe <[email protected]>
>
> In 'commit 2f1ee0913ce5 ("Revert "mm: use early_pfn_to_nid in page_ext_init"")',
> we call page_ext_init() after page_alloc_init_late() to avoid some panic
> problem. It seems that we cannot track early page allocations in current
> kernel even if page structure has been initialized early.
>
> This patch introduce a new boot parameter 'early_page_ext' to resolve this
> problem. If we pass it to kernel, function page_ext_init() will be moved
> up and feature 'deferred initialization of struct pages' will be disabled
> to initialize the page allocator early and prevent from the panic problem
> above. It can help us to catch early page allocations. This is useful
> especially when we find that the free memory value is not the same right
> after different kernel booting.
>

WARNING: modpost: vmlinux.o: section mismatch in reference: early_page_ext_enabled (section: .text.unlikely) -> early_page_ext (section: .meminit.data)
WARNING: modpost: vmlinux.o: section mismatch in reference: early_page_ext_enabled (section: .text.unlikely) -> early_page_ext (section: .meminit.data)

I did this, but it was lazy - perhaps there's a better-optimized
combination of section tags. Please check?

--- a/mm/page_ext.c~page_ext-introduce-boot-parameter-early_page_ext-fix
+++ a/mm/page_ext.c
@@ -91,7 +91,7 @@ unsigned long page_ext_size = sizeof(str
static unsigned long total_usage;
static struct page_ext *lookup_page_ext(const struct page *page);

-bool early_page_ext __meminitdata;
+bool early_page_ext;
static int __init setup_early_page_ext(char *str)
{
early_page_ext = true;
_

2022-08-26 10:49:27

by lizhe.67

[permalink] [raw]
Subject: Re: [PATCH v4] page_ext: introduce boot parameter 'early_page_ext'

On Thu, 25 Aug 2022 21:23:38 -0700, [email protected] wrote:
>On Thu, 25 Aug 2022 18:27:14 +0800 [email protected] wrote:
>
>> From: Li Zhe <[email protected]>
>>
>> In 'commit 2f1ee0913ce5 ("Revert "mm: use early_pfn_to_nid in page_ext_init"")',
>> we call page_ext_init() after page_alloc_init_late() to avoid some panic
>> problem. It seems that we cannot track early page allocations in current
>> kernel even if page structure has been initialized early.
>>
>> This patch introduce a new boot parameter 'early_page_ext' to resolve this
>> problem. If we pass it to kernel, function page_ext_init() will be moved
>> up and feature 'deferred initialization of struct pages' will be disabled
>> to initialize the page allocator early and prevent from the panic problem
>> above. It can help us to catch early page allocations. This is useful
>> especially when we find that the free memory value is not the same right
>> after different kernel booting.
>>
>
>WARNING: modpost: vmlinux.o: section mismatch in reference: early_page_ext_enabled (section: .text.unlikely) -> early_page_ext (section: .meminit.data)
>WARNING: modpost: vmlinux.o: section mismatch in reference: early_page_ext_enabled (section: .text.unlikely) -> early_page_ext (section: .meminit.data)

Sorry for introducing this WARNING. I did multiple checks before submitting
the patch but unluckily I didn't trigger this WARNING. Maybe there are some
differences of config in our compilation environment. I have tried gcc 8.3
and gcc 11.2.1.

>
>I did this, but it was lazy - perhaps there's a better-optimized
>combination of section tags. Please check?
>
>--- a/mm/page_ext.c~page_ext-introduce-boot-parameter-early_page_ext-fix
>+++ a/mm/page_ext.c
>@@ -91,7 +91,7 @@ unsigned long page_ext_size = sizeof(str
> static unsigned long total_usage;
> static struct page_ext *lookup_page_ext(const struct page *page);
>
>-bool early_page_ext __meminitdata;
>+bool early_page_ext;
> static int __init setup_early_page_ext(char *str)
> {
> early_page_ext = true;
>_

Thanks for the fix.
I try '__initdata', it triggers another WARNING below.

WARNING: modpost: vmlinux.o: section mismatch in reference: memmap_init_range (section: .meminit.text) -> early_page_ext (section: .init.data)

I check the section tags in include/linux/init.h. It seems that we don't have
a better choise. So in my opinion, your patch is the best solution.

2022-08-26 10:58:37

by Vlastimil Babka

[permalink] [raw]
Subject: Re: [PATCH v4] page_ext: introduce boot parameter 'early_page_ext'


On 8/26/22 06:23, Andrew Morton wrote:
> On Thu, 25 Aug 2022 18:27:14 +0800 [email protected] wrote:
>
>> From: Li Zhe <[email protected]>
>>
>> In 'commit 2f1ee0913ce5 ("Revert "mm: use early_pfn_to_nid in page_ext_init"")',
>> we call page_ext_init() after page_alloc_init_late() to avoid some panic
>> problem. It seems that we cannot track early page allocations in current
>> kernel even if page structure has been initialized early.
>>
>> This patch introduce a new boot parameter 'early_page_ext' to resolve this
>> problem. If we pass it to kernel, function page_ext_init() will be moved
>> up and feature 'deferred initialization of struct pages' will be disabled
>> to initialize the page allocator early and prevent from the panic problem
>> above. It can help us to catch early page allocations. This is useful
>> especially when we find that the free memory value is not the same right
>> after different kernel booting.
>>
>
> WARNING: modpost: vmlinux.o: section mismatch in reference: early_page_ext_enabled (section: .text.unlikely) -> early_page_ext (section: .meminit.data)
> WARNING: modpost: vmlinux.o: section mismatch in reference: early_page_ext_enabled (section: .text.unlikely) -> early_page_ext (section: .meminit.data)

Hm it's a very small static inline, shouldn't exist separately anywhere.
Maybe it's due to that new debug info level thing?

Would this work instead?

----8<----
diff --git a/include/linux/page_ext.h b/include/linux/page_ext.h
index 884282a7f03a..4bf4e58cf2d4 100644
--- a/include/linux/page_ext.h
+++ b/include/linux/page_ext.h
@@ -40,7 +40,7 @@ extern bool early_page_ext;
extern unsigned long page_ext_size;
extern void pgdat_page_ext_init(struct pglist_data *pgdat);

-static inline bool early_page_ext_enabled(void)
+static inline bool __meminit early_page_ext_enabled(void)
{
return early_page_ext;
}

2022-08-29 09:00:19

by lizhe.67

[permalink] [raw]
Subject: Re: [PATCH v4] page_ext: introduce boot parameter 'early_page_ext'

On 26 Aug 2022 12:49:25 +0200, [email protected] wrote:
>On 8/26/22 06:23, Andrew Morton wrote:
>> On Thu, 25 Aug 2022 18:27:14 +0800 [email protected] wrote:
>>
>>> From: Li Zhe <[email protected]>
>>>
>>> In 'commit 2f1ee0913ce5 ("Revert "mm: use early_pfn_to_nid in page_ext_init"")',
>>> we call page_ext_init() after page_alloc_init_late() to avoid some panic
>>> problem. It seems that we cannot track early page allocations in current
>>> kernel even if page structure has been initialized early.
>>>
>>> This patch introduce a new boot parameter 'early_page_ext' to resolve this
>>> problem. If we pass it to kernel, function page_ext_init() will be moved
>>> up and feature 'deferred initialization of struct pages' will be disabled
>>> to initialize the page allocator early and prevent from the panic problem
>>> above. It can help us to catch early page allocations. This is useful
>>> especially when we find that the free memory value is not the same right
>>> after different kernel booting.
>>>
>>
>> WARNING: modpost: vmlinux.o: section mismatch in reference: early_page_ext_enabled (section: .text.unlikely) -> early_page_ext (section: .meminit.data)
>> WARNING: modpost: vmlinux.o: section mismatch in reference: early_page_ext_enabled (section: .text.unlikely) -> early_page_ext (section: .meminit.data)
>
>Hm it's a very small static inline, shouldn't exist separately anywhere.
>Maybe it's due to that new debug info level thing?
>
>Would this work instead?
>
>----8<----
>diff --git a/include/linux/page_ext.h b/include/linux/page_ext.h
>index 884282a7f03a..4bf4e58cf2d4 100644
>--- a/include/linux/page_ext.h
>+++ b/include/linux/page_ext.h
>@@ -40,7 +40,7 @@ extern bool early_page_ext;
> extern unsigned long page_ext_size;
> extern void pgdat_page_ext_init(struct pglist_data *pgdat);
>
>-static inline bool early_page_ext_enabled(void)
>+static inline bool __meminit early_page_ext_enabled(void)
> {
> return early_page_ext;
> }

I think this is also a method to solve this problem.
Due to '__meminit', early_page_ext_enabled() can not be an inline function
now. So if we finally choose this method, I suggest we put function
early_page_ext_enabled() into page_ext.c if CONFIG_PAGE_EXTENSION=y, and
we can make 'early_page_ext' a static variable.