mm: hugetlb: switch to css_tryget() in hugetlb_cgroup_charge_cgroup()

This change “mm: hugetlb: switch to css_tryget() in hugetlb_cgroup_charge_cgroup()” in Linux kernel is authored by Roman Gushchin <guro [at]> on Fri Nov 15 17:34:46 2019 -0800.

mm: hugetlb: switch to css_tryget() in hugetlb_cgroup_charge_cgroup()

An exiting task might belong to an offline cgroup.  In this case an
attempt to grab a cgroup reference from the task can end up with an
infinite loop in hugetlb_cgroup_charge_cgroup(), because neither the
cgroup will become online, neither the task will be migrated to a live

Fix this by switching over to css_tryget().  As css_tryget_online()
can't guarantee that the cgroup won't go offline, in most cases the
check doesn't make sense.  In this particular case users of
hugetlb_cgroup_charge_cgroup() are not affected by this change.

A similar problem is described by commit 18fa84a2db0e ("cgroup: Use
css_tryget() instead of css_tryget_online() in task_get_css()").

Signed-off-by: Roman Gushchin <>
Acked-by: Johannes Weiner <>
Acked-by: Tejun Heo <>
Reviewed-by: Shakeel Butt <>
Cc: Michal Hocko <>
Cc: <>
Signed-off-by: Andrew Morton <>
Signed-off-by: Linus Torvalds <>

This Linux change may have been applied to various maintained Linux releases and you can find Linux releases including commit 0362f32.

There are 2 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 mm/hugetlb_cgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c
index f1930fa..2ac38bd 100644
--- a/mm/hugetlb_cgroup.c
+++ b/mm/hugetlb_cgroup.c
@@ -196,7 +196,7 @@ int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
 	h_cg = hugetlb_cgroup_from_task(current);
-	if (!css_tryget_online(&h_cg->css)) {
+	if (!css_tryget(&h_cg->css)) {
 		goto again;

The commit for this change in Linux stable tree is 0362f32 (patch).

Leave a Reply

Your email address will not be published. Required fields are marked *