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 D8078C433F5 for ; Tue, 23 Nov 2021 12:05:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 46E6A6B0071; Tue, 23 Nov 2021 07:05:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 41E816B0072; Tue, 23 Nov 2021 07:05:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E6C26B0073; Tue, 23 Nov 2021 07:05:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0213.hostedemail.com [216.40.44.213]) by kanga.kvack.org (Postfix) with ESMTP id 2061C6B0071 for ; Tue, 23 Nov 2021 07:05:17 -0500 (EST) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id D60BC1828C60D for ; Tue, 23 Nov 2021 12:05:06 +0000 (UTC) X-FDA: 78840064212.31.7FCA7EB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 9209D508BD47 for ; Tue, 23 Nov 2021 12:05:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637669105; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=10C2btypfwcrFtuMmhHmEu5fFbIpPIsZeEBRh/iSG+U=; b=csA8xBpolb+OXjWSjjTdT9+sApuTUSyliTLs1eFGlg4BcHYX2t9jPKAGV00nO7qA+KFBkl PV+OhdOk2moESX0OUFYPYjUY3wz92y6u0us3NVnl/NSk7AE5Ql8Qs+RVeqWbcpBOodmow4 A8IhRouikT3rWq0LKRevqXCAUEITb08= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-331-N83xG9eGMgazvlm7quvn8w-1; Tue, 23 Nov 2021 07:05:04 -0500 X-MC-Unique: N83xG9eGMgazvlm7quvn8w-1 Received: by mail-wr1-f70.google.com with SMTP id x17-20020a5d6511000000b0019838caab88so328614wru.6 for ; Tue, 23 Nov 2021 04:05:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=10C2btypfwcrFtuMmhHmEu5fFbIpPIsZeEBRh/iSG+U=; b=GS79huO20bzoqQL8r4Ov+Unuu11iEp5I5WHxUwo5aDcFc7L4BMdd27HS54D+wLhyqZ +QTUYuxjuGQ8xLxVAnE5n1/OYfLleZCCED1IjKkiY6U9eKp7CpriN+C1S5tnEpPgGz0e YcOGsfuMEH0RZWvGwBG24dFZscIdcvAn34CO9mpe0vpchzGO3d24/LsqO8bu/HkqzV7X Jsx+NDxYQwdMhvYUDzMupngRxdQN+2f5jj+wS5r+7Y2gZ+oqUWjb2uEu5yd8kA8VBZAD T5yNrG3nAxeFrww2owHAxLhyKfUte34qPXKIuZSxKo1pVCb5xPbh4UKs3JcJoLGSY5go 9KWQ== X-Gm-Message-State: AOAM532K7tta5rIdqgTvjEb5mLGNw0C0zO2KATYWQ77AB5Y5MFSe0YIm eHkX+I6JN7g1cWvSC70X1QrvthRZij9X9jjlwJ6LGGKAEzjdbChZ18/ADegPL8vHKcE8R1iA6P7 mamVttDnYdXk= X-Received: by 2002:a1c:1c8:: with SMTP id 191mr2389664wmb.90.1637669103364; Tue, 23 Nov 2021 04:05:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJyLoxWe0qE+FnDLpNv40B8GIz11hsE9XFI/Y9fkJD69fhqkCoyVX155VmOBmNmz+cOprFl9Vg== X-Received: by 2002:a1c:1c8:: with SMTP id 191mr2389644wmb.90.1637669103184; Tue, 23 Nov 2021 04:05:03 -0800 (PST) Received: from [192.168.3.132] (p5b0c6765.dip0.t-ipconnect.de. [91.12.103.101]) by smtp.gmail.com with ESMTPSA id o12sm16660715wrc.85.2021.11.23.04.05.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Nov 2021 04:05:02 -0800 (PST) Message-ID: <476868f6-8d32-b8d2-855e-4b19e8a54cc2@redhat.com> Date: Tue, 23 Nov 2021 13:05:01 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [PATCH v7] mm: Add PM_THP_MAPPED to /proc/pid/pagemap To: Mina Almasry , Jonathan Corbet Cc: Matthew Wilcox , "Paul E . McKenney" , Yu Zhao , Andrew Morton , Peter Xu , Ivan Teterevkov , Florian Schmidt , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org References: <20211123000102.4052105-1-almasrymina@google.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20211123000102.4052105-1-almasrymina@google.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9209D508BD47 X-Stat-Signature: sorkzeffttiwbdr3r6izaoqiccf9h4f3 Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=csA8xBpo; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf01.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com X-HE-Tag: 1637669102-466305 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 23.11.21 01:01, Mina Almasry wrote: > Add PM_THP_MAPPED 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_THP_MAPPED 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 because it must read the whole memory range > rather than a small range we care about. 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_THP_MAPPED flag at those > virtual addresses. > > Signed-off-by: Mina Almasry > > Cc: David Hildenbrand > Cc: Matthew Wilcox > Cc: David Rientjes rientjes@google.com > Cc: Paul E. McKenney > Cc: Yu Zhao > Cc: Jonathan Corbet > Cc: Andrew Morton > Cc: Peter Xu > Cc: Ivan Teterevkov > Cc: Florian Schmidt > Cc: linux-kernel@vger.kernel.org > Cc: linux-fsdevel@vger.kernel.org > Cc: linux-mm@kvack.org > > > --- > > Changes in v7: > - Added clarification that smaps is only slow because it looks at the > whole address space. > > Changes in v6: > - Renamed to PM_THP_MAPPED > - Removed changes to transhuge-stress > > Changes in v5: > - Added justification for this interface in the commit message! > > Changes in v4: > - Removed unnecessary moving of flags variable declaration > > Changes in v3: > - Renamed PM_THP to PM_HUGE_THP_MAPPING > - Fixed checks to set PM_HUGE_THP_MAPPING > - Added PM_HUGE_THP_MAPPING docs > --- > Documentation/admin-guide/mm/pagemap.rst | 3 ++- > fs/proc/task_mmu.c | 3 +++ > 2 files changed, 5 insertions(+), 1 deletion(-) > > diff --git a/Documentation/admin-guide/mm/pagemap.rst b/Documentation/admin-guide/mm/pagemap.rst > index fdc19fbc10839..8a0f0064ff336 100644 > --- a/Documentation/admin-guide/mm/pagemap.rst > +++ b/Documentation/admin-guide/mm/pagemap.rst > @@ -23,7 +23,8 @@ There are four components to pagemap: > * Bit 56 page exclusively mapped (since 4.2) > * Bit 57 pte is uffd-wp write-protected (since 5.13) (see > :ref:`Documentation/admin-guide/mm/userfaultfd.rst `) > - * Bits 57-60 zero > + * Bit 58 page is a huge (PMD size) THP mapping > + * Bits 59-60 zero > * Bit 61 page is file-page or shared-anon (since 3.5) > * Bit 62 page swapped > * Bit 63 page present > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c > index ad667dbc96f5c..d784a97aa209a 100644 > --- a/fs/proc/task_mmu.c > +++ b/fs/proc/task_mmu.c > @@ -1302,6 +1302,7 @@ struct pagemapread { > #define PM_SOFT_DIRTY BIT_ULL(55) > #define PM_MMAP_EXCLUSIVE BIT_ULL(56) > #define PM_UFFD_WP BIT_ULL(57) > +#define PM_THP_MAPPED BIT_ULL(58) > #define PM_FILE BIT_ULL(61) > #define PM_SWAP BIT_ULL(62) > #define PM_PRESENT BIT_ULL(63) > @@ -1456,6 +1457,8 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, > > if (page && page_mapcount(page) == 1) > flags |= PM_MMAP_EXCLUSIVE; > + if (page && is_transparent_hugepage(page)) > + flags |= PM_THP_MAPPED; > > for (; addr != end; addr += PAGE_SIZE) { > pagemap_entry_t pme = make_pme(frame, flags); > Thanks! Reviewed-by: David Hildenbrand -- Thanks, David / dhildenb