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=1796324411; b=EMS1UZL2TUQhT9N+LS/fnS5cKQZh/g31RnizCjRMG5OewZMEnsoAdWrxP/EyPVl8QY6y sy40v66xWbHkS1CCiAmB9QlFN0w3bGZoy0MIVmGEjjle2hae9/+oJWF+MS2LePUk2s/+U k1RzP1hW/X/H2btPFvpTs0l7FaBrRAJ8EW2Liaph3Ug6zWlns8VPUX0eg47CL01K3MSj5 oJVMA1tqV25C1eirWqwe5bEFlNMBXyPoc3wy5D6B3t6APjZwWBkOI+LHc6eXsywgNqlyk hbobV8twuniEMnWF+K0pS4MkNCxaiZGsKbsF4ui968eLtQ2GatBhvJm2GSq8u/9DTqw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796324411; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=yBBcU8eKvWEMI1W6OocSROb+vDnULOnlJw9B5f0rtfg=; b=k4lQVFoG5H5hONJvAZUU/n8TuefxLuBYLmpV+gwQpyX8LN99X1nHnvh6BMuzRqo0yfqd Y20OrAn9WmFdGlkjBsddXwfYiHAoqWQUQ3zqyZSGd6djJsWt1TL7MfsUhMAlCBqw5OCZZ WbyelpLRbTJza5xV4hMikvbScPwiPpCBzVFa/1MH2PRQ1GuhMTKsO+h4nix3Gl2LrqiIe jJANkQXc/UStutQdzv8cyFwY4J1jQVHil4iDHXN/7/dxgfGfA2y8C3lwG2ZHALWK59eVs tTM5rAFQeR9uBUC9wfAgnsakBGEMvK9eyY3A5dRLaBVHBGW8cKmrPzjyMenfj1/CT8Q== 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=1MJGJSAf; 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 BEFFF606A32D for ; Thu, 3 Dec 2026 19:00:11 +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=1MJGJSAf Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8839E1F031EE; Thu, 3 Dec 2026 19:00:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796324411; bh=yBBcU8eKvWEMI1W6OocSROb+vDnULOnlJw9B5f0rtfg=; h=Date:To:From:In-Reply-To:References:Subject; b=1MJGJSAflEquTUW9Idp5uHouwgW4j0hbsGUF4szPHXn8Sf3mycfruuVj4TIzTJztl 5ISBLaiJia2dwhJysGqwUbK2PtujSv3zX/cjN3sZT81mJn8/dSFT5dQzXSTakM1wgH 0OKmKN+2r3MZq853dwq+bviq9jAjV45kLbCoZpiU= Date: Thu, 03 Dec 2026 11:00:11 -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: [to-be-updated] mm-hugetlb_cgroup-track-in-use-folios-per-cgroup.patch removed from -mm tree Message-Id: <20261203190011.8839E1F031EE@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 quilt patch titled Subject: mm/hugetlb_cgroup: track in-use folios per cgroup has been removed from the -mm tree. Its filename was mm-hugetlb_cgroup-track-in-use-folios-per-cgroup.patch This patch was dropped because an updated version will be issued ------------------------------------------------------ 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: 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: Jason Gunthorpe Cc: luojiajun Cc: Josef Bacik Cc: Daehyeon Ko <4ncienth@gmail.com> Cc: Ackerley Tng 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 kfence-use-a-nofault-store-to-zero-the-guard-page.patch mm-filemap-update-the-folio-order-range-atomically.patch mm-userfaultfd-account-memory-allocated-for-unmap-events.patch mm-userfaultfd-drop-fork-context-reference-outside-event_wqhlock.patch mm-madvise-dont-declare-oom-for-madv_willneed-swapin.patch mm-mprotect-fix-unpaired-notifier-start-at-address-0.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 hugetlbfs-seal-shm_hugetlb-files-against-growth.patch mm-hugetlb-resolve-protnone-faults-without-a-uffd-bit.patch a.patch