From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1CE0C5B543 for ; Tue, 10 Jun 2025 11:21:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 724336B008A; Tue, 10 Jun 2025 07:21:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6ADE76B008C; Tue, 10 Jun 2025 07:21:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C3C06B0092; Tue, 10 Jun 2025 07:21:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3BF5A6B008A for ; Tue, 10 Jun 2025 07:21:04 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EADB0BF6B6 for ; Tue, 10 Jun 2025 11:21:03 +0000 (UTC) X-FDA: 83539249206.02.8F5E0A6 Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) by imf27.hostedemail.com (Postfix) with ESMTP id 1833E40002 for ; Tue, 10 Jun 2025 11:21:01 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=KUVRmlLr; spf=pass (imf27.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.170 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1749554462; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Hr6vkvNJmo2xkK9euicJYSo2Erx9EUnaEaDLPPm5ZFw=; b=TvqBxFlMJNaq1+yP0LqWz3UEtMGVAlpj7MOozLGVtlu3grMAiZlyE1KIi0yMqDs894exGL jtGuw5BMK4dg3nQMwVitWEm5sDZLveHHmXojBqzeQqkqWt/GlbO1YQI4wCxTTuS6HC3XAf jlxMXL+J4pWOrptTPQcB9IiQovPT1ww= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=KUVRmlLr; spf=pass (imf27.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.170 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1749554462; a=rsa-sha256; cv=none; b=C2LQUvxpj1xTvz27o+YGW5VTKrCjx31h6IKDf9kT5fi93Ro0NNcuriMkyLd9/VcC0bXEuI wCaGUpKT8YRG2cJzm43ovU1VwfsTH6F2dWsrZUDDa3saGS8zYIll5A7gilGeIJTkwSNvr/ CRSobYwMbal+KmAQ3Pjg65tTbbvTqdA= Received: by mail-qt1-f170.google.com with SMTP id d75a77b69052e-476a720e806so48872091cf.0 for ; Tue, 10 Jun 2025 04:21:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1749554461; x=1750159261; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Hr6vkvNJmo2xkK9euicJYSo2Erx9EUnaEaDLPPm5ZFw=; b=KUVRmlLrE/XHCD68RbZj6a3zyRIJF0xfvzItPCcYfQqTlyOf6XQVxgYC4fNyBXNHq0 cuKXvukZDAIeYMzLW6kM9b7Gl9EDmt6ta1ELGrrp7xzOs1jitXmLeo+pJOjvlVoPS8MF cRB7mNd1prkBiis6o4HUvDj80k+Xj8eBb/vQAHtvIeJdug8Sfdu48aEIU62Ldkl7L8VK RgeskAXpDs1jSomeOG3kxA3tLEV6BwgQKSBNPDPXh62Dj73MgxI2H7uEGnmG/kSqc7NX j0zFdZOErGGJ5QXxhPnlcx7XRK6afaWnhgRCN34ccwdT+a6bkEIH/e3xooqhiNjf5RnN PnSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749554461; x=1750159261; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Hr6vkvNJmo2xkK9euicJYSo2Erx9EUnaEaDLPPm5ZFw=; b=FEX9SfcZU6LBfBHYZLaBRvpjY1pJiLq1RKQfzwlQHuofMY0QMeZF/JU82OB4cs8EiJ imRLnCJngUmfVHEh7aUB+kvqQbSkg8CgU1iwZAw/Z42w/rzVNMSciL7FG92ahVHW8bk+ r00IVSjChWXZCWS7jIxKuj+W3A8BuGUq0o1VkoTDgYWXVxmQr4Cy0dyH9iFXL4aag0zX 2A3hYRO55rdP2WEDURoZAHWodWPmov07wnL4WzgG3ZOKLzkBMKK8sqxNMOgPJcp01Ru3 jSYzTXvl9D4RAVmWlh6zDppDWfEz+bENcdsyOsbXHgq/KRAScgRm0sO66Y1Ea4opjTDc pklw== X-Forwarded-Encrypted: i=1; AJvYcCV4syWCZJXDRjrAd4T5Fx6FHBhiGtp/3MTWBBBftnSIqFIZGuXYZ7n6G4lkmI7SBAreM0ppT3oVjg==@kvack.org X-Gm-Message-State: AOJu0YxqbWqY/rTJG/va27dXWZBvJa7teKI8ItOoh94iigWBLV+JWmfz Rtq+ovRiuoTdCZwQ8TVQu+QXa3RqY5VRQq1c7w2r/Rn6q3+ZYUuY6rtlTTXtRejFZnpDnMEm0+7 6PhGkqJT9bTfTFdsjDRsBZcy/YvS33s75hGptPfT26A== X-Gm-Gg: ASbGnctsJzFGvsVaHlij99k1QJ5QldalIDIB8tohLPFXdQM7hK/RpDz8mf8k+H6nfBq BV9BhWKRfy/rFzthUaiU945LBeQlFlzI9BMxROWs/VBXWeQLf54tW9Re+M3CZpTbpi66svGeKQn f7IRp65L12q3Ak04TGZFNJzEbzqoa540HilUx8K+34 X-Google-Smtp-Source: AGHT+IEYByUVl/yepIaYoB2uxlybeMfdVCnOM2tCCnTwmK/gNk4T3vDFpOGjgIevx5sWAC+4GR5rpfJ+v3CSPkSnqY4= X-Received: by 2002:a05:622a:4d87:b0:4a4:39a6:93d6 with SMTP id d75a77b69052e-4a5b9dec472mr350827001cf.52.1749554461120; Tue, 10 Jun 2025 04:21:01 -0700 (PDT) MIME-Version: 1.0 References: <20250605171143.76963-1-pratyush@kernel.org> In-Reply-To: From: Pasha Tatashin Date: Tue, 10 Jun 2025 07:20:23 -0400 X-Gm-Features: AX0GCFuL7c_RAoZ4ZCdyX1YlCD0SjPG2cCCnRF6R-Ws5F5HXOirJt-HVRYtvgUQ Message-ID: Subject: Re: [PATCH] kho: initialize tail pages for higher order folios properly To: Mike Rapoport Cc: Pratyush Yadav , Alexander Graf , Changyuan Lyu , Andrew Morton , Baoquan He , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 1833E40002 X-Stat-Signature: dwz1xk6x6zxt7ihm6djpx3dsm9himuor X-Rspam-User: X-HE-Tag: 1749554461-774459 X-HE-Meta: U2FsdGVkX1+HJetIEUi4lyN4muGYklTKoeEXKAA0oZQerccXn+lpDY07s1XUBBXKOg3pA6/oc9vG6/4osU55iQ6nIDQx0KSjT94awfUGvlcfyV81g5v3s1gI2iatDacCCape4PGRBtkfx6ObG9bGvq4KkETFmv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8PQxDsHf51He9glXLpxYdFFQTETY1j4JIK09fQpdWtLNglTB1S2gOs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Jun 10, 2025 at 1:44=E2=80=AFAM Mike Rapoport wro= te: > > On Mon, Jun 09, 2025 at 04:07:50PM -0400, Pasha Tatashin wrote: > > On Mon, Jun 9, 2025 at 3:36=E2=80=AFPM Mike Rapoport = wrote: > > > > > > 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 > > > > >> > > > > >> --- 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 or= der) > > > > >> { > > > > >> - 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 th= em. > > > > > > You are right, I missed it. > > > > > > > That said, while reading through some of the code, I noticed anothe= r > > > > bug: because KHO reserves the preserved pages as NOINIT, with > > > > CONFIG_DEFERRED_STRUCT_PAGE_INIT =3D=3D n, all the pages get initia= lized > > > > when memmap_init_range() is called from setup_arch (paging_init() o= n > > > > x86). This happens before kho_memory_init(), so the KHO-preserved p= ages > > > > 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-pres= erved > > > > pages are marked as reserved. So, deferred_init_maxorder() will ski= p > > > > 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 T= BH, I > > > > am not sure why KHO pages even need to be marked noinit in the firs= t > > > > place. Probably the only benefit would be if a large chunk of memor= y is > > > > KHO-preserved, the pages can be initialized later on-demand, reduci= ng > > > > 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 r= eally > > > excessive. > > > > > > But more importantly, if we remove memblock_reserved_mark_noinit(), w= ith > > > 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() i= s > > > > __meminit and we would have to make sure it doesn't go away after b= oot. > > > > > > 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 wa= y to > > > make it all work together. > > > > This is what I've done in LUOv3 WIP: > > https://github.com/soleen/linux/commit/3059f38ac0a39a397873759fb429bd5d= 1f8ea681 > > I think it should be the other way around, KHO should depend on > !DEFERRED_STRUCT_PAGE_INIT. Agreed, and this is what I first tried, but that does not work, there is some circular dependency breaking the build. If you feel adventurous you can try that :-) > > We will need to teah KHO to work with deferred struct page init. I > > suspect, we could init preserved struct pages and then skip over them > > during deferred init. > > We could, but with that would mean we'll run this before SMP and it's not > desirable. Also, init_deferred_page() for a random page requires We already run KHO init before smp_init: start_kernel() -> mm_core_init() -> kho_memory_init() -> kho_restore_folio() -> struct pages must be already initialized here! While deferred struct pages are initialized: start_kernel() -> rest_init() -> kernel_init() -> kernel_init_freeable() -> page_alloc_init_late() -> deferred_init_memmap() If the number of preserved pages that is needed during early boot is relatively small, that it should not be an issue to pre-initialize struct pages for them before deferred struct pages are initialized. We already pre-initialize some "struct pages" that are needed during early boot before the reset are initialized, see deferred_grow_zone() Pasha