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 X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 25D7DC433ED for ; Mon, 19 Apr 2021 09:36:42 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C79EB61027 for ; Mon, 19 Apr 2021 09:36:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C79EB61027 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id AA395100EBB98; Mon, 19 Apr 2021 02:36:40 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=198.145.29.99; helo=mail.kernel.org; envelope-from=rppt@kernel.org; receiver= Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4E7C0100EBB92 for ; Mon, 19 Apr 2021 02:36:38 -0700 (PDT) Received: by mail.kernel.org (Postfix) with ESMTPSA id CE5486101D; Mon, 19 Apr 2021 09:36:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618824997; bh=gKvvGKT7gwRRGsoZvfcNRGcz0Uq+afSf3EpowR/OLNc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=P3lkwvjW/R0feyjsaGtC46WUvSA5fINd83XuQt+ZESQgLmLjszsOUu+LDUHEcKzFK sigplCcojQ4mBEu6rER8dXQGEZqUGKDoigx7QfRx9QLVtR+aRgfcwkGniPnNZcwK1Y esYRQZkAPosCP1G+VuLB3y59ckxByt6ogqqNClQC0M2eiZ92c2ENWNcdwDNmkJaobH Q6eesP5D30kBeyc+SuhpDLAJuFI3pxzWfEnJtG1/zLkGk9o8TBN3uAS9cvmcCI24LT EfVn9mOhYvqkGR2hQgso12puyTHP9lzT9F9imFG/PQhcsS3AMAg4DeKSgo5cUC9n88 820gRflNkMWuw== Date: Mon, 19 Apr 2021 12:36:19 +0300 From: Mike Rapoport To: David Hildenbrand Subject: Re: [PATCH] secretmem: optimize page_is_secretmem() Message-ID: References: <20210419084218.7466-1-rppt@kernel.org> <3b30ac54-8a92-5f54-28f0-f110a40700c7@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <3b30ac54-8a92-5f54-28f0-f110a40700c7@redhat.com> Message-ID-Hash: ZHYIJWT7JIVFA4ADHGQ64THDVIS5NG4P X-Message-ID-Hash: ZHYIJWT7JIVFA4ADHGQ64THDVIS5NG4P X-MailFrom: rppt@kernel.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: Andrew Morton , Alexander Viro , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Catalin Marinas , Christopher Lameter , Dave Hansen , Elena Reshetova , "H. Peter Anvin" , Ingo Molnar , James Bottomley , "Kirill A. Shutemov" , Matthew Wilcox , Matthew Garrett , Mark Rutland , Michal Hocko , Mike Rapoport , Michael Kerrisk , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , "Rafael J. Wysocki" , Rick Edgecombe , Roman Gushchin , Shakeel Butt , S huah Khan , Thomas Gleixner , Tycho Andersen , Will Deacon , Yury Norov , linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-nvdimm@lists.01.org, linux-riscv@lists.infradead.org, x86@kernel.org, kernel test robot X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable On Mon, Apr 19, 2021 at 11:15:02AM +0200, David Hildenbrand wrote: > On 19.04.21 10:42, Mike Rapoport wrote: > > From: Mike Rapoport > >=20 > > Kernel test robot reported -4.2% regression of will-it-scale.per_thread= _ops > > due to commit "mm: introduce memfd_secret system call to create "secret" > > memory areas". > >=20 > > The perf profile of the test indicated that the regression is caused by > > page_is_secretmem() called from gup_pte_range() (inlined by gup_pgd_ran= ge): > >=20 > > 27.76 +2.5 30.23 perf-profile.children.cycles-pp.gup_pgd_range > > 0.00 +3.2 3.19 =B1 2% perf-profile.children.cycles-pp.page_mappi= ng > > 0.00 +3.7 3.66 =B1 2% perf-profile.children.cycles-pp.page_is_se= cretmem > >=20 > > Further analysis showed that the slow down happens because neither > > page_is_secretmem() nor page_mapping() are not inline and moreover, > > multiple page flags checks in page_mapping() involve calling > > compound_head() several times for the same page. > >=20 > > Make page_is_secretmem() inline and replace page_mapping() with page fl= ag > > checks that do not imply page-to-head conversion. > >=20 > > Reported-by: kernel test robot > > Signed-off-by: Mike Rapoport > > --- > >=20 > > @Andrew, > > The patch is vs v5.12-rc7-mmots-2021-04-15-16-28, I'd appreciate if it = would > > be added as a fixup to the memfd_secret series. > >=20 > > include/linux/secretmem.h | 26 +++++++++++++++++++++++++- > > mm/secretmem.c | 12 +----------- > > 2 files changed, 26 insertions(+), 12 deletions(-) > >=20 > > diff --git a/include/linux/secretmem.h b/include/linux/secretmem.h > > index 907a6734059c..b842b38cbeb1 100644 > > --- a/include/linux/secretmem.h > > +++ b/include/linux/secretmem.h > > @@ -4,8 +4,32 @@ > > #ifdef CONFIG_SECRETMEM > > +extern const struct address_space_operations secretmem_aops; > > + > > +static inline bool page_is_secretmem(struct page *page) > > +{ > > + struct address_space *mapping; > > + > > + /* > > + * Using page_mapping() is quite slow because of the actual call > > + * instruction and repeated compound_head(page) inside the > > + * page_mapping() function. > > + * We know that secretmem pages are not compound and LRU so we can > > + * save a couple of cycles here. > > + */ > > + if (PageCompound(page) || !PageLRU(page)) > > + return false; >=20 > I'd assume secretmem pages are rare in basically every setup out there. So > maybe throwing in a couple of likely()/unlikely() might make sense. I'd say we could do unlikely(page_is_secretmem()) at call sites. Here I can hardly estimate which pages are going to be checked. =20 > > + > > + mapping =3D (struct address_space *) > > + ((unsigned long)page->mapping & ~PAGE_MAPPING_FLAGS); > > + >=20 > Not sure if open-coding page_mapping is really a good idea here -- or even > necessary after the fast path above is in place. Anyhow, just my 2 cents. Well, most if the -4.2% of the performance regression kbuild reported were due to repeated compount_head(page) in page_mapping(). So the whole point of this patch is to avoid calling page_mapping(). > The idea of the patch makes sense to me. --=20 Sincerely yours, Mike. _______________________________________________ Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org To unsubscribe send an email to linux-nvdimm-leave@lists.01.org