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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F944C433F5 for ; Tue, 16 Nov 2021 01:41:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BD1A861A7C for ; Tue, 16 Nov 2021 01:41:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BD1A861A7C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 0586D6B00B1; Mon, 15 Nov 2021 20:41:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 006686B00B2; Mon, 15 Nov 2021 20:41:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE88E6B00B3; Mon, 15 Nov 2021 20:41:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0164.hostedemail.com [216.40.44.164]) by kanga.kvack.org (Postfix) with ESMTP id CC2776B00B1 for ; Mon, 15 Nov 2021 20:41:52 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 829C51815CBF0 for ; Tue, 16 Nov 2021 01:41:52 +0000 (UTC) X-FDA: 78813092232.05.BD2F372 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf20.hostedemail.com (Postfix) with ESMTP id 23845D0000B3 for ; Tue, 16 Nov 2021 01:41:38 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id AE3A761A0D; Tue, 16 Nov 2021 01:41:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1637026911; bh=3hMkbBt+nftVPfBL7onIS7bfvCNYqfZ04xqsGgCSA8k=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=v4IL68xgFo8100jW63GQsuBXCL4HsHUP+ndfLODwZxDDwvtYNCMjIRBmdg5iokeN0 okgGhc9Zx6aAL0FqMX9o53P4DfQiw0oIeRS+Yji0LBMYrv+r9fHQIyE9e5MADqgZU1 lKk59cS2sginfvqjTYqwQzoNS/Nk1nNZNWdqsM+Q= Date: Mon, 15 Nov 2021 17:41:48 -0800 From: Andrew Morton To: Mina Almasry Cc: David Hildenbrand , Matthew Wilcox , "Paul E . McKenney" , Yu Zhao , Jonathan Corbet , Peter Xu , Ivan Teterevkov , Florian Schmidt , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v5] mm: Add PM_HUGE_THP_MAPPING to /proc/pid/pagemap Message-Id: <20211115174148.cdaeef3a026fe3143e6699cc@linux-foundation.org> In-Reply-To: <20211110221120.3833294-1-almasrymina@google.com> References: <20211110221120.3833294-1-almasrymina@google.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 23845D0000B3 X-Stat-Signature: mcjyiaqtc7gjyr4edrohocbwb3is7kf4 Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=v4IL68xg; spf=pass (imf20.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-HE-Tag: 1637026898-227303 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 Wed, 10 Nov 2021 14:11:20 -0800 Mina Almasry wrote: > Add PM_HUGE_THP MAPPING to allow userspace to detect whether a given virt > address is currently mapped by a transparent huge page or not. Example > use case is a process requesting THPs from the kernel (via a huge tmpfs > mount for example), for a performance critical region of memory. The > userspace may want to query whether the kernel is actually backing this > memory by hugepages or not. > > PM_HUGE_THP_MAPPING bit is set if the virt address is mapped at the PMD > level and the underlying page is a transparent huge page. > > A few options were considered: > 1. Add /proc/pid/pageflags that exports the same info as > /proc/kpageflags. This is not appropriate because many kpageflags are > inappropriate to expose to userspace processes. > 2. Simply get this info from the existing /proc/pid/smaps interface. > There are a couple of issues with that: > 1. /proc/pid/smaps output is human readable and unfriendly to > programatically parse. > 2. /proc/pid/smaps is slow. The cost of reading /proc/pid/smaps into > userspace buffers is about ~800us per call, and this doesn't > include parsing the output to get the information you need. The > cost of querying 1 virt address in /proc/pid/pagemaps however is > around 5-7us. > > Tested manually by adding logging into transhuge-stress, and by > allocating THP and querying the PM_HUGE_THP_MAPPING flag at those > virtual addresses. > > --- a/tools/testing/selftests/vm/transhuge-stress.c > +++ b/tools/testing/selftests/vm/transhuge-stress.c > @@ -16,6 +16,12 @@ > #include > #include > > +/* > + * We can use /proc/pid/pagemap to detect whether the kernel was able to find > + * hugepages or no. This can be very noisy, so is disabled by default. > + */ > +#define NO_DETECT_HUGEPAGES > + > > ... > > +#ifndef NO_DETECT_HUGEPAGES > + if (!PAGEMAP_THP(ent[0])) > + fprintf(stderr, "WARNING: detected non THP page\n"); > +#endif This looks like a developer thing. Is there any point in leaving it in the mainline code?