From patchwork Wed Jan 11 21:59:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13097279 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 772BEC46467 for ; Wed, 11 Jan 2023 21:59:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB60B8E0002; Wed, 11 Jan 2023 16:59:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C66308E0001; Wed, 11 Jan 2023 16:59:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B2DDD8E0002; Wed, 11 Jan 2023 16:59:12 -0500 (EST) 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 A57618E0001 for ; Wed, 11 Jan 2023 16:59:12 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7B42B1A0AE1 for ; Wed, 11 Jan 2023 21:59:12 +0000 (UTC) X-FDA: 80343884544.03.C76CFC0 Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by imf05.hostedemail.com (Postfix) with ESMTP id DDF46100007 for ; Wed, 11 Jan 2023 21:59:10 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=CmstqYp9; spf=pass (imf05.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.175 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=1673474351; 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=hLlRGFfxK+N0AdFFVO3VU9eoPoiCOoB3+UBhQVqyXOc=; b=vjWcfY5v+qFZEaZn9C4ZkZeWQfao1tkfmjzsvSWpiAOA4Xiim4op7n6onGrlIymXMToxzM 24JMipX6pOei5hVfHWViTpUffri55L8vhCCLEXCO9yP8gnVBTogY0kZGI/NjxnFgW6B3pW 7O44xxW34x2nUlSNMANBtXiFCHF0YzA= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=CmstqYp9; spf=pass (imf05.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.175 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673474351; a=rsa-sha256; cv=none; b=H9O0B4qPX679MskMr/+4iywcF2OdFUrjTMGZGz+LU7f5o9+wzkeV3dCosRK43G97kUdAtt q+tHp58mEbNDnn/tImHSWup2VCjdcXg7BTnNtd0Wyx7dW00Tx6clPuaE3InzYbj/22QkFw CIAlRdJBbU0VeEsf6ZWop/yESjAY2+A= Received: by mail-qt1-f175.google.com with SMTP id d16so2036201qtw.8 for ; Wed, 11 Jan 2023 13:59:10 -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=hLlRGFfxK+N0AdFFVO3VU9eoPoiCOoB3+UBhQVqyXOc=; b=CmstqYp912NmC9R4Xxm0EZWE1EhKvjcarg8Dw/Wvo1asypNqfDTwrkBigSXdwnWl8a 4ops4Q+AZ0AZAR9vQ87owdxKCGQyO1aJVUMY/IHzpPs8rGSv2PsogsQfOABGUB0wTC0+ pJ065B57G02ECCMJGrn6Oc6MOKi8zH2FecW9PW7SWyWva98kX9k0AhQDxpjfolODUYhR CkQnwaYhwRcFKnLZoTLY9RtUZpKEpdLKWbtYd23OPbAfYQc8/SGGSy4dhN3BhPhW+vgL GbtU0c09nPenwJQh3RYSCB+o2ZH/R0FgrMVTAi51zP7oJ5FAioNBfWy8OxS77pzIG2Gg htLg== 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=hLlRGFfxK+N0AdFFVO3VU9eoPoiCOoB3+UBhQVqyXOc=; b=bp24paVnlGKHoFWcScUrL1XFLk/7HQpyxXZ4UbRc9X9w48XpE7sRGKmy+hFp208v37 QDWmUSWqiWdMGazctAyLDF/JqdFBGY7wLj+jdlPX9hqIY96lWsJR0eSxNT62GtT1YP3N y0VoMAesdZBdb4SS0mO3WOkfdrwQ4pYFVEXaREMEtFwV0YTYu3I17iMu+hySdqzS6fHS bh6t4cEUZP9jUP7bOyaRHf4ZF8Beu1LeaTgjj7swYbi4/0E92r72rj7TsZbaXffNHu0r xsJsAfF7HYxYk1k2TL2hO0CAbxkHztCZrW2taf0YoJ4blEmfQxlB1KKmKZU1GcioGf5u 0Qqw== X-Gm-Message-State: AFqh2kofOEYvQYUOIDO6yjL3xcmL1D4uPlOA9y4/8ZATl0DusVwLtXY5 FPEpgqnoxTDjmcgzhDj+IH8gng== X-Google-Smtp-Source: AMrXdXsI2I0zIUl7fjZav5IrW4r6Gg92vBY0uLe3rvbW4hymgGfFuhQ2srGQZjabnFysCNG8OZZtNw== X-Received: by 2002:ac8:4509:0:b0:3a8:287c:8aa9 with SMTP id q9-20020ac84509000000b003a8287c8aa9mr104803620qtn.31.1673474349971; Wed, 11 Jan 2023 13:59:09 -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 l12-20020ac8078c000000b003996aa171b9sm8001201qth.97.2023.01.11.13.59.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jan 2023 13:59:09 -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] mm/page_ext: Do not allocate space for page_ext->flags if not needed Date: Wed, 11 Jan 2023 21:59:06 +0000 Message-Id: <20230111215906.2645056-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: DDF46100007 X-Stat-Signature: xhuqyaduz6btttw7h4agu4sy17axrr8b X-Rspam-User: X-HE-Tag: 1673474350-18138 X-HE-Meta: U2FsdGVkX1/c97AOWoaWOpW6RZZ30eXeR7mOcGjYIPBu/Ypqqq0SKiMBOMIhhvi775tDcsK5BZVY2B7Qnq6J6L4C62/p3kRqZ+dzSTmSHCU2hcRelakj4pcTPPCROb4NNcAOjtANIg0+4LlxNgpSXUt1mBib2DqQiIsVdLuiHlIZv8nFRqLSWUOTAXxm2lBcaCsehmYh1Huk0voet2CEOXWNVg3gsMGhh79a0cgcR/ph6qPSPis8WKDI397e14Bwn1wKjjecpu07ywekxt5JyuV1Bn0tGUUce7xmZAqcIRNmTEvXncbEVc55eyCvxjaUOMBH6Oy182KhtBKCEZK/p0ihASfwkuS4w8cNFAfU0IC9Fq00/YUv/+L/JiThCYC0+VmnzKS8e3QDG3C6EjJI+DlASTSllzq7YwEVkDi+nrMmiwmiYWFb65QT1eOKtUk9GMw9jDnI+aU0iS8L6w/lvp5NBJx1h75R/2AICn4K+SRFn2BbX3L2bdd5DXKS6Rx2SGnf4trBS4lIErp+NirdgScxWRrQaJ5rWHVarCyebqSnIJCpswMEQilUvSBFmYF4eaOW7eZQqKDemdLSltJCjmyAMaz+o6uF+NvUpP2jdC9NgTdTs7G8/wSZ7glTcnhHmbKBqrP4GEfsZ72oEMCJQoPHLIiVrXeY3QckZl5amnBKkdmnU5jZJPjOcMy0WbiRv4afQJAvW/GlgC2Yoq7rVuPHsd9PVUXv4NLZ9UNGaIt8O2/a30Je2aSrIaHskBfj/mZpcrTWbwSsIB+FUVCAfzGXT5alF1BSuq4x1IJD3S0OQMmM6eAKxK2xx+Y61PYTeGY8HMD8b4LZTC8EbtvlO98UbHoxMmnmo31ITVYj/yUhoFmteEv+5NGkvfS6s6RDIG4+fLQ6n7Z+ckH4aYdGZ0AJN84Ja7QKtuvvoivXw3xh/VxMr5XTfOMF0eSgLc9owzwdkgfvEo9TAv7II+j WtbZUoEB ZJ3AcYhq01eUhKoFM1hrbjDGQW1VnNAFJPPeWYZ/+ncxMFrbgWAWL+uoMCex5JtYgQeB8oWXmd2ys3uzyLcDpl+kN011EoeEq7mRWGN8JFxpj7EK4Bp+t2DAe81Q+ec8VuvuNr1vNl5BrtpnIuGM58yltsg== 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(-) 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..612a988373cc 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_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)