mm/hugetlb_cgroup: move per-node usage on cgroup reparenting

hugetlb_cgroup_css_offline() hands the folios of a dying cgroup over to
its parent with hugetlb_cgroup_move_parent(), which moves the page_counter
charges and the hugetlb_cgroup pointer of the folio but not its per-node
usage.  The parent's hugetlb.<size>.numa_stat is short by that usage while
they are charged, and underflows once they are freed, exposing incorrect
per-node usage values to userspace.

Move the per-node usage to the parent as well.  The folios keep their node
here, so only the cgroup which holds the usage changes.

Link: https://lore.kernel.org/[email protected]
Fixes: f477619990 ("hugetlb: add hugetlb.*.numa_stat file")
Signed-off-by: Hongfu Li <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Acked-by: Muchun Song <[email protected]>
Cc: Colin Ian King <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: Mina Almasry <[email protected]>
Cc: Oscar Salvador <[email protected]>
Cc: Shakeel Butt <[email protected]>
Cc: <[email protected]>
This commit is contained in:
Hongfu Li
2026-10-12 21:26:27 -07:00
committed by Andrew Morton
parent fe0ba1909c
commit 23fac055c2
+2
View File
@@ -241,6 +241,8 @@ static void hugetlb_cgroup_move_parent(int idx, struct hugetlb_cgroup *h_cg,
/* Take the pages off the local counter */
page_counter_cancel(counter, nr_pages);
hugetlb_cgroup_move_usage(h_cg, parent, folio, folio);
set_hugetlb_cgroup(folio, parent);
out:
return;