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: 44814 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2006363wrn; Tue, 17 Jan 2023 14:07:22 -0800 (PST) X-Google-Smtp-Source: AMrXdXuLHCeSoCZqlv9RZHjTfamjEYXCf4iWPZtyYt2hJFqgLRPbGegChudEHc837Zv5b79EHvLf X-Received: by 2002:a05:6402:380a:b0:494:cb3b:eb59 with SMTP id es10-20020a056402380a00b00494cb3beb59mr4823479edb.12.1673993242420; Tue, 17 Jan 2023 14:07:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673993242; cv=none; d=google.com; s=arc-20160816; b=Ea1hNzIGejDauNCW4qf6mrlJStKdUTxuGvkCF7e4gWy99QiAJuthCwSW2vTkMmHymA uQEvGvOfW4azOoSiQjcuR6M5rfWSgoPjFq6jyMSBrRwEOdccROolUwAJ9BW/HG6IZJI0 sghGsKEXlmqSLy+a6yb8Ri5FgMoIJdb/6T1EzY/eMmpedN9q2DdBHCce85VPHKE5KHmb PbbvfgGJHlYEia6bcXIJGIezYNgHgWyajjjJ1ljhqMd2/2bqoq932i/8sFE8qbdn84l/ M0niXaHjUaYzzCyq9yi4u95Zof830imFAQacBgmTPYT2Rpw3B0mxk+SnHpxgWEBKv7c4 p2Vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=1zg9S1unmML51wggskQ/tkuvQeGqpwGJV4esxPGJRUo=; b=o+SH4Vj2qX1pvs8Jk9QBrEtYdj0afa+xtbXFTEQ4joJq5PMflYu9VsCEaltSl9qz7B PNQkWKV2Hud83m8suKWb51O1iAaL8/+RL718EII3Mg8dM/lPwAbOGJx9JStO5X5CfDci 83ibL87bR07SsNM6TkSHZNqMCt1m5WnBmTBGStbDnJmqFuguOOlJZtduSg1YI7+/024O JjWdCig3d0T1Pe5gp4giDDFGhwJ4V5NC83+NKvmsq8gsdmynBVnxVv84g4VwmdOUN840 bAnJINyA1YtQsw0LLaiCMcY2+LGPY2vOzWDkevY7fiAbtU//WSBQ5HORZqPIdnmW8Jwk e4Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=JLJdOl00; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eb7-20020a0564020d0700b004859d0f61e0si42655804edb.380.2023.01.17.14.06.57; Tue, 17 Jan 2023 14:07:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=JLJdOl00; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229497AbjAQWGa (ORCPT + 99 others); Tue, 17 Jan 2023 17:06:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229910AbjAQWET (ORCPT ); Tue, 17 Jan 2023 17:04:19 -0500 Received: from mail-vs1-xe33.google.com (mail-vs1-xe33.google.com [IPv6:2607:f8b0:4864:20::e33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B97E16307 for ; Tue, 17 Jan 2023 12:21:07 -0800 (PST) Received: by mail-vs1-xe33.google.com with SMTP id k6so24590147vsk.1 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=GN2EpqxjP3Rxi6lbUMuXBUgmj8jSECIxpiGAppIgbUhwAgt5BNihbeFjFbKzsYqa1X asp5wbDA104bHRmAdXR6XyXxGnTnolA/3wvjKanJtSUJExxdM/oI3j8BIicEKUxqJMuc fhm4X2JZf9kYcbtYMVop7ga2zBI8SyjUs8ZvSfrxKSZ1pkpLpGuCHuk3+Oim5bJLxzGi X2nOYc/KpUWE5cdabETPekZXRjNw61JFlqYCFy4HdBQ5lSmtifaM3/5ID1ik/vtbV0fv DobC5uquti2YT+zhv0dvo2by7XAFcQX5Nr5Uia7GAQxSRz5vsBBQlyKucvsJp3Y2222F RAzA== X-Gm-Message-State: AFqh2kqm3W/gddXIARs93Ppcu9CJ11VGGQjCtOR5Jx3cDDNkdbllSAWc edAtmZNpAhgTIf1pst8DOWC4FQ== 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754832104694180697?= X-GMAIL-MSGID: =?utf-8?q?1755309137952876436?= 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)