Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9BD3C388F9 for ; Mon, 26 Oct 2020 17:34:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5DA292225C for ; Mon, 26 Oct 2020 17:34:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5DA292225C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 617E86B0068; Mon, 26 Oct 2020 13:34:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 54B946B0062; Mon, 26 Oct 2020 13:34:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3EAEB6B006E; Mon, 26 Oct 2020 13:34:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0117.hostedemail.com [216.40.44.117]) by kanga.kvack.org (Postfix) with ESMTP id 0DD186B005C for ; Mon, 26 Oct 2020 13:34:09 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id A90231EE6 for ; Mon, 26 Oct 2020 17:34:08 +0000 (UTC) X-FDA: 77414774976.21.beds25_420241027275 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 842C5180442C2 for ; Mon, 26 Oct 2020 17:34:08 +0000 (UTC) X-HE-Tag: beds25_420241027275 X-Filterd-Recvd-Size: 3593 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Mon, 26 Oct 2020 17:34:08 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id BE5E7AEFE; Mon, 26 Oct 2020 17:34:06 +0000 (UTC) From: Vlastimil Babka To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Alexander Potapenko , Kees Cook , Michal Hocko , David Hildenbrand , Mateusz Nosek , Vlastimil Babka Subject: [PATCH 3/3] mm, page_alloc: reduce static keys in prep_new_page() Date: Mon, 26 Oct 2020 18:33:58 +0100 Message-Id: <20201026173358.14704-4-vbabka@suse.cz> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20201026173358.14704-1-vbabka@suse.cz> References: <20201026173358.14704-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: prep_new_page() will always zero a new page (regardless of __GFP_ZERO) wh= en init_on_alloc is enabled, but will also always skip zeroing if the page w= as already zeroed on free by init_on_free or page poisoning. The latter check implemented by free_pages_prezeroed() can involve two different static keys. As prep_new_page() is really a hot path, let's int= roduce a single static key free_pages_not_prezeroed for this purpose and initial= ize it in init_mem_debugging(). Signed-off-by: Vlastimil Babka --- mm/page_alloc.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 2a1be197649d..980780f5f242 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -171,6 +171,8 @@ EXPORT_SYMBOL(init_on_alloc); DEFINE_STATIC_KEY_FALSE_RO(init_on_free); EXPORT_SYMBOL(init_on_free); =20 +static DEFINE_STATIC_KEY_TRUE_RO(free_pages_not_prezeroed); + static bool _init_on_alloc_enabled_early __read_mostly =3D IS_ENABLED(CONFIG_INIT_ON_ALLOC_DEFAULT_ON); static int __init early_init_on_alloc(char *buf) @@ -777,6 +779,16 @@ void init_mem_debugging() } } =20 + /* + * We have a special static key that controls whether prep_new_page wil= l + * never need to zero the page. This mode is enabled when page is + * already zeroed by init_on_free or page_poisoning zero mode. + */ + if (_init_on_free_enabled_early || + (IS_ENABLED(CONFIG_PAGE_POISONING_ZERO) + && page_poisoning_enabled())) + static_branch_disable(&free_pages_not_prezeroed); + #ifdef CONFIG_PAGE_POISONING /* * Page poisoning is debug page alloc for some arches. If @@ -2216,12 +2228,6 @@ static inline int check_new_page(struct page *page= ) return 1; } =20 -static inline bool free_pages_prezeroed(void) -{ - return (IS_ENABLED(CONFIG_PAGE_POISONING_ZERO) && - page_poisoning_enabled_static()) || want_init_on_free(); -} - #ifdef CONFIG_DEBUG_VM /* * With DEBUG_VM enabled, order-0 pages are checked for expected state w= hen @@ -2291,7 +2297,8 @@ static void prep_new_page(struct page *page, unsign= ed int order, gfp_t gfp_flags { post_alloc_hook(page, order, gfp_flags); =20 - if (!free_pages_prezeroed() && want_init_on_alloc(gfp_flags)) + if (static_branch_likely(&free_pages_not_prezeroed) + && want_init_on_alloc(gfp_flags)) kernel_init_free_pages(page, 1 << order); =20 if (order && (gfp_flags & __GFP_COMP)) --=20 2.29.0