mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wei Yang <richard.weiyang@gmail.com>
To: "Liu, Yuan1" <yuan1.liu@intel.com>
Cc: "David Hildenbrand (Arm)" <david@kernel.org>,
	Oscar Salvador <osalvador@suse.de>,
	Mike Rapoport <rppt@kernel.org>,
	Wei Yang <richard.weiyang@gmail.com>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"Zou, Nanhai" <nanhai.zou@intel.com>,
	"Deng, Pan" <pan.deng@intel.com>,
	"Li, Tianyou" <tianyou.li@intel.com>,
	Chen Zhang <zhangchen.kidd@jd.com>,
	"Zeng, Jason" <jason.zeng@intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v6 1/2] mm/memory_hotplug: optimize zone contiguous check when changing pfn range
Date: Sun, 9 Aug 2026 03:12:05 +0000	[thread overview]
Message-ID: <20260809031205.h6skr3uluj3cnn7t@master> (raw)
In-Reply-To: <MW4PR11MB69363CCE15647FD7D85542B6A3D12@MW4PR11MB6936.namprd11.prod.outlook.com>

On Fri, Aug 07, 2026 at 12:15:42PM +0000, Liu, Yuan1 wrote:
>> -----Original Message-----
>> From: David Hildenbrand (Arm) <david@kernel.org>
>> Sent: Friday, August 7, 2026 7:30 PM
>> To: Liu, Yuan1 <yuan1.liu@intel.com>; Oscar Salvador <osalvador@suse.de>;
>> Mike Rapoport <rppt@kernel.org>; Wei Yang <richard.weiyang@gmail.com>
>> Cc: linux-mm@kvack.org; Zou, Nanhai <nanhai.zou@intel.com>; Deng, Pan
>> <pan.deng@intel.com>; Li, Tianyou <tianyou.li@intel.com>; Chen Zhang
>> <zhangchen.kidd@jd.com>; Zeng, Jason <jason.zeng@intel.com>; linux-
>> kernel@vger.kernel.org
>> Subject: Re: [PATCH v6 1/2] mm/memory_hotplug: optimize zone contiguous
>> check when changing pfn range
>> 
>> On 8/6/26 11:52, Liu, Yuan1 wrote:
>> >> -----Original Message-----
>> >> From: David Hildenbrand (Arm) <david@kernel.org>
>> >> Sent: Thursday, August 6, 2026 4:46 PM
>> >> To: Liu, Yuan1 <yuan1.liu@intel.com>; Oscar Salvador
>> <osalvador@suse.de>;
>> >> Mike Rapoport <rppt@kernel.org>; Wei Yang <richard.weiyang@gmail.com>
>> >> Cc: linux-mm@kvack.org; Zou, Nanhai <nanhai.zou@intel.com>; Deng, Pan
>> >> <pan.deng@intel.com>; Li, Tianyou <tianyou.li@intel.com>; Chen Zhang
>> >> <zhangchen.kidd@jd.com>; Zeng, Jason <jason.zeng@intel.com>; linux-
>> >> kernel@vger.kernel.org
>> >> Subject: Re: [PATCH v6 1/2] mm/memory_hotplug: optimize zone contiguous
>> >> check when changing pfn range
>> >>
>> >>
>> >>>
>> >>> Will do.
>> >>>
>> >>>
>> >>> pages_with_online_memmap counts all PFNs where pfn_to_online_page() is
>> >>> valid. With CONFIG_SPARSEMEM_VMEMMAP, pfn_section_valid() operates at
>> >>> PAGES_PER_SUBSECTION granularity — when any page in a subsection has
>> >>> memory, the entire subsection is valid/online. So we align to
>> subsection
>> >>> boundaries to include hole pages within partially-populated
>> subsections.
>> >>
>> >> But we must never account exceeding the zone range. So I don't
>> understand
>> >> why we
>> >> would have to care about PAGES_PER_SUBSECTION here at all?
>> >
>> > We never account beyond the zone range, because `sub_start` and
>> > `sub_end` are still clamped to the zone boundaries after the
>> > alignment.
>> >
>> > The subsection alignment is needed for hole PFNs between memblocks
>> > within the zone. These hole PFNs are valid for
>> > `pfn_to_online_page()`, because they sit in a subsection that has
>> > memory, so the whole subsection's memmap is online.
>> >
>> > |----------- zone range -----------|
>> >
>> > +-----------+---------+------------+
>> > + memblock 1|  hole   | memblock 2 |
>> > +-----------+---------+------------+
>> >                ^
>> >                |
>> >                |
>> >      subsection boundary
>> 
>> Right, but init_unavailable_range() can just return how many were actually
>> initalized? Why can't we piggy-back on that?
>> 
>> I think we had something similar previously, why can't we use that?
>> 
>> We know the zone span, so we can just account all the mmap in the zone
>> span
>> that we initialize.
>> 
>> What is the problem with that?
>
>Hi David
>
>My understanding is that init_unavailable_range() initializes all
>PFNs that satisfy pfn_valid(), but not all of them satisfy
>pfn_to_online_page(), since some PFNs belong to subsections that are
>not online.
>
>You previously mentioned:
>
>  pfn_valid() says early sections always have a full memmap, so even invalid
>  subsections have a memmap. pfn_to_online_page() says an invalid subsection
>  cannot be online and its content must be stale. for_each_valid_pfn() follows
>  pfn_valid() semantics, and we use it to initialize memmap that is not going
>  to be online and account it as pages_with_online_memmap, which is wrong.
>
>  The cleanest approach is to avoid allocating memmap for subsections, which
>  also removes the special early-section handling from pfn_valid() and
>  for_each_valid_pfn().
>
>I also share the concerns raised by Sashiko in the analysis below [1]:
>
>  Scanners like isolate_migratepages_block() will then blindly iterate through
>  the pageblock and access the completely uninitialized struct pages of the hole,
>  leading to functional errors or kernel panics when reading these zero-filled
>  structures via macros like PageHuge() or page_zone().
>
>That's why we went with the current approach in v6 instead of your
>earlier suggestion. I'd really appreciate your guidance on which
>direction you think would be more appropriate.
>
>[1] https://sashiko.dev/#/patchset/20260520093457.3719960-1-yuan1.liu%40intel.com
>

