linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Pratyush Yadav <pratyush@kernel.org>
Cc: Alexander Graf <graf@amazon.com>,
	Changyuan Lyu <changyuanl@google.com>,
	Pasha Tatashin <pasha.tatashin@soleen.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Baoquan He <bhe@redhat.com>,
	kexec@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [PATCH] kho: initialize tail pages for higher order folios properly
Date: Mon, 9 Jun 2025 22:36:48 +0300	[thread overview]
Message-ID: <aEc30BoLE9HRxiZm@kernel.org> (raw)
In-Reply-To: <mafs0jz5osutx.fsf@kernel.org>

Hi Pratyush,

On Fri, Jun 06, 2025 at 06:23:06PM +0200, Pratyush Yadav wrote:
> Hi Mike,
> 
> On Fri, Jun 06 2025, Mike Rapoport wrote:
> 
> > On Thu, Jun 05, 2025 at 07:11:41PM +0200, Pratyush Yadav wrote:
> >> From: Pratyush Yadav <ptyadav@amazon.de>
> >> 
> >> --- a/kernel/kexec_handover.c
> >> +++ b/kernel/kexec_handover.c
> >> @@ -157,11 +157,21 @@ static int __kho_preserve_order(struct kho_mem_track *track, unsigned long pfn,
> >>  }
> >> 
> >>  /* almost as free_reserved_page(), just don't free the page */
> >> -static void kho_restore_page(struct page *page)
> >> +static void kho_restore_page(struct page *page, unsigned int order)
> >>  {
> >> -	ClearPageReserved(page);
> >
> > So now we don't clear PG_Reserved even on order-0 pages? ;-)
> 
> We don't need to. As I mentioned in the commit message as well,
> PG_Reserved is never set for KHO pages since they are reserved with
> MEMBLOCK_RSRV_NOINIT, so memmap_init_reserved_pages() skips over them.

You are right, I missed it.
 
> That said, while reading through some of the code, I noticed another
> bug: because KHO reserves the preserved pages as NOINIT, with
> CONFIG_DEFERRED_STRUCT_PAGE_INIT == n, all the pages get initialized
> when memmap_init_range() is called from setup_arch (paging_init() on
> x86). This happens before kho_memory_init(), so the KHO-preserved pages
> are not marked as reserved to memblock yet.
> 
> With deferred page init, some pages might not get initialized early, and
> get initialized after kho_memory_init(), by which time the KHO-preserved
> pages are marked as reserved. So, deferred_init_maxorder() will skip
> over those pages and leave them uninitialized.
> 
> So we need to either also call init_deferred_page(), or remove the
> memblock_reserved_mark_noinit() call in deserialize_bitmap(). And TBH, I
> am not sure why KHO pages even need to be marked noinit in the first
> place. Probably the only benefit would be if a large chunk of memory is
> KHO-preserved, the pages can be initialized later on-demand, reducing
> bootup time a bit.

One benefit is performance indeed, because in not deferred case the
initialization of reserved pages in memmap_init_reserved_pages() is really
excessive.

But more importantly, if we remove memblock_reserved_mark_noinit(), with
CONFIG_DEFERRED_STRUCT_PAGE_INIT we'd loose page->private because the
struct page will be cleared after kho_mem_deserialize().
 
> What do you think? Should we drop noinit or call init_deferred_page()?
> FWIW, my preference is to drop noinit, since init_deferred_page() is
> __meminit and we would have to make sure it doesn't go away after boot.

We can't drop noinit and calling init_deferred_page() after boot just won't
work because it uses memblock to find the page's node and memblock is gone
after init.

The simplest short-term solution is to disable KHO when
CONFIG_DEFERRED_STRUCT_PAGE_INIT is set and then find an efficient way to
make it all work together.
 
-- 
Sincerely yours,
Mike.


  reply	other threads:[~2025-06-09 19:36 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-05 17:11 [PATCH] kho: initialize tail pages for higher order folios properly Pratyush Yadav
2025-06-05 20:13 ` Andrew Morton
2025-06-06  8:04 ` Mike Rapoport
2025-06-06 16:23   ` Pratyush Yadav
2025-06-09 19:36     ` Mike Rapoport [this message]
2025-06-09 20:07       ` Pasha Tatashin
2025-06-10  5:44         ` Mike Rapoport
2025-06-10 11:20           ` Pasha Tatashin
2025-06-10 16:41             ` Mike Rapoport
2025-06-10 22:33               ` Pasha Tatashin
2025-06-11 13:06                 ` Pratyush Yadav
2025-06-11 13:14                   ` Pasha Tatashin
2025-06-11 13:35                     ` Mike Rapoport
2025-06-11 14:01                       ` Pratyush Yadav
2025-06-11 14:36                         ` Mike Rapoport
2025-06-13 14:22                           ` Pratyush Yadav
2025-06-13 16:21                             ` Mike Rapoport
2025-06-11 13:38                     ` Pratyush Yadav

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=aEc30BoLE9HRxiZm@kernel.org \
    --to=rppt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=bhe@redhat.com \
    --cc=changyuanl@google.com \
    --cc=graf@amazon.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=pasha.tatashin@soleen.com \
    --cc=pratyush@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).