From patchwork Fri Jan 13 15:42:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13100988 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 5798AC54EBE for ; Fri, 13 Jan 2023 15:43:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BF2278E0003; Fri, 13 Jan 2023 10:42:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BA2658E0001; Fri, 13 Jan 2023 10:42:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A69DC8E0003; Fri, 13 Jan 2023 10:42:59 -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 965428E0001 for ; Fri, 13 Jan 2023 10:42:59 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 630ADC0D53 for ; Fri, 13 Jan 2023 15:42:59 +0000 (UTC) X-FDA: 80350194078.02.5AD1771 Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) by imf07.hostedemail.com (Postfix) with ESMTP id DA05040019 for ; Fri, 13 Jan 2023 15:42:57 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=NrIMn+EG; spf=pass (imf07.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.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=1673624578; 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=fcODqOMs4kmXyIK9NRLS6X4ag83qwdUq4JEzAmDRzvU=; b=p6eJDhgDnU4Dz+yEBM1APorqpRHdAHsga3pJv1MptbtTp3NzSLoEVV9DOToNcfHwrUmXzV YMOHqRxQZvH+OV0GoUBZaEuj/kgu5wAeM4vea1l6VlTNiomvAsX5tzcy0RAl08kRs7hTu1 hUa2fGXRBkkZkYu0HaYEeDxWQYqF+eQ= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=NrIMn+EG; spf=pass (imf07.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.175 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673624578; a=rsa-sha256; cv=none; b=T/WEVdoZtSO2tOwn40kSZlVX5gOOF353ZgtTMgHLDxprRBif5npGa6wrW68mHQjHYKAVeR 3ZOhbOPIPHTneT1XAznwNYV8ubFs9bbx0WEFPLOEDRRis7bJS5W6Oe0qet55+rrFv5Iu82 D814B2QO8XdcrayfU75IcgKeBAH5scs= Received: by mail-yb1-f175.google.com with SMTP id 9so5354267ybn.6 for ; Fri, 13 Jan 2023 07:42:57 -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=fcODqOMs4kmXyIK9NRLS6X4ag83qwdUq4JEzAmDRzvU=; b=NrIMn+EGvvyFQLNvTF2p3fDVX6y06gxhZmoOs3RcOqCBpp61cU+ch788tI/meEMgl8 C+AcjQmTPQOCmC7Akkcr2HjewRJN/S5lJsVBTrv/nQNOqkON6peWr8HUTje/8oF5GOPc byHK2EJ5c38X/nvZ01I65IBPVaw6AVLgZEkfz9VKPVqN49gsWxJl3CiDAjvuNbdVeLPT TShjDscb+9g6Mlx6aH7r82rWW13GnL17zKAReE3vUtBJmFNbg9vMMm69kUXQIaXUrNta 56JCZKjhZ3BNvAS2pmQRDv9kWcZIlX5xwXzDb+skwsgahphNCwZDmU4h19eq0maf1BKl Bw2w== 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=fcODqOMs4kmXyIK9NRLS6X4ag83qwdUq4JEzAmDRzvU=; b=d5WrY/oL0m+HKadqwqmjms8JY9lBbEOEO8XkggY/igOHaxf2LLUBLXDZueYK5+DMKc 0b30NCAHsVPp4ZoKhvoBx6sLGyJQ5H6EOmlOir278iiCBbBcfqkmCldUOzHFDPI2J2yh DYsjUHlJwD+csl68GRAK2wXLrQCSEfkDbPqIEayHeoQShQqQmB9cX/xUjc37lhfeUaE2 dq+cxKfgakHXYxiv25kKHGOuETViJbo6LpHhfDGREI7PYiWON1UF5UrYnS5HXzmqVR9a 071PwyYzgM0DnZC1S52L7/3YV6ikAfP4qDb91H0g/HsATS/FJTqOmVekW78btWOvcsUS /OLg== X-Gm-Message-State: AFqh2kpNXxpJmV0s9BmwdQDAtVOjBtpd57EEoNrllgou0MAxlDIv5Xdp p8fBZyMluxhRmxrNP89n/gljlNaSyodL74qy X-Google-Smtp-Source: AMrXdXsE8lqjUzTinL01kK0qcQ1nLyyGH4tcf9i7DwikeQBusCPoLcGcKu9VPICbR9Fal1Vu24+JOQ== X-Received: by 2002:a25:d20b:0:b0:703:1e28:5734 with SMTP id j11-20020a25d20b000000b007031e285734mr8221723ybg.42.1673624576931; Fri, 13 Jan 2023 07:42:56 -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 c15-20020ae9ed0f000000b006fafc111b12sm12716266qkg.83.2023.01.13.07.42.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 07:42:56 -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 v3] mm/page_ext: Do not allocate space for page_ext->flags if not needed Date: Fri, 13 Jan 2023 15:42:53 +0000 Message-Id: <20230113154253.92480-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: DA05040019 X-Stat-Signature: ab33z6k85bgc4c71nyunzr8wyraa9k44 X-HE-Tag: 1673624577-357200 X-HE-Meta: U2FsdGVkX1/RbSstJuYFNZbp/3ebzOqicDzOJlhqUYOstnYQWej0vUdMHKrsju+0BjmVsefvRqvtcpdxo97hlMFSEEJcTM3OgXVboS72YNkjJ+y8f9WDyrc5HILmJl/84aVsE3BRsSZoehj7momWfHcRzEK6esO3fnxXtpkR1bEddUHynlHMcfjH0ny5ZqV5Jq5linhijHm6HMiIQmjYy/ZXXzifDoxJ5M5w5PJdTq09XdQqDCTahS+BR2K0Ko8xqRlD1Po1C/1urs8B3IZPXAZUHADncXBUuKwSgL05s4VlpbMMG2QBgJckORfGYk63ETeN85yKrD6700GzJQmKjxWX41tJWLW/cJjxgUnUO3mOeotqvCUVmW35+KFesvaPbC64UXZaS8NICwFi8RqGTivfJD93SKcd/pOU9OitSL02FNGoadHYDs1b8v3rz2c6W7WPn8FtYGj2CQhg3uvhbQWgU3B347HkIAsYcTdSAXNEw+j5nYOWyHs7yJnLO6P7fZ5whlFwGWL9Gf1F5+WQWyKH4+B4J/dBeYxB1hx77diWIGYmkbzZ1GtHd6qWaw8C+ETAp9Q39aK8RS8uAJxKgCDU39ydgFJU5Y1l6VnbQXxkUpU1uV1am8iYF8GqfZ/+NilXqgaTzB1BK7RK08ivoMPSVSOl7EmRthMfIJdoHw4zEbDH1FtxxhXbHN2KHQ81TpbMuCVGU1vzZRioGk067Xxo49cJmi+yZNvb3YnQdh3dX4yByxnQfhiX3FSp0JcgdjgFqG+95MXlTjByj45nDEwhHxDdwQDFHmb7KE4sh5OUqRewN9busWTcrqfSK/TvjkHA6y71SiLo0CF6nYWU8UjTPFBn1oST6V/LPKAJboLsHNvtsR+bEmAw1+7OPKAyyCDZhxWk1RBcy+LNKIbtOM/NUiwT87X+nqXS3Nh8vK1rMbr2x0Z0hbZVI0OhjUYmqstl3cERBpvr/8F609p qBEgZ7CM 8Zc/8nfLIDcRQFBcWP9dtkdRPsD6b9gbTnK438Y6rylbkffxxZUPiLWGGqIAzX2yyDpGIAjDtcNBNW8E3oBgKuLhA0EMldchkDpSf+9SkQzgdj4xGLRyQBNRosx1NUVb5Eg9G1a7AhfJFmOzvbDmcSnie2FdwdqksiHGW 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 Also, add a comment before page_ext_operations that describes the field, and remove check if need() is set, as that is now a required field. Signed-off-by: Pasha Tatashin Acked-by: Vlastimil Babka Acked-by: David Hildenbrand --- include/linux/page_ext.h | 19 +++++++++++++++++++ mm/page_ext.c | 14 ++++++++++++-- mm/page_owner.c | 1 + mm/page_table_check.c | 1 + 4 files changed, 33 insertions(+), 2 deletions(-) Changelog: v2: Fixed field name in page_owner.c that caused build error. v3: Added comment before page_ext_operations, removed check if need is null. diff --git a/include/linux/page_ext.h b/include/linux/page_ext.h index 22be4582faae..be0b465c7d78 100644 --- a/include/linux/page_ext.h +++ b/include/linux/page_ext.h @@ -7,15 +7,31 @@ #include struct pglist_data; + +/* + * Each Page Extension client must define page_ext_operations in + * page_ext_ops array. + * offset offset to the client's data within page_ext. Offset is returned to + * the client by page_ext_init. + * size the size of the client data within page_ext. + * need() function that returns true if client requires page_ext + * init() (optional) called to initialize client once page_exts are allocated. + * using_shared_ext_flags true when client is using shared page_ext->flags + * field. + */ struct page_ext_operations { size_t offset; 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 +47,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..d14dbd44fa49 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); @@ -106,7 +107,16 @@ static bool __init invoke_need_callbacks(void) 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]->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]->offset = page_ext_size; page_ext_size += page_ext_ops[i]->size; need = true; 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)