From patchwork Thu Jan 12 15:33:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13098237 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 78847C54EBC for ; Thu, 12 Jan 2023 15:33:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED08A8E0002; Thu, 12 Jan 2023 10:33:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E80408E0001; Thu, 12 Jan 2023 10:33:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D47D38E0002; Thu, 12 Jan 2023 10:33:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C40258E0001 for ; Thu, 12 Jan 2023 10:33:55 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9BC9A1A0605 for ; Thu, 12 Jan 2023 15:33:55 +0000 (UTC) X-FDA: 80346542430.01.4DC3A7F Received: from mail-oo1-f41.google.com (mail-oo1-f41.google.com [209.85.161.41]) by imf06.hostedemail.com (Postfix) with ESMTP id 15D3518000D for ; Thu, 12 Jan 2023 15:33:52 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b="F/vNL4nc"; spf=pass (imf06.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.161.41 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=1673537633; 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=3ubEBjBZWCZprxvg3hFb0J7l69r3LVSgsyPzd+ncfrs=; b=2HVP9GGP2kY7nFEyq79TuvobTfHqkmruhF4EqSPjz9NtHiqOTRVtf8b/S+OstodAqLDG4I y41K1VjZDsQBmYjwKODi+0W6dFJBBuQYwI/I0+o9Gq8kV+T8kGaQZYTBqsfjJ/vPs4oe9H uvQVKAWa3iHbDznvJoMp4TLbyfrkn0s= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b="F/vNL4nc"; spf=pass (imf06.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.161.41 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673537633; a=rsa-sha256; cv=none; b=baiwI7OzXjkNWkg7XzRgJWFTZbswPA+8iNs2UiqAMy5vCJqmyajGufARw/S0KQh8w/Lsmt 8rcJGH/x/3VeOqZIjQ6/T56TVjq16tRpB9fUlXC2MM3B4uEfKGxlKPnn4p+SJbc1QNYXzr qAxRoUEfDvKNSloYgVyLrsbqKfLz4JQ= Received: by mail-oo1-f41.google.com with SMTP id m23-20020a4abc97000000b004bfe105c580so4897204oop.4 for ; Thu, 12 Jan 2023 07:33:52 -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=3ubEBjBZWCZprxvg3hFb0J7l69r3LVSgsyPzd+ncfrs=; b=F/vNL4ncA2Wx1v6nHhyPY2j1Q6TgA7m1qi0ck+kX4IfwwviTOxM4YNEonMibKmrMgG 2U4yyzaBkI/wf4kFyXlzFQzfHD3p+rBmQtdE85GOIFMOeXpPVtQ54OMh1e87Am4CPdFm DPjuttNKso0QHW4cVVr0dDKvVV/HwrT257jH7NDWbXzPB+SW7D56JnDqK0CJDr9S1rl5 G2Pzk8BjRkof8WHiPNLH8TFHTQxR6IVlZdVoytWvDBiCkZhYpOti2pb71HiuO3egOTON 0z2iQgADIaQ2TjIBRAqvgOs7Moc+UKZd+H6XwJrp4pspbWvQ8TWDi5bJ48u5irNal845 2nLA== 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=3ubEBjBZWCZprxvg3hFb0J7l69r3LVSgsyPzd+ncfrs=; b=VA/P9/xfbJ1ugBwfS67dnydgbUfsWMtJ0DTOgrZNC6woys6BCdWJsA1H9fzDM947SK cBc7qGBB7kkxwAyJHoDU3o9c5JBbRZzc9wD/VCYJXaF1SJ34zNH/vmJBXR2PB3B4e9+v LWId5NJ318zvT8lkCrAbQgy6vAGdxH9Xwi47Yain52AWEeZcnrqLOl6iakJR+BZ/Ad4K spF44SEJhwpr0Kjht2CExmwc2xJANT0bZTpLCEH4D0bIMwLF8YYMe+AbysbLEXdZKbid 9Qns0Z8xGwqVo4170H/TXoRYMQmLjcx7jrG+JxLOqXrXyHmDVVtdrn3/cPT6EZDc23SH syzg== X-Gm-Message-State: AFqh2kqWeNkN1a/bOoqeruJqSfNjv35AaZYAiF7vRaOJwSjYf7tK4NSs xKyxwfBo12jt/vn+FiMPQFOByg== X-Google-Smtp-Source: AMrXdXs32cUCLr2B0L+g5wRnD/cB216iGpqeyA7gyHvA2oYBav2gm6xGjCyUSPYovsFYFANcwGWSyg== X-Received: by 2002:a05:6358:5bce:b0:ec:ed9a:9b4b with SMTP id i14-20020a0563585bce00b000eced9a9b4bmr154475rwf.7.1673537631552; Thu, 12 Jan 2023 07:33:51 -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 u8-20020a05620a454800b006fc7302cf89sm11113288qkp.28.2023.01.12.07.33.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 07:33:50 -0800 (PST) From: Pasha Tatashin To: pasha.tatashin@soleen.com, 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: Do not allocate space for page_ext->flags if not needed Date: Thu, 12 Jan 2023 15:33:48 +0000 Message-Id: <20230112153348.3202173-1-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 15D3518000D X-Stat-Signature: h16j35kd9z9nxp4ozryscagdb43bi6oz X-Rspam-User: X-HE-Tag: 1673537632-183445 X-HE-Meta: U2FsdGVkX1/drJMGpgMCVSdMtgjGpM5g8+4CXa8WxEPhb7L0TliYGdvwkzuFawUO6qYrA1HXBb7WfLy5hQUMz7AOvNSiv9PllxweBslFyYa+OmFvmMw3aIngPJ7plK9kiXUO2l5cSt3vbwQp7lFDLuooN5atL945FYosuJ85NcnymyvM9yn4XfHG7tZb8zNc28o51OmeTxPNFo821M6igNIXmFXanGqbhFBqN0NRQ7LZ9KWRPcAPDZ40YzqcZ8aHR/V7if+eCroLxwx+WUZbteZlgkBJ5r/cZ4+Shr0b+7A4ObDu/UH1Qi3/7+W1veiRq9oEAXvZIHJoPdnfeDxKwvhtcm/sBFuAt1AqsVM/OKdz11nPgAExjFGT098gbGBJ3s36Je/X6g1Ro/RssMdVh+eELZ4j1oJ/HPrCBMv1GzilpOcBrUIRcoBK9O78oMTdmrSvEl9Ug7Yv5qs9cTO4cnTSwxeceppGviIzxEJ1KVk4Ikw2fr5YbLqJ2R/nJ1DW2C61m8zBMCYwY2HeQmFXNxSQCntfsp08UAxDp9UfEToHG5ZluvcZ8A5FdF5AC8fFPgv82VGQKmOYeio9caTFInlx54H5xQfjarPurzjROOig3VsgZY5tw56CdFscwTk+q1yEuarDjfFkiZek30OzqEsf96x8sjMuImyjZZxDiUh1teNee/yaq5mqOdvBSVZ4y8clwBSBd+8TowZLc+R8kYQuB4F0cJIuyUFhNEW0gWkBR3+OrUjjKKYMJeg9DBpRp8DqFrRCdY4KyDK4pmS1xZztiRMdq/eq71ElgCycHzG6D5u3cJd6QTkw5JlSGKmCeBqZAxJwkaI98X0gk6v5I94S+C77vk++uLOoqRUSE/2sd5n8xHI9USf0T11dqjxu9oUS12gYBQ6KhCvAUm8TL+fMPqb7L/M6MWu1QLC8B4BQb45yv5LvZTM/zErHEV6CBHpPTEXtSA2s6Fu3Fft ciEANfsn xrDZ6DZoFnJ+TY2+IUsZD21sFQFn9WlzW+nme2XVfb1k/l1drVhN6NDoVE/SQhpySZccCR1i85AtxI6SciribAImjpKWCWqwxfe7bNHHmhPTIGRrasgP7M7/8xp4j5ygZ78uGOvUvPHIh9VTAwBgcSQENQg== 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: There is 8 byte page_ext->flags field allocated per page whenever CONFIG_PAGE_EXTENSION is enabled. However, not every user of page_ext uses flags. Therefore, check whether flags is needed at least by one user and if so allocate space for it. For example when page_table_check is enabled, on a machine with 128G of memory before the fix: [ 2.244288] allocated 536870912 bytes of page_ext after the fix: [ 2.160154] allocated 268435456 bytes of page_ext Signed-off-by: Pasha Tatashin --- include/linux/page_ext.h | 7 +++++++ mm/page_ext.c | 12 +++++++++++- mm/page_owner.c | 1 + mm/page_table_check.c | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) Changelog: v2: Fixed field name in page_owner.c that caused build error. diff --git a/include/linux/page_ext.h b/include/linux/page_ext.h index 22be4582faae..29909e135052 100644 --- a/include/linux/page_ext.h +++ b/include/linux/page_ext.h @@ -12,10 +12,14 @@ struct page_ext_operations { size_t size; bool (*need)(void); void (*init)(void); + bool using_shared_ext_flags; }; #ifdef CONFIG_PAGE_EXTENSION +/* + * The page_ext_flags users must set using_shared_ext_flags to true. + */ enum page_ext_flags { PAGE_EXT_OWNER, PAGE_EXT_OWNER_ALLOCATED, @@ -31,6 +35,9 @@ enum page_ext_flags { * page_ext helps us add more information about the page. * All page_ext are allocated at boot or memory hotplug event, * then the page_ext for pfn always exists. + * Note: that if none of the users of page_ext is setting + * using_shared_ext_flags to true, the field cannot be used, + * as it will be overlapped with another data. */ struct page_ext { unsigned long flags; diff --git a/mm/page_ext.c b/mm/page_ext.c index 4ee522fd381c..7443a797b96b 100644 --- a/mm/page_ext.c +++ b/mm/page_ext.c @@ -71,6 +71,7 @@ static bool need_page_idle(void) } static struct page_ext_operations page_idle_ops __initdata = { .need = need_page_idle, + .using_shared_ext_flags = true, }; #endif @@ -86,7 +87,7 @@ static struct page_ext_operations *page_ext_ops[] __initdata = { #endif }; -unsigned long page_ext_size = sizeof(struct page_ext); +unsigned long page_ext_size; static unsigned long total_usage; static struct page_ext *lookup_page_ext(const struct page *page); @@ -105,6 +106,15 @@ static bool __init invoke_need_callbacks(void) int entries = ARRAY_SIZE(page_ext_ops); bool need = false; + for (i = 0; i < entries; i++) { + if (page_ext_ops[i]->need && page_ext_ops[i]->need()) { + if (page_ext_ops[i]->using_shared_ext_flags) { + page_ext_size = sizeof(struct page_ext); + break; + } + } + } + for (i = 0; i < entries; i++) { if (page_ext_ops[i]->need && page_ext_ops[i]->need()) { page_ext_ops[i]->offset = page_ext_size; diff --git a/mm/page_owner.c b/mm/page_owner.c index 2d27f532df4c..1a62ab3fc00e 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -99,6 +99,7 @@ struct page_ext_operations page_owner_ops = { .size = sizeof(struct page_owner), .need = need_page_owner, .init = init_page_owner, + .using_shared_ext_flags = true, }; static inline struct page_owner *get_page_owner(struct page_ext *page_ext) diff --git a/mm/page_table_check.c b/mm/page_table_check.c index 93e633c1d587..74cfe89d5f53 100644 --- a/mm/page_table_check.c +++ b/mm/page_table_check.c @@ -45,6 +45,7 @@ struct page_ext_operations page_table_check_ops = { .size = sizeof(struct page_table_check), .need = need_page_table_check, .init = init_page_table_check, + .using_shared_ext_flags = false, }; static struct page_table_check *get_page_table_check(struct page_ext *page_ext)