From patchwork Wed Jan 18 15:52:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13106608 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 AB339C32793 for ; Wed, 18 Jan 2023 15:52:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F5C16B0072; Wed, 18 Jan 2023 10:52:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 17F2E6B0073; Wed, 18 Jan 2023 10:52:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3AD26B0074; Wed, 18 Jan 2023 10:52:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E46186B0072 for ; Wed, 18 Jan 2023 10:52:56 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B581B4014B for ; Wed, 18 Jan 2023 15:52:56 +0000 (UTC) X-FDA: 80368363152.08.E1ADB44 Received: from mail-vs1-f53.google.com (mail-vs1-f53.google.com [209.85.217.53]) by imf05.hostedemail.com (Postfix) with ESMTP id 2F2B910000A for ; Wed, 18 Jan 2023 15:52:54 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=AqBeL7mq; spf=pass (imf05.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.217.53 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674057175; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=e11pkTomTpxVYwWB/x5AvRv96kjActm3EnkRXWTwwk8=; b=o0/dkCP4bSW2JOxui7TE0r+hQdisPxRM2mbbbQAG/spPEwyU6GY+TtiGI6ELa5q5yj86lx wc5WRofG1tlDRWdy5lP85mmjA1OeQfavnV5+Hw5D1vAbMeBLRY60m4wLNnCQ8ThDhA7jXQ oNouHXWG1t14+CUHjw7vaaC4iN+nCNw= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=AqBeL7mq; spf=pass (imf05.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.217.53 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674057175; a=rsa-sha256; cv=none; b=MM83HDgZAZk/JZEaLpt5+2+KJAT028gAou7C2vqiePr1IYR7sgtGXYW0XE1eYVQO5Vmptd Ng0uaZfGKSXt/8AbvFbp6qg34T4JAFAS+iDKNAsMzypX0S2TVhF2XUcJJE5SaKCNErc53x xyym+F+XNvoF3TDzFXo4awvjkFV+qo0= Received: by mail-vs1-f53.google.com with SMTP id q125so24425287vsb.0 for ; Wed, 18 Jan 2023 07:52:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=e11pkTomTpxVYwWB/x5AvRv96kjActm3EnkRXWTwwk8=; b=AqBeL7mq8lZay/paXXhXRpjjUJt08FG0+VU0ZB+QGYdRQOFLPBRNqL3f2d/9j0is0u nC5nf83+Zr3iIdMxFZ5v+PbCMljIQEZ4/YitGIpzM0Qr4OAyiDmJJnwkl/gcWLDtVPof y5M4pF3/e4Ch2yyIgXDvGLtEkimCCIq6390DO77T+SPfBnM7ooO9uB4bz/g7YzUONXzy oRLmErk8+FAC7Qp5rgxRpmal6VR2HL4vzdyfJ+xbfD8OhrlbjVi0p/1hOiYJ4JGkUsVc YQqunb6tYi3yrUadma6zoTzCssM7MmkzMpkH1e6janr+4wU5yfrR+UDySpft6rNGMZYm QrFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=e11pkTomTpxVYwWB/x5AvRv96kjActm3EnkRXWTwwk8=; b=u6Hwucc0/c5HKmoNH5Fpt1Vk3CP+Ab4bXfcap7NYRmK3uB5LZLpD8DDqPYfeiCpvFM wK42hedac9AzVLx+J95rn8x7ISO4IlI3RkZo/V/vhgKk4xy3inoGkxUNKDxoTjV+/rbG R374bCCNYPExUIQjNbtp3eqAWzlZaExRa6jjBUOb/wpd7RRESlW4pFGjMhPfa05cfTWv mSPddoZK7GplIo9z15ZuCF4hA+Gd3bvCqvPwGvnKvC3b4e8ShDlfudI3Sz0SpO6qfAAe i44Z+jKG0d+aQ7BxmotKONmWh0zbuGE4pfuK+0VUNggSENhrd1wF2ArOQlxxm9ch+kJx FQPw== X-Gm-Message-State: AFqh2kp1mB2RfnYguXO3FAXwD6NStgUWz321gfTLm34+mmvY/3nSNueh /ShZFt2SKrrhTGDgCGTlW7xfrA== X-Google-Smtp-Source: AMrXdXtDAtxod2Jf4LXcipYYXHgxbN+j/hk/GhDfBM+ha9kvUk5VE4+MCQIKH0XfpAJYh1JMjv3T4Q== X-Received: by 2002:a05:6102:941:b0:3ce:b848:d673 with SMTP id a1-20020a056102094100b003ceb848d673mr5109816vsi.32.1674057174121; Wed, 18 Jan 2023 07:52:54 -0800 (PST) Received: from soleen.c.googlers.com.com (193.132.150.34.bc.googleusercontent.com. [34.150.132.193]) by smtp.gmail.com with ESMTPSA id j9-20020a05620a288900b006f9f714cb6asm21935932qkp.50.2023.01.18.07.52.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 07:52:53 -0800 (PST) From: Pasha Tatashin To: pasha.tatashin@soleen.com, rppt@kernel.org, akpm@linux-foundation.org, mhocko@suse.com, vbabka@suse.cz, david@redhat.com, quic_charante@quicinc.com, lizhe.67@bytedance.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2] mm/page_ext: init page_ext early if there are no deferred struct pages Date: Wed, 18 Jan 2023 15:52:51 +0000 Message-Id: <20230118155251.2522985-1-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 2F2B910000A X-Stat-Signature: dawoqx1ff6e39hwrins9ij9hhxoaqi96 X-HE-Tag: 1674057174-754065 X-HE-Meta: U2FsdGVkX190IATVrXLvuLkBjnMPn2GGy8OI3jm2pq/DUo97w84lKmOClCZLdT6dnvVOUTo6tekAddpdjeQGwr1NtMC87TgkDeTOSkOWViKf3FKvMkZCsnyx4Gz5qNAQGRsyeAkFKVmCWpsNcd7hx0s7Vlm1kHauiJq4Uq6kKN4KOssL/qUUgBrls4ZWfnpWqwfsTldjrUDaUs1G9a6XBqym2hDANlt9JyB4uMG0zaMzxqz44q+1DqG1lSGMNvT3RcfaP1r+byAywv9N/6okAtAQx/OdtqWQfsez2dQPeqcnySZBgwgdJCdFH8xDrpAuvuMahDoA2VNrLou7upvjMDu2b/2yD7LRSvNzruAT6KTYgEHP2ZAiErA46rj4iP6+Udyqh40IVgTMCOPBUHr3l9kCEao3bNUh8hOmFWdVAw9SHEDXjyVqDDIjgFKhwIeSNHh2s34ikOOodt2j4eZj9p9Nxp3WJjUPvHhzh+WUR2jJxTozXMZEa+whmdZgMMwAJryylOQC4L4EqKuFurqJ2weVetn9YpAYDj1SaQ8ktdFm4El6eL8TublVNfA4h8wXs0v/dkRaSkwApw7YIlZcRJCU5TYFQB70XODc+HtEIYDT0bJd9GSzI6kaNd1pveCYNaW+c9Cf0t+1M7F03Mu+28R1qgWaJ88DyhYVQ/uZrEM+FuRJbZlSFWsAjKduE0YfUZhIC4/bHpJVXrR5Q2QupNOWKgFNwdSkHRZsAS8VRj8MFNvfo5+96UYwifgPoeixj43LngIP5CNKYikaY4HVubx6uAihPMFO9e8klZTuMXTPp9EFwn/NJR9gPQh2x7vdkXyepSE+Nn4zhwwyEC5iqGcX/fLdAE+ouHxUypwCD8segajKMw1GzOuuud2wcfOgFMcOy/HsjAMHhZmhmvOYuNynvlPI+ZF32OoGK2BnqTJRG5zVBrFrvIU2KUom1mqbKr+RJKrScR3SgHW2qse 5zXBq6sZ MCleyOQcrzde5jIjbou0pHf3Te6QPtKXrBVGGTnp4W1Lhu8qBUIHXFPYyKz/s+0mNOaJ8mvXfFGqWpVg0ItFEKUusH1a/SvCIIpu1E9oVKv0QkKOaNSfvYOmMBVFoy/TCyZQ5kmtHApFM7mG+4kxgITvvsg== 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: page_ext must be initialized after all struct pages are initialized. Therefore, page_ext is initialized after page_alloc_init_late(), and can optionally be initialized earlier via early_page_ext kernel parameter which as a side effect also disables deferred struct pages. Allow to automatically init page_ext early when there are no deferred struct pages in order to be able to use page_ext during kernel boot and track for example page allocations early. Signed-off-by: Pasha Tatashin Acked-by: Mike Rapoport (IBM) Acked-by: Vlastimil Babka --- include/linux/page_ext.h | 2 ++ init/main.c | 6 +++--- mm/page_alloc.c | 6 +++++- mm/page_ext.c | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) Changelog: v2: Fixed build issue with CONFIG_PAGE_EXTENSION=n diff --git a/include/linux/page_ext.h b/include/linux/page_ext.h index 67314f648aeb..bc2e39090a1f 100644 --- a/include/linux/page_ext.h +++ b/include/linux/page_ext.h @@ -29,6 +29,8 @@ struct page_ext_operations { bool need_shared_flags; }; +extern bool deferred_struct_pages; + #ifdef CONFIG_PAGE_EXTENSION /* diff --git a/init/main.c b/init/main.c index e1c3911d7c70..64cd2ff051c4 100644 --- a/init/main.c +++ b/init/main.c @@ -855,8 +855,8 @@ 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()) + /* If no deferred init page_ext now, as vmap is fully initialized */ + if (!deferred_struct_pages) page_ext_init(); /* Should be run before the first non-init thread is created */ init_espfix_bsp(); @@ -1628,7 +1628,7 @@ static noinline void __init kernel_init_freeable(void) padata_init(); page_alloc_init_late(); /* Initialize page ext after all struct pages are initialized. */ - if (!early_page_ext_enabled()) + if (deferred_struct_pages) page_ext_init(); do_basic_setup(); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 99ebb08dc3f2..717f12e83b85 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -430,6 +430,8 @@ EXPORT_SYMBOL(nr_online_nodes); int page_group_by_mobility_disabled __read_mostly; +bool deferred_struct_pages __meminitdata; + #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT /* * During boot we initialize deferred pages on-demand, as needed, but once @@ -6803,8 +6805,10 @@ void __meminit memmap_init_range(unsigned long size, int nid, unsigned long zone if (context == MEMINIT_EARLY) { if (overlap_memmap_init(zone, &pfn)) continue; - if (defer_init(nid, pfn, zone_end_pfn)) + if (defer_init(nid, pfn, zone_end_pfn)) { + deferred_struct_pages = true; break; + } } page = pfn_to_page(pfn); diff --git a/mm/page_ext.c b/mm/page_ext.c index e2c22ffdbb81..dc1626be458b 100644 --- a/mm/page_ext.c +++ b/mm/page_ext.c @@ -92,7 +92,7 @@ unsigned long page_ext_size; static unsigned long total_usage; static struct page_ext *lookup_page_ext(const struct page *page); -bool early_page_ext; +bool early_page_ext __meminitdata; static int __init setup_early_page_ext(char *str) { early_page_ext = true;