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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE311C54EAA for ; Fri, 27 Jan 2023 23:04:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231602AbjA0XET (ORCPT ); Fri, 27 Jan 2023 18:04:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232440AbjA0XES (ORCPT ); Fri, 27 Jan 2023 18:04:18 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B0AE8BB80; Fri, 27 Jan 2023 15:04:13 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 35CF861DC4; Fri, 27 Jan 2023 23:04:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36E7AC433D2; Fri, 27 Jan 2023 23:04:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1674860652; bh=vXb6OGR3jjuhguEAysSQHpLS55ZCH4lzC8q7qrmExC4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=GeXLPEFPnmXnybEa25WwdFpTpr2nhYU8dLL7E2sH4CFNOzfVOkdnfEsFzv+w1P77i ZFHD1cIyfbt01v+7INXSaQrNBZu9xQCzZVaHHdD09PqZPS918tHEKQ7Y1NXN0O362B SeJxlYCZqBX14TKSM/4XPHIjm5y0xIrxE6v2kSgs= Date: Fri, 27 Jan 2023 15:04:11 -0800 From: Andrew Morton To: David Hildenbrand Cc: Mike Kravetz , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Naoya Horiguchi , James Houghton , Peter Xu , Michal Hocko , Yang Shi , Vishal Moola , Matthew Wilcox , Muchun Song , stable@vger.kernel.org Subject: Re: [PATCH 1/2] mm: hugetlb: proc: check for hugetlb shared PMD in /proc/PID/smaps Message-Id: <20230127150411.7c3b7b99fa4884a6af0b9351@linux-foundation.org> In-Reply-To: <4ad5163f-5368-0bd8-de9b-1400a7a653ed@redhat.com> References: <20230126222721.222195-1-mike.kravetz@oracle.com> <20230126222721.222195-2-mike.kravetz@oracle.com> <4ad5163f-5368-0bd8-de9b-1400a7a653ed@redhat.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org On Fri, 27 Jan 2023 17:23:39 +0100 David Hildenbrand wrote: > On 26.01.23 23:27, Mike Kravetz wrote: > > A hugetlb page will have a mapcount of 1 if mapped by multiple processes > > via a shared PMD. This is because only the first process increases the > > map count, and subsequent processes just add the shared PMD page to > > their page table. > > > > page_mapcount is being used to decide if a hugetlb page is shared or > > private in /proc/PID/smaps. Pages referenced via a shared PMD were > > incorrectly being counted as private. > > > > To fix, check for a shared PMD if mapcount is 1. If a shared PMD is > > found count the hugetlb page as shared. A new helper to check for a > > shared PMD is added. > > > ... > > > --- a/fs/proc/task_mmu.c > > +++ b/fs/proc/task_mmu.c > > @@ -749,8 +749,14 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned long hmask, > > > > if (mapcount >= 2) > > mss->shared_hugetlb += huge_page_size(hstate_vma(vma)); > > - else > > - mss->private_hugetlb += huge_page_size(hstate_vma(vma)); > > + else { > > Better: > > if (mapcount >= 2 || hugetlb_pmd_shared(pte)) > mss->shared_hugetlb += huge_page_size(hstate_vma(vma)); > else > mss->private_hugetlb += huge_page_size(hstate_vma(vma)); Yup. And that local doesn't add any value? --- a/fs/proc/task_mmu.c~mm-hugetlb-proc-check-for-hugetlb-shared-pmd-in-proc-pid-smaps-fix +++ a/fs/proc/task_mmu.c @@ -745,18 +745,10 @@ static int smaps_hugetlb_range(pte_t *pt page = pfn_swap_entry_to_page(swpent); } if (page) { - int mapcount = page_mapcount(page); - - if (mapcount >= 2) + if (page_mapcount(page) >= 2 || hugetlb_pmd_shared(pte)) mss->shared_hugetlb += huge_page_size(hstate_vma(vma)); - else { - if (hugetlb_pmd_shared(pte)) - mss->shared_hugetlb += - huge_page_size(hstate_vma(vma)); - else - mss->private_hugetlb += - huge_page_size(hstate_vma(vma)); - } + else + mss->private_hugetlb += huge_page_size(hstate_vma(vma)); } return 0; } _