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=1796007153; b=zf3T9IJnqmvXBemKN4m9NYxg65w3WaNm8or8RqN0ro1JwVp/z0plZc2EtDDQIl5dx1R3 E6vit62X1upAWGJ0/wnV/rm1lGcznI9U4OP2HaQHihNPKcrH7bvgUBQ/4IvqsQA2wJLoK p0qfKIvFMxj2Y9v/iekUaWMam+YGF2+kZTMA0VkxhE0262/fEnhKRp5e7aw2cTNlt5K/U KEGukQFELX+lBctCxv0yS9qFlF6JULeEyElbALYwUcG1oqa2t9ECRPVc0smgTFa9rYWHL 9aXx9U3dr+H9xxR1pRFZC9VfLGEJA0ROmhYIQezamYKm8IzozWtRGHVzHAEDEaY/dXg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796007153; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=Yf/aPg4oUIW1fUUPR3gx5UglWGjjT9F1jfE9oAQK2QU=; b=ejmed8HERxbQc6ZUJDlWr1zNGJ7dFBenyugXFbfB+YTut8FhA6FE90/ZPg3TOFBJOToJ t9iNh085S9jgz4ceKtRd05PduLfApvoOUM3XbgnzdHXmqgcAWWnKa4bEfX+QkxogQILkN WqkS8SNYiKAQxXRPzyUFOoY2rlkNEI9+ze9c9PspSQUHMh14RVb31JpmMu2CNOsz9j0/W f1SKZGC3g4vMG+Bze8KEPWh5mOWCk4dVfXBoOwugTwNtKI4D8qCK+vTJ0BT34y+tJUPFj h6RbXna0bwCbmD05t25qJO2T4XwqAy4MiDkk8GR+wstRa5o6EqyYHmcCRR4gF4BCTdg== 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=sZrepKnR; 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 AF5FE606A31D for ; Mon, 30 Nov 2026 02:52:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=sZrepKnR Received: by smtp.kernel.org (Postfix) with ESMTPSA id E42F31F00896; Mon, 30 Nov 2026 02:52:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796007153; bh=Yf/aPg4oUIW1fUUPR3gx5UglWGjjT9F1jfE9oAQK2QU=; h=Date:To:From:In-Reply-To:References:Subject; b=sZrepKnREQ1jNDBiJjJc+iXwqls8c+2/oCSRx7qp2PW/x2Ahv5Vm64qUiQXlvIHsR BzWiwOES+jOoEdr5DoT0oJjvHLROzAKSvvM3Fnb505FB1YVXv+MiwfYXcRQv6jMhN0 8/wKCa48Zk0sWa+1nIGzXtJ1M1NHNsU0PHDS1MVE= Date: Sun, 29 Nov 2026 18:52:32 -0800 To: mm-commits@vger.kernel.org,mason@kernel.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261125-hugetlb_fixes_2-v1-16-db27fd2f71a8@kernel.org> References: <20261125-hugetlb_fixes_2-v1-16-db27fd2f71a8@kernel.org> Subject: + mm-hugetlb_cgroup-track-in-use-folios-per-cgroup.patch added to mm-new branch Message-Id: <20261130025232.E42F31F00896@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_cgroup: track in-use folios per cgroup has been added to the -mm mm-new branch. Its filename is mm-hugetlb_cgroup-track-in-use-folios-per-cgroup.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-hugetlb_cgroup-track-in-use-folios-per-cgroup.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next 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: Chris Mason Subject: mm/hugetlb_cgroup: track in-use folios per cgroup Date: Wed, 25 Nov 2026 23:33:14 +0100 When offlining a hugetlb cgroup, hugetlb_cgroup_css_offline() walks the list of all in-use hugetlb folios of each hstate with hugetlb_lock held and interrupts disabled, to reparent the folios charged to the dying cgroup. With many in-use hugetlb folios, that can keep interrupts disabled for a long time on every hugetlb cgroup removal, even for cgroups that never charged any hugetlb folios. Let's fix it by keeping in-use folios that are charged to a hugetlb cgroup on per-cgroup lists, so offlining only has to walk the folios of the dying cgroup. Process in batches to not keep interrupts disabled for too long when a single cgroup has many folios. Use batches of 32, like reclaim does with SWAP_CLUSTER_MAX. This has low urgency, as it only matters with a lot of hugetlb folios; let's not CC stable. [david@kernel.org: add lock checks, add HUGETLB_CGROUP_OFFLINE_BATCH, simplify comments and description] Link: https://patch.msgid.link/20261125-hugetlb_fixes_2-v1-16-db27fd2f71a8@kernel.org Fixes: da1def55919f ("hugetlb/cgroup: add support for cgroup removal") Signed-off-by: Chris Mason Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Andrew Morton Cc: Muchun Song Cc: Oscar Salvador Cc: Jinmeng Zhou Cc: Hongfu Li 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: Michal Hocko Cc: David Rientjes Cc: Joern Engel Cc: Jonathan Corbet Cc: Shuah Khan Cc: Randy Dunlap 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: "Oscar Salvador (SUSE)" Cc: Jiaqi Yan include/linux/hugetlb_cgroup.h | 20 ++++++++++++++++++ mm/hugetlb.c | 4 +-- mm/hugetlb_cgroup.c | 34 ++++++++++++++----------------- 3 files changed, 38 insertions(+), 20 deletions(-) --- a/include/linux/hugetlb_cgroup.h~mm-hugetlb_cgroup-track-in-use-folios-per-cgroup +++ a/include/linux/hugetlb_cgroup.h @@ -54,6 +54,9 @@ struct hugetlb_cgroup { /* Handle for "hugetlb.events.local" */ struct cgroup_file events_local_file[HUGE_MAX_HSTATE]; + /* In-use folios whose usage is charged here, under hugetlb_lock. */ + struct list_head activelist[HUGE_MAX_HSTATE]; + struct hugetlb_cgroup_per_node *nodeinfo[]; }; @@ -100,6 +103,17 @@ static inline void set_hugetlb_cgroup_rs __set_hugetlb_cgroup(folio, h_cg, true); } +static inline struct list_head *hugetlb_folio_activelist(struct folio *folio) +{ + struct hugetlb_cgroup *h_cg = hugetlb_cgroup_from_folio(folio); + struct hstate *h = folio_hstate(folio); + + lockdep_assert_held(&hugetlb_lock); + if (!h_cg) + return &h->hugepage_activelist; + return &h_cg->activelist[hstate_index(h)]; +} + static inline bool hugetlb_cgroup_disabled(void) { return !cgroup_subsys_enabled(hugetlb_cgrp_subsys); @@ -185,6 +199,12 @@ static inline void set_hugetlb_cgroup_rs { } +static inline struct list_head *hugetlb_folio_activelist(struct folio *folio) +{ + lockdep_assert_held(&hugetlb_lock); + return &folio_hstate(folio)->hugepage_activelist; +} + static inline bool hugetlb_cgroup_disabled(void) { return true; --- a/mm/hugetlb.c~mm-hugetlb_cgroup-track-in-use-folios-per-cgroup +++ a/mm/hugetlb.c @@ -7585,7 +7585,7 @@ void folio_putback_hugetlb(struct folio { spin_lock_irq(&hugetlb_lock); folio_set_hugetlb_migratable(folio); - list_move_tail(&folio->lru, &(folio_hstate(folio))->hugepage_activelist); + list_move_tail(&folio->lru, hugetlb_folio_activelist(folio)); spin_unlock_irq(&hugetlb_lock); folio_put(folio); } @@ -7661,7 +7661,7 @@ void move_hugetlb_state(struct folio *ol */ spin_lock_irq(&hugetlb_lock); folio_set_hugetlb_migratable(new_folio); - list_move_tail(&new_folio->lru, &(folio_hstate(new_folio))->hugepage_activelist); + list_move_tail(&new_folio->lru, hugetlb_folio_activelist(new_folio)); spin_unlock_irq(&hugetlb_lock); } --- a/mm/hugetlb_cgroup.c~mm-hugetlb_cgroup-track-in-use-folios-per-cgroup +++ a/mm/hugetlb_cgroup.c @@ -28,6 +28,8 @@ #define DFL_TMPL_SIZE ARRAY_SIZE(hugetlb_dfl_tmpl) #define LEGACY_TMPL_SIZE ARRAY_SIZE(hugetlb_legacy_tmpl) +#define HUGETLB_CGROUP_OFFLINE_BATCH 32 + static struct hugetlb_cgroup *root_h_cgroup __read_mostly; static struct cftype *dfl_files; static struct cftype *legacy_files; @@ -123,6 +125,8 @@ static void hugetlb_cgroup_init(struct h VM_WARN_ON_ONCE(ret); ret = page_counter_set_max(rsvd, limit); VM_WARN_ON_ONCE(ret); + + INIT_LIST_HEAD(&h_cgroup->activelist[idx]); } } @@ -219,18 +223,8 @@ static void hugetlb_cgroup_move_parent(i { unsigned int nr_pages; struct page_counter *counter; - struct hugetlb_cgroup *hcg; struct hugetlb_cgroup *parent = parent_hugetlb_cgroup(h_cg); - hcg = hugetlb_cgroup_from_folio(folio); - /* - * We can have pages in active list without any cgroup - * ie, hugepage with less than 3 pages. We can safely - * ignore those pages. - */ - if (!hcg || hcg != h_cg) - goto out; - nr_pages = folio_nr_pages(folio); if (!parent) { parent = root_h_cgroup; @@ -244,8 +238,7 @@ static void hugetlb_cgroup_move_parent(i hugetlb_cgroup_move_usage(h_cg, parent, folio, folio); set_hugetlb_cgroup(folio, parent); -out: - return; + list_move(&folio->lru, hugetlb_folio_activelist(folio)); } /* @@ -255,15 +248,20 @@ out: static void hugetlb_cgroup_css_offline(struct cgroup_subsys_state *css) { struct hugetlb_cgroup *h_cg = hugetlb_cgroup_from_css(css); + struct folio *folio, *next; struct hstate *h; - struct folio *folio; do { for_each_hstate(h) { - spin_lock_irq(&hugetlb_lock); - list_for_each_entry(folio, &h->hugepage_activelist, lru) - hugetlb_cgroup_move_parent(hstate_index(h), h_cg, folio); + int idx = hstate_index(h); + unsigned int nr = 0; + spin_lock_irq(&hugetlb_lock); + list_for_each_entry_safe(folio, next, &h_cg->activelist[idx], lru) { + hugetlb_cgroup_move_parent(idx, h_cg, folio); + if (++nr == HUGETLB_CGROUP_OFFLINE_BATCH) + break; + } spin_unlock_irq(&hugetlb_lock); } cond_resched(); @@ -367,6 +365,7 @@ static void __hugetlb_cgroup_commit_char */ WRITE_ONCE(h_cg->nodeinfo[folio_nid(folio)]->usage[idx], usage + nr_pages); + list_move(&folio->lru, hugetlb_folio_activelist(folio)); } out: if (!rsvd && charged_h_cg) @@ -940,7 +939,6 @@ void hugetlb_cgroup_migrate(struct folio { struct hugetlb_cgroup *h_cg; struct hugetlb_cgroup *h_cg_rsvd; - struct hstate *h = folio_hstate(old_folio); if (hugetlb_cgroup_disabled()) return; @@ -957,7 +955,7 @@ void hugetlb_cgroup_migrate(struct folio hugetlb_cgroup_move_usage(h_cg, h_cg, old_folio, new_folio); - list_move(&new_folio->lru, &h->hugepage_activelist); + list_move(&new_folio->lru, hugetlb_folio_activelist(new_folio)); spin_unlock_irq(&hugetlb_lock); } _ Patches currently in -mm which might be from mason@kernel.org are mm-swap-fix-large-swap-in-across-swap-file-extents.patch hugetlbfs-do-not-grow-a-sealed-file-in-mmap.patch mm-hugetlb-keep-surplus-folios-that-are-reserved.patch mm-hugetlb-fix-reservation-leak-on-min_size=-mounts.patch mm-cachestat-count-each-page-only-once.patch mm-cachestat-restart-the-walk-after-each-entry.patch percpu-queue-the-balance-work-on-an-unbound-workqueue.patch mm-vma-fix-uncharge-after-failed-stack-relocation.patch mm-mremap-apply-the-mmap-offset-limits-on-expansion.patch mm-mremap-respect-guard-gaps-on-in-place-expansion.patch mm-vma-make-brk-mappings-non-executable-under-mdwe.patch mm-hmm-refuse-secretmem-vmas-in-hmm_range_fault.patch mm-mglru-count-all-generations-as-evictable.patch mm-mglru-test-pg_lru-before-taking-a-folio-reference.patch mm-mglru-report-root-reclaim-to-memorypressure_level.patch kfence-use-a-nofault-store-to-zero-the-guard-page.patch mm-hugetlb-fix-truncated-copy-result-in-uffdio_copy.patch hugetlbfs-fix-deadlock-between-hole-punching-and-memory-failure.patch hugetlbfs-recheck-the-vma-range-after-the-lock-wait.patch mm-hugetlb-dont-zap-non-present-entries-when-unmapping-a-folio.patch mm-hugetlb-unshare-pmds-of-a-split-vma-if-allocating-its-lock-fails.patch mm-hugetlb_cgroup-track-in-use-folios-per-cgroup.patch hugetlbfs-seal-shm_hugetlb-files-against-growth.patch mm-hugetlb-resolve-protnone-faults-without-a-uffd-bit.patch