From patchwork Tue Jan 17 20:21:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13105029 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 0D654C3DA78 for ; Tue, 17 Jan 2023 20:21:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7AF0E6B0072; Tue, 17 Jan 2023 15:21:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 75F6F6B0080; Tue, 17 Jan 2023 15:21:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64E086B0082; Tue, 17 Jan 2023 15:21:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 567CC6B0072 for ; Tue, 17 Jan 2023 15:21:09 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0B16F1203C0 for ; Tue, 17 Jan 2023 20:21:09 +0000 (UTC) X-FDA: 80365410258.24.4C002A8 Received: from mail-vs1-f51.google.com (mail-vs1-f51.google.com [209.85.217.51]) by imf23.hostedemail.com (Postfix) with ESMTP id 6A099140008 for ; Tue, 17 Jan 2023 20:21:07 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=JLJdOl00; dmarc=none; spf=pass (imf23.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.217.51 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673986867; 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=1zg9S1unmML51wggskQ/tkuvQeGqpwGJV4esxPGJRUo=; b=Y35FCi1jMKYmEeierqwjP1POyzEViGowOA9InMfxRvYIimP4YBANbFH2XHfu5Ftz1SBmvg CTVJsMD0wv+DEo7XKWBez3jvfhaiQqJRM+aE8VhGlyJBClrK/xgCjjm+0Y7E0lbSScnTD7 kYXMegZZ8iEWdUCDvJhCh2sYEnn6ZDo= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=JLJdOl00; dmarc=none; spf=pass (imf23.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.217.51 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673986867; a=rsa-sha256; cv=none; b=ko2/FQoHXSk1W6TbsITU4rmp9VUqN4IxQARsn1oVCTL9fjLmrr9qbmsc6r6tR4ew+dB8gg bYC+r5qq4Jwun2MktNK40WNqcYV8GWDZdLbj21zqcXe+r4yTIm7Y8kgjO1f9mnXWKu1akI QL5C7NWG+xIIk4KwK+ZZPrrCerMHE+8= Received: by mail-vs1-f51.google.com with SMTP id n190so29622955vsc.11 for ; Tue, 17 Jan 2023 12:21:07 -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=1zg9S1unmML51wggskQ/tkuvQeGqpwGJV4esxPGJRUo=; b=JLJdOl009aot+nrMeCM5C1JKpOsuZ+h6D/BvkaK2hT/o43mwon77NvHBk8/izyWUU/ i4GDL4FiTOUIKYQ4bY45laKBk9oKN7aZpQIRNjxGZ9HWQBNJmj1ofpDh6TszP7ypZnl1 5agrjCZEJqDVIH2sSO9SvqiiCoxwoTmtlW2u5LR3aFl48S3ayOug2Z/AOa44qng1KUXZ mbw7zcRzH78ACfXIbaHsVHG4bpojz6Ij2lq+oWV1KXyw7iLFr1kGonrvPuJSSaAnBXNJ hr8OpSHmTW49bkLzLu8cjybfTO2H0269g4qYuuteaekUdDRV6GT0COSq81Wodp7bbWhQ NFMA== 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=1zg9S1unmML51wggskQ/tkuvQeGqpwGJV4esxPGJRUo=; b=PqULbxt93vIr9DW093P1wtZxg0ZZh3gPYnFUKZRolPMlXvvXDyeM5dEvzBKMNeRvSp LHbnOn1B7Y5Gc3f/Lk9P6dU6IR3jFEHU+5NTh0JiLqKtQkMKoM8vI081Vr6eV2B+ufXK MfNFKzMSi/DGkRVxEDtEdJG5SDWKC/mef08+IkjerlFnEZ7kF1xXh1xaTLLIN3h9wi+l uOysUHiA2UXutIb4YhI4IopiZqRRuh4+yJaWV9Tl0LR4prNgkqnpyNV6ky0TQdt1w97H G9ukKG8aCOo1NuR954g8ail9Ddfr2JayKBjbggwbPYZEYIcOnxHt4XveT2OO/T95J6+H rYKw== X-Gm-Message-State: AFqh2kqLRbeYU84kGzhL0qK+faG/h+jgYim9mj3cchYnf3dD9EZZOICR GRdyuNOPO0WUAZhkxG2CBlf4sg== X-Google-Smtp-Source: AMrXdXs6SG+Ub80KW1QWuDv3yN7xOZkTR5LMb4bbNvgE4IDL8MMconCg45Kq7GyVqxf+E5jUhPr8jw== X-Received: by 2002:a67:ffd3:0:b0:3d0:a5f0:bee5 with SMTP id w19-20020a67ffd3000000b003d0a5f0bee5mr2177202vsq.18.1673986866455; Tue, 17 Jan 2023 12:21:06 -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 195-20020a370ccc000000b007023fc46b64sm20688193qkm.113.2023.01.17.12.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 12:21:06 -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 v4] mm/page_ext: Do not allocate space for page_ext->flags if not needed Date: Tue, 17 Jan 2023 20:21:03 +0000 Message-Id: <20230117202103.1412449-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: rspam02 X-Rspamd-Queue-Id: 6A099140008 X-Stat-Signature: jho1x4nfryyqh7phfsssacm5s3o73iwn X-HE-Tag: 1673986867-784049 X-HE-Meta: U2FsdGVkX18GVqIvrNJy5bVKWAY4NIvUn/p48ipszjUudYRRf8lizDl6OisiFKdAT9QSAoEihOEPVpYuPxQkQGgHXny47p19OPwD0LzF4eHM1O4lKEVuGNv2RRMIUlWKvZFS79vr+L96OcOhC98z/VJRugbu3/Bp4+gU5uLrIqPmd7YnqxqQmpUnv4Nt5EGulAfHdOLd+Vo8txZYFTWvFmELTgnk74qmCKfxdNdx0vgq2WFXZz9q6Z2L4QOhSD2xGdHjwlhr2/zJqckJm+xytvoH2GewiKZYGqnVWC5ZnRSQjG7Eq+80y+5vSdeEvwa7g3zFQUqpsm5lfXGj6EoJZlFc8VusxL24eQa+9nkOzLuNVW6PgaUV7F/zfrW1huvJNXCsLDfmgdgGFakSCRXeXbi01d1RGNKk71YTw1Oxygf6nagzHC1KTdts/SdOYHOYuDsK30jnUjArizFDk7YBFNTloYKSyyFR79O5NOZVuVLIxVzOnAf7w7J0f2SX00CL7ECQrDMAZiK4/4XDwwnIX/qHqAJGm/cFI2v/v1u1ijfTIGnLX7zc6PkX5RFkJr0WtGkY39SDihS6Vmopy53JLoKZZ443qRjUKQ0Gmv1d7h5PxtxyCjUQbnmUnZoFSAjTOw6XvjHjzjnMdKjApWNDyUgV20rzqaOu4eFhFVhOzt45w7E1iCDokNFYNDjBdJm6o3Wcb7zWQ3LDnwBkzl6V6xkxCjBzdj49+ZEVzjRCcSZxAwb8MU33p36qV4pJ9pVmcQMsMj4lctgb0N6XukD3nkmWpLJr3TJauR+usMaHt+kqUXYxah++yR+qxypPwh/1uWWeKevW1Al2IdKbVZLx3Cqcd/2mxHar/gV4Zb5fSjXUuOojZKn+INd/6ZdiTznYe9cqui0XUCjRJog5KmICFSLPY9uWXUX0u/j9HHyYxCVOxJovukxRoBUyW9c9N1Nq4X4i0TopSg0fCy4qcLg 32lxSoO2 uujqV2yUJiqO6QKPtBF01gAID2iZYGeud1MwISFz8MBPzZP/eQducVHlUa0v3ZyfLtjbKNCu7OED4erpm2phvKo+GiREP/mGChaxR3EPUOqaINWQnf2VjN/+ZWQzDyPMovFZbC7eOQCNOZ524olY6TbfwCwLWQyMrResq 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 kernel-doc comment before page_ext_operations that describes the fields, 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 Reviewed-by: Mike Rapoport (IBM) Acked-by: David Rientjes --- include/linux/page_ext.h | 18 ++++++++++++++++++ mm/page_ext.c | 14 ++++++++++++-- mm/page_owner.c | 1 + mm/page_table_check.c | 1 + 4 files changed, 32 insertions(+), 2 deletions(-) Changelog: v4: Addressed comments from Mike Rapoport, added Acked-by's. v3: Added comment before page_ext_operations, removed check if need is null. 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..67314f648aeb 100644 --- a/include/linux/page_ext.h +++ b/include/linux/page_ext.h @@ -7,15 +7,33 @@ #include struct pglist_data; + +/** + * struct page_ext_operations - per page_ext client operations + * @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. + * @need_shared_flags: True when client is using shared page_ext->flags + * field. + * + * Each Page Extension client must define page_ext_operations in + * page_ext_ops array. + */ struct page_ext_operations { size_t offset; size_t size; bool (*need)(void); void (*init)(void); + bool need_shared_flags; }; #ifdef CONFIG_PAGE_EXTENSION +/* + * The page_ext_flags users must set need_shared_flags to true. + */ enum page_ext_flags { PAGE_EXT_OWNER, PAGE_EXT_OWNER_ALLOCATED, diff --git a/mm/page_ext.c b/mm/page_ext.c index 4ee522fd381c..e2c22ffdbb81 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, + .need_shared_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]->need_shared_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..f0553bedb39d 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, + .need_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..25d8610c0042 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, + .need_shared_flags = false, }; static struct page_table_check *get_page_table_check(struct page_ext *page_ext)