From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796298346; b=hGzACOz1zAqXJ7w5VW3kdELOXTlu599iYrdtQK3m2+CQ9mX05Y31eCagws4syDm06h8b acaJJbJ15lR9i94qmxUAlhgVYvrfPhJUnWjPai8EyPG9qhwPUXbcc9oUQe1rJcr4VILv8 45UcRwIU8lg6hMbUq30aPSxpgDAQ7fyHuQVloVgeN3t87P39gC8n4STRa19ZDqgOtaYye ZzFUAgpELQK/GYqoiDoAqvWIeTJR9tFCyy9StYUPM0eT/lPJRMYYS/yk6pZtIVtZy5X18 jNIFDXjhx/tiulTZqeBfPOMMGVoOTzm1MqqDyzIUI3pouUcBW4sEXXNzPTH9pqZCFSw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796298346; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=Fygo2h7HJv37hWPiHGUuyC56JqEK24QH8WGbsW+hnc0=; b=jUAbEPoRLxhbAWRgLGBrlcAiRSfmeOFXp95WFP9e/gETFYqoXUBEq3QcZgDeDNIQzSqR 2TTi+onjksfnoFNS39L0YPIriDfY8ra2lHSd+rc/dMAzx/wXjV5pWWQqAW7GYFVdLo7LN g3jxBiVhpJ5EvuWGJQeHDCqDXZsIVnEXCYSafJI09VSqPn50DpVwPCJtHKRVyyEf1Mc3v aNzUP8LPhWwL9BRhdT8Dhw6UvomHdxIs/rN5P19UzsjBL2b4HpxSzkaisQOPlhu97rsm/ X0AQ7c1krHX3EaPcgcvAWj+RRdTCj4SoPVWarkNJI0jhWd7FzkX13Jk4kwZzwFhpJ1Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Q841Uatk; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ABA17606A32C; Thu, 3 Dec 2026 11:45:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Q841Uatk Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0899A1F00896; Thu, 3 Dec 2026 11:45:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796298346; bh=Fygo2h7HJv37hWPiHGUuyC56JqEK24QH8WGbsW+hnc0=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Q841UatkaQeXOTn/mFuvjFkskbN9m6DpyNIbu8v0Aq9hudLb3cTl3DH2gOy845MBq 9uaAcE4eOGT+LOhofmiPaSBccMLQh3ij40NZoiIMCAuzzKvAY8K5nVZsc5GgohYhYk kwBnwZwS6C7tPvMEY+Y2ri9r/fkqQ5969BJF1ksAJdlgyIEiRavoO0Ve4toziHzWd1 UvMy12PDYc0LFvEdJyGGzrDWpLPx4tKOof2krYXN3pDtvImwZ6HT6+UCmgmkb2GUdT 7GaUhArA+1mLwSJJ1v5S1RxKZR8TRoLCtAlLeJqq6pLdWF0BiUMJ29PRyNoClKkXGn /LjmPwGOGY0cQ== From: "David Hildenbrand (Arm)" Date: Thu, 03 Dec 2026 12:37:55 +0100 Subject: [PATCH v2 32/35] mm/hugetlb: stop accounting HugetlbPages once PMD tables were shared X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261203-hugetlb_fixes_2-v2-32-9bbeabb555d2@kernel.org> References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> In-Reply-To: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> To: Muchun Song , Oscar Salvador , Andrew Morton , Hongfu Li , Jinmeng Zhou , Mina Almasry , Davidlohr Bueso , Naoya Horiguchi , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Michal Hocko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Vivek Kasireddy , Mel Gorman , Hugh Dickins , Baolin Wang , Dave Airlie , Jason Gunthorpe , Andy Whitcroft , Roman Gushchin , Barry Song , Andrea Arcangeli , Lorenzo Stoakes , Suren Baghdasaryan , Shakeel Butt , Pedro Falcato , Jann Horn , Guillaume Morin , Yang Shi , James Houghton , Rik van Riel , Harry Yoo , Lance Yang , Axel Rasmussen , Peter Xu , Sasha Levin , Kiryl Shutsemau , Christian Brauner , "Steven Rostedt (Google)" , Hongbo Li , Gregory Price , Zi Yan , Joshua Hahn , Rakie Kim , Ying Huang , Matthew Brost , Byungchul Park , Alistair Popple , Andi Kleen , David Rientjes , Joern Engel , "Aneesh Kumar K.V" Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, Gerd Hoffmann , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Johannes Weiner , Chris Mason , Jiaqi Yan , "David Hildenbrand (Arm)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3111; i=david@kernel.org; h=from:subject:message-id; bh=dcMA7czxK0m22sytgjUJ2MeENM/Zng7Wat864XqhBj4=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIFQ2o/CBUoqPetYT04q7z3zzet6RrOi06sUHc/t7Ut2 oT54yXujhIWBjEOBlkxRZag4PsGL1+uq61242OGmcPKBDKEgYtTACbC3sLI8HEy3+UtjLfPpMp5 13qpNz1qCLq43PDL67wvsUqdS9drnGD48aTsUCB/3ySxpatnNiocivjNpL5zxppfEzdPrp07oeI gDwA= X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A Sharing hugetlb PMD tables can leave HugetlbPages in /proc//status too low or too high, or make it underflow: when (un)mapping a folio in a shared PMD table, we only adjust mm->hugetlb_usage of the MM we process, not of the other sharers. Accounting this precisely is not worth it for a statistic, so let's just give up: once an MM shares a PMD table, set mm->hugetlb_usage of both MMs to LONG_MIN / 2, and report negative values as 0. Later updates cannot realistically make it positive again, as PMD table sharing is 64-bit only. Document that HugetlbPages is 0 once a process shared hugetlb PMD page tables. This has low urgency, as it only affects a statistic. Let's not CC stable. Fixes: 5d317b2b6536 ("mm: hugetlb: proc: add HugetlbPages field to /proc/PID/status") Reported-by: Chris Mason Signed-off-by: David Hildenbrand (Arm) --- Documentation/filesystems/proc.rst | 3 ++- mm/hugetlb.c | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst index bcbcb41814d96..8696359b06498 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -268,7 +268,8 @@ It's slow but very precise. VmPTE size of page table entries VmSwap amount of swap used by anonymous private data (shmem swap usage is not included) - HugetlbPages size of hugetlb memory portions + HugetlbPages size of hugetlb memory portions (0 once the + process shared hugetlb PMD page tables) CoreDumping process's memory is currently being dumped (killing the process may lead to a corrupted core) THP_enabled process is allowed to use THP (returns 0 when diff --git a/mm/hugetlb.c b/mm/hugetlb.c index c1fbe66d30332..9c85fc5790f3a 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4766,8 +4766,9 @@ void hugetlb_show_meminfo_node(int nid) void hugetlb_report_usage(struct seq_file *m, struct mm_struct *mm) { + /* Negative once the MM shared PMD tables, see huge_pmd_share(). */ seq_printf(m, "HugetlbPages:\t%8lu kB\n", - K(atomic_long_read(&mm->hugetlb_usage))); + K(max(atomic_long_read(&mm->hugetlb_usage), 0L))); } /* Return the number pages of memory we physically have, in PAGE_SIZE units. */ @@ -7349,6 +7350,12 @@ pte_t *huge_pmd_share(struct mm_struct *mm, struct vm_area_struct *vma, (pmd_t *)((unsigned long)spte & PAGE_MASK)); hugetlbfs_pmd_sharing_inc(file_inode(vma->vm_file)); mm_inc_nr_pmds(mm); + /* + * (Un)mapping folios with shared PMD tables would require + * updating statistics of all MMs. Instead, give up accounting. + */ + atomic_long_set(&mm->hugetlb_usage, LONG_MIN / 2); + atomic_long_set(&svma->vm_mm->hugetlb_usage, LONG_MIN / 2); } else { ptdesc_pmd_pts_dec(virt_to_ptdesc(spte)); } -- 2.56.1