Hi, Yuan & David

One thing I found is __pageblock_pfn_to_page() is ambiguous when pageblock
contains 2 subsections.

The subsection size is fixed, which is 2^21=2M. But pageblock is not fixed
size. If !CONFIG_HUGETLB_PAGE && !CONFIG_TRANSPARENT_HUGEPAGE, default
pageblock size is 4K * 2 ^ 10 = 4M, which contains 2 subsection.

For a pageblock in early section, __paeblock_pfn_to_page() result is
different when the hole is at the beginning or at the end.

Like what I did in [1], I punch a hole in Zone Normal with 2M size.

If the hole is at the beginning of the pageblock, the zone is non-contiguous.

  [    0.004079]  memory[0x2]     [0x0000000100000000-0x000000013fffffff], 0x0000000040000000 bytes on node 0 flags: 0x0
  [    0.004080]  memory[0x3]     [0x0000000140200000-0x00000001bfffffff], 0x000000007fe00000 bytes on node 0 flags: 0x0
  
If the hole is at the end of the pageblock, the zone is contiguous.

  [    0.004068]  memory[0x2]     [0x0000000100000000-0x00000001401fffff], 0x0000000040200000 bytes on node 0 flags: 0x0
  [    0.004068]  memory[0x3]     [0x0000000140400000-0x00000001bfffffff], 0x000000007fc00000 bytes on node 0 flags: 0x0

The reason is in __pageblock_pfn_to_page() we have different requirement for
start_pfn and end_pfn.

Hmm... and things would be complicated as pageblock is PAGE based but
subsection is size based. If we have large PAGE_SIZE...

Also when pageblock_pfn_to_page() is introduced in commit 7d49d8868336 ("mm,
compaction: reduce zone checking frequency in the migration scanner"), we
assume there won't be [node0 node1 node0] interleave within a single pageblock.
Would this still stand for large PAGE_SIZE?

[1]: https://lore.kernel.org/all/20260408031615.1831922-1-yuan1.liu@intel.com/T/#u

>Best Regards,
>Liu, Yuan
>
>> Cheers,
>> 
>> David

-- 
Wei Yang
Help you, Help me

  reply	other threads:[~2026-08-09  3:12 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-23  8:49 [PATCH v6 0/2] " Yuan Liu
2026-07-23  8:49 ` [PATCH v6 1/2] " Yuan Liu
2026-08-05 11:53   ` David Hildenbrand (Arm)
2026-08-06  7:23     ` Liu, Yuan1
2026-08-06  8:45       ` David Hildenbrand (Arm)
2026-08-06  9:52         ` Liu, Yuan1
2026-08-07 11:29           ` David Hildenbrand (Arm)
2026-08-07 12:15             ` Liu, Yuan1
2026-08-09  3:12               ` Wei Yang [this message]
2026-08-10 14:04               ` David Hildenbrand (Arm)
2026-08-11 12:23                 ` David Hildenbrand (Arm)
2026-08-12  9:17                   ` Liu, Yuan1
2026-08-12 10:11                     ` David Hildenbrand (Arm)
2026-08-15  1:55                   ` Wei Yang
2026-08-19 15:57                     ` David Hildenbrand (Arm)
2026-07-23  8:49 ` [PATCH v6 2/2] mm/memory_hotplug: improve shrink_zone_span() subsection boundary checks Yuan Liu
2026-07-25  2:49   ` Wei Yang
2026-07-27  9:49     ` Liu, Yuan1
2026-07-30  2:36       ` Wei Yang
2026-07-30  7:57         ` Liu, Yuan1
2026-08-01  0:59           ` Wei Yang
2026-08-05 11:02   ` David Hildenbrand (Arm)
2026-08-06  7:14     ` Liu, Yuan1
2026-08-07  3:22     ` Wei Yang
2026-08-07 11:25       ` David Hildenbrand (Arm)
2026-08-05  9:40 ` [PATCH v6 0/2] mm/memory_hotplug: optimize zone contiguous check when changing pfn range Liu, Yuan1

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=20260809031205.h6skr3uluj3cnn7t@master \
    --to=richard.weiyang@gmail.com \
    --cc=david@kernel.org \
    --cc=jason.zeng@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nanhai.zou@intel.com \
    --cc=osalvador@suse.de \
    --cc=pan.deng@intel.com \
    --cc=rppt@kernel.org \
    --cc=tianyou.li@intel.com \
    --cc=yuan1.liu@intel.com \
    --cc=zhangchen.kidd@jd.com \
    /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

all inboxes | Powered by JetHome®