From mboxrd@z Thu Jan 1 00:00:00 1970 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 97F96C54EBE for ; Mon, 16 Jan 2023 10:51:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 078D96B0071; Mon, 16 Jan 2023 05:51:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 026406B0072; Mon, 16 Jan 2023 05:51:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E08BB6B0073; Mon, 16 Jan 2023 05:51:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D125B6B0071 for ; Mon, 16 Jan 2023 05:51:37 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A328140666 for ; Mon, 16 Jan 2023 10:51:37 +0000 (UTC) X-FDA: 80360346234.08.007E816 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf27.hostedemail.com (Postfix) with ESMTP id D0BC940010 for ; Mon, 16 Jan 2023 10:51:35 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="IH/xncah"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=NxusArKl; dmarc=none; spf=pass (imf27.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673866296; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CjbT/LdORNHkPdYoXwdky8kda4m0F2JBqWj9+khVPtU=; b=Ekwae8tKqAWjWO3bZ2BoXxqeM1R46XUzrFtzeA3H1wNgr0n6KK/fvhaQb2EpzGO1sl2oGQ nXckNex/CzRcu4SCBCSnHwowJ9SLeprvy/Z+Gw1kD55yDjuyzM8Z7bbI2UUdapuR3IJTTi fF7ttvzEUtKCp+7QnyUnCNczeGdz2Rg= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="IH/xncah"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=NxusArKl; dmarc=none; spf=pass (imf27.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673866296; a=rsa-sha256; cv=none; b=OzHhVnvdJpwsqEtbt2lF6LJGawogJl/ilHQzY5k9xTpahntu63BRld68tFDbO3hjT0mLE1 yjJC8GAJm3nkF/IMD1S7fWLQU/dnradcVFDkeTP/2ZHjFgSkYWLxyq67UsCChRhw/imkzf CxIM9yQnKSNngTHaBv1YDf2ISsHFmDE= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4D81837209; Mon, 16 Jan 2023 10:51:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1673866294; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CjbT/LdORNHkPdYoXwdky8kda4m0F2JBqWj9+khVPtU=; b=IH/xncahraPYS1Ub618+/ZJQJyfD1Dg7q1jrKW6lJFe3YYbMgWbGtGkLcUFE9luCeFvIFm JHMrt+CivjD/LLE6F4Pq3rIseMTj7yJ1GmP4eF1OJK33kEdtuIh5VEFTDUQ94FfJjabg9j aIM7d+azI3UYFy7G5KAvYa9fggxYMKc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1673866294; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CjbT/LdORNHkPdYoXwdky8kda4m0F2JBqWj9+khVPtU=; b=NxusArKl+fiywqVDXDDBtXp5JpXNN2VVRKdvKSzr87v+R8DIdP4LcQATsPdgmysnd2IIOF 8SIZ5m3PXZjHlsCg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2DC5E138FA; Mon, 16 Jan 2023 10:51:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id BK6SCjYsxWO6XgAAMHmgww (envelope-from ); Mon, 16 Jan 2023 10:51:34 +0000 Message-ID: <0c706897-b2cc-714c-c72e-4154b1f3f52b@suse.cz> Date: Mon, 16 Jan 2023 11:51:33 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH v3] mm/page_ext: Do not allocate space for page_ext->flags if not needed To: Pasha Tatashin , akpm@linux-foundation.org, mhocko@suse.com, david@redhat.com, quic_charante@quicinc.com, lizhe.67@bytedance.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Mike Rapoport References: <20230113154253.92480-1-pasha.tatashin@soleen.com> Content-Language: en-US From: Vlastimil Babka In-Reply-To: <20230113154253.92480-1-pasha.tatashin@soleen.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: D0BC940010 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: qt3nj3zih9dzxpd8k9d8z9drhurtz9ww X-HE-Tag: 1673866295-319926 X-HE-Meta: U2FsdGVkX18UxZoBKS3GeQ9zHMJMrN5mURpfKjlYOus6zi9Vml4azcO+HV45m8t4q/bOTOANlOK+pnvF+Hjpp7ZtAy5j6ON93tEbRjMbH5n/Yjwips4rUQXA39ckq5zwY99MZ41CgGtYajvAaniMSsbBVAfRNupJSDV/atzcxJnJm8ZRWHsFJnVeiX+TzPyrSpL/V9jrIFRb1v8b9gWw6E4jVUZbTRjephQ0AVSw/IefrAXTCgn0MirKur6Rftunl6S6t02lTTzYCtYjabFIhJswpO7ID6zbFhVUJRgjIiB5fdyVACh8a2GOBjBDsdL21JXSrBSKSk1KCj4IkcfSHtctRkN6bKZ9XkgxNJoThcJ8+GOapZM3uqiqMqOkjnEEgtBhzJTTsUYINgAl7b4onMBdCqjCIuX3O1qGESKhvd15MPX12QyO1T2E5MTJgpVfq+g8hH28P4v23tBqClje1RF8IxJIhPQhrQFuaGTsQNx0m77Is6uluANIB6vl7XpTr3HBpjtQIncgIfvcZ2jmMdKW61/mTZnopVSoLdaCjRxDxb8Y6aVqJk0FZZWU3F4TTl4IZFDBZ1TcozqYu43Zh6DTfmuEhKfitIpovTOQX5PeQGTKBW/sacN7PQAU09Nsxx2OIIrGIN2ZOBg6VA4L878m0wQwGpKIlZXbNmUr6rl38DcC2RE3ALq3UqrVM7a18exTgCDQQF3ZHltnEc1NuimyS181ZAz+05n2lIAi+LdnK2Ohm9whDP+2KZ75D3f1rhAkxjcNpvCV1iRhtQn87ZbcDmkjsSFJEO8Ci+jHzSrYCvHqXXU0SKqjl+yKy/vmzTPQZJsZTYG6+/+KVptiGWRbUv4yivjColLqdQ36TfKAIWAnypGQwPBM3BcgfjnMwhcMHqQHprS7IZ/c1mVq3ecxIgpirg8JTRAjjI0aLrZZlQHaIGNK4BZNgsrWuTJt2+oIdXHuwpDjoeRyHo0 dkQ== 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: On 1/13/23 16:42, Pasha Tatashin wrote: > 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 Mike's comments look reasonable to me. > --- > 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)