* [PATCH] mm/mm_init: Don't iterate pages below ARCH_PFN_OFFSET
@ 2025-04-18 16:27 Ruihan Li
2025-04-19 7:16 ` Mike Rapoport
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Ruihan Li @ 2025-04-18 16:27 UTC (permalink / raw)
To: Mike Rapoport, Andrew Morton, linux-mm; +Cc: linux-kernel, Ruihan Li
Currently, memmap_init initializes pfn_hole with 0 instead of
ARCH_PFN_OFFSET. Then init_unavailable_range will start iterating each
page from the page at address zero to the first available page, but it
won't do anything for pages below ARCH_PFN_OFFSET because pfn_valid
won't pass.
If ARCH_PFN_OFFSET is very large (e.g., something like 2^64-2GiB if the
kernel is used as a library and loaded at a very high address), the
pointless iteration for pages below ARCH_PFN_OFFSET will take a very
long time, and the kernel will look stuck at boot time.
This commit sets the initial value of pfn_hole to ARCH_PFN_OFFSET, which
avoids the problematic and useless iteration mentioned above.
Fixes: 907ec5fca3dc ("mm: zero remaining unavailable struct pages")
Signed-off-by: Ruihan Li <lrh2000@pku.edu.cn>
---
mm/mm_init.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/mm_init.c b/mm/mm_init.c
index 84f14fa12..b3ae9f797 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -966,7 +966,7 @@ static void __init memmap_init_zone_range(struct zone *zone,
static void __init memmap_init(void)
{
unsigned long start_pfn, end_pfn;
- unsigned long hole_pfn = 0;
+ unsigned long hole_pfn = ARCH_PFN_OFFSET;
int i, j, zone_id = 0, nid;
for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid) {
--
2.49.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/mm_init: Don't iterate pages below ARCH_PFN_OFFSET
2025-04-18 16:27 [PATCH] mm/mm_init: Don't iterate pages below ARCH_PFN_OFFSET Ruihan Li
@ 2025-04-19 7:16 ` Mike Rapoport
2025-04-19 12:08 ` Ruihan Li
2025-04-19 10:56 ` kernel test robot
2025-04-19 11:06 ` kernel test robot
2 siblings, 1 reply; 5+ messages in thread
From: Mike Rapoport @ 2025-04-19 7:16 UTC (permalink / raw)
To: Ruihan Li; +Cc: Andrew Morton, linux-mm, linux-kernel
On Sat, Apr 19, 2025 at 12:27:27AM +0800, Ruihan Li wrote:
> Currently, memmap_init initializes pfn_hole with 0 instead of
> ARCH_PFN_OFFSET. Then init_unavailable_range will start iterating each
> page from the page at address zero to the first available page, but it
> won't do anything for pages below ARCH_PFN_OFFSET because pfn_valid
> won't pass.
>
> If ARCH_PFN_OFFSET is very large (e.g., something like 2^64-2GiB if the
> kernel is used as a library and loaded at a very high address), the
> pointless iteration for pages below ARCH_PFN_OFFSET will take a very
> long time, and the kernel will look stuck at boot time.
>
> This commit sets the initial value of pfn_hole to ARCH_PFN_OFFSET, which
> avoids the problematic and useless iteration mentioned above.
>
> Fixes: 907ec5fca3dc ("mm: zero remaining unavailable struct pages")
I don't think it should be backported, this does not fix a bug.
> Signed-off-by: Ruihan Li <lrh2000@pku.edu.cn>
> ---
> mm/mm_init.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/mm_init.c b/mm/mm_init.c
> index 84f14fa12..b3ae9f797 100644
> --- a/mm/mm_init.c
> +++ b/mm/mm_init.c
> @@ -966,7 +966,7 @@ static void __init memmap_init_zone_range(struct zone *zone,
> static void __init memmap_init(void)
> {
> unsigned long start_pfn, end_pfn;
> - unsigned long hole_pfn = 0;
> + unsigned long hole_pfn = ARCH_PFN_OFFSET;
ARCH_PFN_OFFSET is defined only for FLATMEM, this won't even build for
SPARSEMEM.
> int i, j, zone_id = 0, nid;
>
> for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid) {
> --
> 2.49.0
>
>
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/mm_init: Don't iterate pages below ARCH_PFN_OFFSET
2025-04-18 16:27 [PATCH] mm/mm_init: Don't iterate pages below ARCH_PFN_OFFSET Ruihan Li
2025-04-19 7:16 ` Mike Rapoport
@ 2025-04-19 10:56 ` kernel test robot
2025-04-19 11:06 ` kernel test robot
2 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2025-04-19 10:56 UTC (permalink / raw)
To: Ruihan Li, Mike Rapoport, Andrew Morton
Cc: oe-kbuild-all, Linux Memory Management List, linux-kernel, Ruihan Li
Hi Ruihan,
kernel test robot noticed the following build errors:
[auto build test ERROR on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Ruihan-Li/mm-mm_init-Don-t-iterate-pages-below-ARCH_PFN_OFFSET/20250419-002910
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/20250418162727.1535335-1-lrh2000%40pku.edu.cn
patch subject: [PATCH] mm/mm_init: Don't iterate pages below ARCH_PFN_OFFSET
config: s390-randconfig-002-20250419 (https://download.01.org/0day-ci/archive/20250419/202504191858.5WVRkO7O-lkp@intel.com/config)
compiler: s390-linux-gcc (GCC) 7.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250419/202504191858.5WVRkO7O-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202504191858.5WVRkO7O-lkp@intel.com/
All errors (new ones prefixed by >>):
mm/mm_init.c: In function 'memmap_init':
>> mm/mm_init.c:975:27: error: 'ARCH_PFN_OFFSET' undeclared (first use in this function); did you mean 'PREEMPT_OFFSET'?
unsigned long hole_pfn = ARCH_PFN_OFFSET;
^~~~~~~~~~~~~~~
PREEMPT_OFFSET
mm/mm_init.c:975:27: note: each undeclared identifier is reported only once for each function it appears in
vim +975 mm/mm_init.c
971
972 static void __init memmap_init(void)
973 {
974 unsigned long start_pfn, end_pfn;
> 975 unsigned long hole_pfn = ARCH_PFN_OFFSET;
976 int i, j, zone_id = 0, nid;
977
978 for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid) {
979 struct pglist_data *node = NODE_DATA(nid);
980
981 for (j = 0; j < MAX_NR_ZONES; j++) {
982 struct zone *zone = node->node_zones + j;
983
984 if (!populated_zone(zone))
985 continue;
986
987 memmap_init_zone_range(zone, start_pfn, end_pfn,
988 &hole_pfn);
989 zone_id = j;
990 }
991 }
992
993 /*
994 * Initialize the memory map for hole in the range [memory_end,
995 * section_end] for SPARSEMEM and in the range [memory_end, memmap_end]
996 * for FLATMEM.
997 * Append the pages in this hole to the highest zone in the last
998 * node.
999 */
1000 #ifdef CONFIG_SPARSEMEM
1001 end_pfn = round_up(end_pfn, PAGES_PER_SECTION);
1002 #else
1003 end_pfn = round_up(end_pfn, MAX_ORDER_NR_PAGES);
1004 #endif
1005 if (hole_pfn < end_pfn)
1006 init_unavailable_range(hole_pfn, end_pfn, zone_id, nid);
1007 }
1008
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/mm_init: Don't iterate pages below ARCH_PFN_OFFSET
2025-04-18 16:27 [PATCH] mm/mm_init: Don't iterate pages below ARCH_PFN_OFFSET Ruihan Li
2025-04-19 7:16 ` Mike Rapoport
2025-04-19 10:56 ` kernel test robot
@ 2025-04-19 11:06 ` kernel test robot
2 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2025-04-19 11:06 UTC (permalink / raw)
To: Ruihan Li, Mike Rapoport, Andrew Morton
Cc: llvm, oe-kbuild-all, Linux Memory Management List, linux-kernel,
Ruihan Li
Hi Ruihan,
kernel test robot noticed the following build errors:
[auto build test ERROR on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Ruihan-Li/mm-mm_init-Don-t-iterate-pages-below-ARCH_PFN_OFFSET/20250419-002910
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/20250418162727.1535335-1-lrh2000%40pku.edu.cn
patch subject: [PATCH] mm/mm_init: Don't iterate pages below ARCH_PFN_OFFSET
config: s390-randconfig-001-20250419 (https://download.01.org/0day-ci/archive/20250419/202504191834.zUYILN1L-lkp@intel.com/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project f819f46284f2a79790038e1f6649172789734ae8)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250419/202504191834.zUYILN1L-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202504191834.zUYILN1L-lkp@intel.com/
All errors (new ones prefixed by >>):
>> mm/mm_init.c:975:27: error: use of undeclared identifier 'ARCH_PFN_OFFSET'
975 | unsigned long hole_pfn = ARCH_PFN_OFFSET;
| ^
1 error generated.
vim +/ARCH_PFN_OFFSET +975 mm/mm_init.c
971
972 static void __init memmap_init(void)
973 {
974 unsigned long start_pfn, end_pfn;
> 975 unsigned long hole_pfn = ARCH_PFN_OFFSET;
976 int i, j, zone_id = 0, nid;
977
978 for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid) {
979 struct pglist_data *node = NODE_DATA(nid);
980
981 for (j = 0; j < MAX_NR_ZONES; j++) {
982 struct zone *zone = node->node_zones + j;
983
984 if (!populated_zone(zone))
985 continue;
986
987 memmap_init_zone_range(zone, start_pfn, end_pfn,
988 &hole_pfn);
989 zone_id = j;
990 }
991 }
992
993 /*
994 * Initialize the memory map for hole in the range [memory_end,
995 * section_end] for SPARSEMEM and in the range [memory_end, memmap_end]
996 * for FLATMEM.
997 * Append the pages in this hole to the highest zone in the last
998 * node.
999 */
1000 #ifdef CONFIG_SPARSEMEM
1001 end_pfn = round_up(end_pfn, PAGES_PER_SECTION);
1002 #else
1003 end_pfn = round_up(end_pfn, MAX_ORDER_NR_PAGES);
1004 #endif
1005 if (hole_pfn < end_pfn)
1006 init_unavailable_range(hole_pfn, end_pfn, zone_id, nid);
1007 }
1008
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/mm_init: Don't iterate pages below ARCH_PFN_OFFSET
2025-04-19 7:16 ` Mike Rapoport
@ 2025-04-19 12:08 ` Ruihan Li
0 siblings, 0 replies; 5+ messages in thread
From: Ruihan Li @ 2025-04-19 12:08 UTC (permalink / raw)
To: Mike Rapoport; +Cc: Andrew Morton, linux-mm, linux-kernel, Ruihan Li
Hi Mike,
Thanks a lot for your review!
On Sat, Apr 19, 2025 at 10:16:34AM +0300, Mike Rapoport wrote:
> On Sat, Apr 19, 2025 at 12:27:27AM +0800, Ruihan Li wrote:
> > Currently, memmap_init initializes pfn_hole with 0 instead of
> > ARCH_PFN_OFFSET. Then init_unavailable_range will start iterating each
> > page from the page at address zero to the first available page, but it
> > won't do anything for pages below ARCH_PFN_OFFSET because pfn_valid
> > won't pass.
> >
> > If ARCH_PFN_OFFSET is very large (e.g., something like 2^64-2GiB if the
> > kernel is used as a library and loaded at a very high address), the
> > pointless iteration for pages below ARCH_PFN_OFFSET will take a very
> > long time, and the kernel will look stuck at boot time.
> >
> > This commit sets the initial value of pfn_hole to ARCH_PFN_OFFSET, which
> > avoids the problematic and useless iteration mentioned above.
> >
> > Fixes: 907ec5fca3dc ("mm: zero remaining unavailable struct pages")
>
> I don't think it should be backported, this does not fix a bug.
I thought the Fixes tag only indicated that the problem existed since
the specific commit, not the need for a backport (since the backport
should only happen when someone sends or CC's the patch to the
linux-stable mailing list)?
But anyway, I'm going to remove the Fixes tag when I send v2.
>
> > Signed-off-by: Ruihan Li <lrh2000@pku.edu.cn>
> > ---
> > mm/mm_init.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/mm/mm_init.c b/mm/mm_init.c
> > index 84f14fa12..b3ae9f797 100644
> > --- a/mm/mm_init.c
> > +++ b/mm/mm_init.c
> > @@ -966,7 +966,7 @@ static void __init memmap_init_zone_range(struct zone *zone,
> > static void __init memmap_init(void)
> > {
> > unsigned long start_pfn, end_pfn;
> > - unsigned long hole_pfn = 0;
> > + unsigned long hole_pfn = ARCH_PFN_OFFSET;
>
> ARCH_PFN_OFFSET is defined only for FLATMEM, this won't even build for
> SPARSEMEM.
Sorry for my ignorance. I'm not familiar with the code and I'm only
testing the FLATMEM configuration. I'll send a v2 patch to fix this.
Thanks for pointing out my stupid mistake.
>
> > int i, j, zone_id = 0, nid;
> >
> > for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid) {
> > --
> > 2.49.0
> >
> >
>
> --
> Sincerely yours,
> Mike.
Thanks,
Ruihan Li
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-04-19 12:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-18 16:27 [PATCH] mm/mm_init: Don't iterate pages below ARCH_PFN_OFFSET Ruihan Li
2025-04-19 7:16 ` Mike Rapoport
2025-04-19 12:08 ` Ruihan Li
2025-04-19 10:56 ` kernel test robot
2025-04-19 11:06 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox