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=1796006456; b=P3GyAZ2fnxIJR5SbOED7uAoudZMWIaZg/jCtYZXy1Ancowlz3P0kBbDgFvFF4ipmOt+Z Jsl5ZuLhqBRC0eAjmc3rTNGQ1pCli8hVrjMsVxWOXWG2ZDPjvL1MyKuj+JLpF0RgkY5y5 //4gZiWHBZ27Jtxclns19Jyjc3oLlQcXjkVQPaf3BaMlq8lvX8jmB00t8qbqcfUTX8BFV F3bd+Rug+K3KYiIQZxXVIla8m/9rMjI+KoyC+XhKj8xZxOUT293bMRCkSxLvHiPjl01Td O37zN05gok2tzZjklzSEJrL/tjn8iVhZKRHEsScHhZU69FvCSBJYyax9GZbsUFuU+gg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796006456; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=q5Q8tHa/AZQuF9DIDg1mrhqKuVst/Ou4wimBUo6Oftc=; b=amya8ANd+heHOkD32gYhVuaUDd9d3ITFU5V4S5bfDAQGVeKoube5Gw9g2b7LC7obmbOJ 0pZyoxVTPRkhgwe5HvQ6k61kxN+dxbFFgW16PRkQIpTba/ldvgYUGafPcn74pUIDEih0Y RYwyA4TprVFE5PKCH3AxJkdoKZpnilRzmNpgxITyBHcq2Nb/+7IHJX2jcqLnHiDj80e1s 4FrHwCZbmheewQPgVjhfQWFrdhSu+YXC/7NqnYbop3z4eBu3yJvCbagjcjJN7iNvJDS/X NHwH9GhMlr/CkScjKknFWmcW1a1/A8dYQKl8hqaBIKAfMTXyE8Tq4d5279QByHU4riQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=s2s2t+Ts; 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 AFA6B606A31C for ; Mon, 30 Nov 2026 02:40:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=s2s2t+Ts Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEB0A1F00897; Mon, 30 Nov 2026 02:40:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796006456; bh=q5Q8tHa/AZQuF9DIDg1mrhqKuVst/Ou4wimBUo6Oftc=; h=Date:To:From:In-Reply-To:References:Subject; b=s2s2t+TsLesNkKp/6fB0uOOPoOR2vPD693clEXSAv/dm3FukHBttiXLUN93Ttb2sA Ua1D3uRBOFpaAiK3vVQVzNUbanfCG0txASRZ+O0e9LxHorVrqgiVFw0q/D0jLeEIGc ObRmXdPyxVgh3/gNXOf1Ui41SgsTbbj7m3yrdMNY= Date: Sun, 29 Nov 2026 18:40:55 -0800 To: mm-commits@vger.kernel.org,ziy@nvidia.com,ying.huang@linux.alibaba.com, vivek.kasireddy@intel.com,vbabka@kernel.org,surenb@google.com, skhan@linuxfoundation.org,shy828301@gmail.com,shakeel.butt@linux.dev, sasha.levin@oracle.com,rppt@kernel.org,rientjes@google.com,riel@surriel.com, rdunlap@infradead.org,rakie.kim@sk.com,pfalcato@suse.de,osalvador@suse.de, osalvador@kernel.org,nao.horiguchi@gmail.com,muchun.song@linux.dev, mike.kravetz@oracle.com,mhocko@suse.cz,mhocko@suse.com,mel@csn.ul.ie, matthew.brost@intel.com,mason@kernel.org,luojiajun3@huawei.com, ljs@kernel.org,liwp.linux@gmail.com,liwanp@linux.vnet.ibm.com, lihongfu@kylinos.cn,liam@infradead.org,lance.yang@linux.dev, kraxel@redhat.com,kenneth.w.chen@intel.com,kas@kernel.org, kamezawa.hiroyu@jp.fujitsu.com,jthoughton@google.com,joshua.hahnjy@gmail.com, josef@toxicpanda.com,joern@logfs.org,jinmengzhou22@gmail.com, jiaqiyan@google.com,jgg@ziepe.ca,jannh@google.com,hughd@google.com, harry@kernel.org,guillaume@morinfr.org,gourry@gourry.net, dave.mccracken@oracle.com,corbet@lwn.net,byungchul@sk.com, baolin.wang@linux.alibaba.com,apw@shadowen.org,apopple@nvidia.com, aneesh.kumar@linux.vnet.ibm.com,ak@linux.intel.com,airlied@redhat.com, agl@us.ibm.com,ackerleytng@google.com,aarcange@redhat.com,4ncienth@gmail.com, david@kernel.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261125-hugetlb_fixes_2-v1-1-db27fd2f71a8@kernel.org> References: <20261125-hugetlb_fixes_2-v1-1-db27fd2f71a8@kernel.org> Subject: + mm-hugetlb-charge-the-copy-made-at-fork-to-the-parent.patch added to mm-hotfixes-unstable branch Message-Id: <20261130024055.EEB0A1F00897@smtp.kernel.org> X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: mm/hugetlb: charge the copy made at fork to the parent has been added to the -mm mm-hotfixes-unstable branch. Its filename is mm-hugetlb-charge-the-copy-made-at-fork-to-the-parent.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-hugetlb-charge-the-copy-made-at-fork-to-the-parent.patch This patch will later appear in the mm-hotfixes-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: "David Hildenbrand (Arm)" Subject: mm/hugetlb: charge the copy made at fork to the parent Date: Wed, 25 Nov 2026 23:32:59 +0100 When copying page tables during fork(), the child is not yet assigned to the right memcg. When copying possibly pinned anon hugetlb folios, we must charge them to the parent's memcg, otherwise we can end up allocating more hugetlb folios than allowed. Let's fix it by charging the copy to the parent's mm, like we do when copying small folios in copy_present_page(), introducing a new helper function alloc_hugetlb_folio_for_fork(). Link: https://lore.kernel.org/20261125-hugetlb_fixes_2-v1-0-db27fd2f71a8@kernel.org Link: https://patch.msgid.link/20261125-hugetlb_fixes_2-v1-1-db27fd2f71a8@kernel.org Fixes: c2deb1356d82 ("mm/hugetlb: charge folios to the target mm's memcg") Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Andrew Morton Reported-by: Chris Mason Acked-by: Michal Hocko Tested-by: Hongfu Li Link: https://lore.kernel.org/5dc5ea66-ba09-48d3-8c72-bcc5c141b6d9@kylinos.cn Reviewed-by: Hongfu Li Reviewed-by: Muchun Song (ByteDance) Acked-by: Oscar Salvador (SUSE) Cc: Oscar Salvador Cc: Jinmeng Zhou Cc: Andrea Arcangeli Cc: Mike Kravetz Cc: Naoya Horiguchi Cc: Hugh Dickins Cc: Baolin Wang Cc: Dave Airlie Cc: Vivek Kasireddy Cc: Gerd Hoffmann Cc: Mike Rapoport Cc: Mel Gorman Cc: Dave McCracken Cc: Andy Whitcroft Cc: Adam Litke Cc: Lorenzo Stoakes Cc: Rik van Riel Cc: Liam R. Howlett Cc: Vlastimil Babka Cc: Harry Yoo Cc: Jann Horn Cc: Lance Yang Cc: James Houghton Cc: Yang Shi Cc: Suren Baghdasaryan Cc: Shakeel Butt Cc: Pedro Falcato Cc: Gregory Price Cc: Zi Yan Cc: Joshua Hahn Cc: Rakie Kim Cc: Ying Huang Cc: Matthew Brost Cc: Byungchul Park Cc: Alistair Popple Cc: Wanpeng Li Cc: Andi Kleen Cc: Kenneth W Chen Cc: David Rientjes Cc: Joern Engel Cc: Jonathan Corbet Cc: Shuah Khan Cc: Randy Dunlap Cc: Michal Hocko Cc: Aneesh Kumar K.V Cc: KAMEZAWA Hiroyuki Cc: Kiryl Shutsemau Cc: Sasha Levin Cc: Guillaume Morin Cc: Wanpeng Li Cc: Jason Gunthorpe Cc: luojiajun Cc: Josef Bacik Cc: Daehyeon Ko <4ncienth@gmail.com> Cc: Ackerley Tng Cc: Jiaqi Yan mm/hugetlb.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) --- a/mm/hugetlb.c~mm-hugetlb-charge-the-copy-made-at-fork-to-the-parent +++ a/mm/hugetlb.c @@ -3005,8 +3005,9 @@ typedef enum { * allocation). New call sites should (probably) never set it to true!! * When it's set, the allocation will bypass all vma level reservations. */ -struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, - unsigned long addr, bool cow_from_owner) +static struct folio *__alloc_hugetlb_folio(struct vm_area_struct *vma, + unsigned long addr, bool cow_from_owner, + struct mm_struct *memcg_mm) { struct hugepage_subpool *spool = subpool_vma(vma); struct hstate *h = hstate_vma(vma); @@ -3089,7 +3090,7 @@ struct folio *alloc_hugetlb_folio(struct .nodemask = nodemask, }; - folio = hugetlb_alloc_folio(h, &mpoli, vma->vm_mm, alloc_flags); + folio = hugetlb_alloc_folio(h, &mpoli, memcg_mm, alloc_flags); mpol_cond_put(mpol); @@ -3143,6 +3144,23 @@ out_end_reservation: return ERR_PTR(ret); } +struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, + unsigned long addr, bool cow_from_owner) +{ + return __alloc_hugetlb_folio(vma, addr, cow_from_owner, vma->vm_mm); +} + +/* + * Allocate a folio for a copy in the child VMA during fork(), charged to the + * parent's mm: the child is not in its memory cgroup yet. + */ +static struct folio *alloc_hugetlb_folio_for_fork(struct vm_area_struct *dst_vma, + unsigned long addr, struct mm_struct *src_mm) +{ + return __alloc_hugetlb_folio(dst_vma, addr, /* cow_from_owner = */ false, + src_mm); +} + static __init void *alloc_bootmem(struct hstate *h, int nid, bool node_exact) { if (hugetlb_early_cma(h)) @@ -5081,7 +5099,7 @@ again: spin_unlock(src_ptl); spin_unlock(dst_ptl); /* Do not use reserve as it's private owned */ - new_folio = alloc_hugetlb_folio(dst_vma, addr, false); + new_folio = alloc_hugetlb_folio_for_fork(dst_vma, addr, src); if (IS_ERR(new_folio)) { folio_put(pte_folio); ret = PTR_ERR(new_folio); _ Patches currently in -mm which might be from david@kernel.org are mm-hugetlb-charge-the-copy-made-at-fork-to-the-parent.patch mm-mprotect-dont-skip-uffd-marker-install-when-racing-with-pte-table-reclaim.patch mm-userfaultfd-prevent-poison-marker-loss.patch mm-hugetlb-compare-against-persistent-count-when-freeing-lowmem-folios.patch mm-hugetlb-preserve-reservations-when-shrinking-on-highmem.patch mm-hugetlb-account-temporary-folios-separately.patch mm-hugetlb-account-temporary-folios-separately-fix.patch mm-hugetlb-serialize-page-cache-allocations-with-truncation.patch mm-hugetlb-serialize-page-cache-allocations-with-truncation-fix.patch mm-memfd-recheck-the-page-cache-before-allocating-a-hugetlb-folio.patch mm-hugetlb-count-again-if-the-reserve-map-shrank.patch mm-hugetlb-account-restored-reservations-before-freeing-folios.patch mm-hugetlb-delay-anon-folio-rmap-removal-until-after-the-tlb-flush.patch mm-userfaultfd-reject-dax-mappings.patch uprobes-skip-mappings-not-managed-by-core-mm.patch mm-memory-store-the-pfn-of-cow-pfnmap-mappings-in-the-anon-page-offset.patch mm-hugetlb-always-mark-new-page-cache-folios-migratable.patch mm-memfd-mark-new-hugetlb-folios-migratable.patch mm-hugetlb-free-surplus-folios-of-other-nodes-on-free.patch hugetlbfs-dont-zero-poisoned-pages-in-a-hole-punch.patch mm-hugetlb-only-check-pmd-table-sharing-for-pmd-sized-folios.patch mm-migrate-check-hugetlb-pmd-sharing-in-move_pages.patch mm-hugetlb-dont-share-page-tables-of-a-vma-during-mprotect.patch mm-hugetlb-count-migration-entries-at-fork-and-unmap.patch mm-hugetlb-stop-accounting-hugetlbpages-once-pmd-tables-were-shared.patch fs-proc-task_mmu-dont-clear-vm_softdirty-on-hugetlb-vmas.patch mm-hugetlb-use-the-vma-lock-to-stabilize-flags-for-pmd-sharing.patch rfc-mm-hugetlb_cgroup-charge-faults-to-mm-owner.patch