Re: [PATCH 21/21] RFC: mm/hugetlb_cgroup: charge faults to mm->owner

From: David Hildenbrand (Arm)

Date: Wed Dec 02 2026 - 13:48:22 EST


> Hi David,>

Hi!

> hugetlb_cgroup_from_mm() falls back to current for mm == NULL, while
> get_mem_cgroup_from_mm() uses current->mm. Should
> hugetlb_cgroup_from_mm() follow memcg and use current->mm->owner when
> current->mm is non-NULL, and fall back to current otherwise? Something
> like this:

That sounds like making it more consistent, which should be the right thing to do.

>
> --- a/mm/hugetlb_cgroup.c
> +++ b/mm/hugetlb_cgroup.c
> @@ -287,6 +287,8 @@ static struct hugetlb_cgroup
> *hugetlb_cgroup_from_mm(struct mm_struct *mm)
>  #ifdef CONFIG_MEMCG
>      /* Like memcg, charge the owner of the mm we allocate for. */
> +    if (!mm)
> +        mm = current->mm;
>      if (mm)
>          task = rcu_dereference(mm->owner);
>  #endif
>

Ack, I'll fold that in.

>> +
>> static int __hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
>> - struct hugetlb_cgroup **ptr,
>> - bool rsvd)
>> + struct mm_struct *mm, struct hugetlb_cgroup **ptr, bool rsvd)
>> {
>> int ret = 0;
>> struct page_counter *counter;
>> @@ -293,7 +304,12 @@ static int __hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
>> goto done;
>> again:
>> rcu_read_lock();
>> - h_cg = hugetlb_cgroup_from_task(current);
>> + h_cg = hugetlb_cgroup_from_mm(mm);
>
> hugetlb_reserve_pages() has a vma but passes NULL, so the reservation
> is charged to current instead of mm->owner. Would it make sense to
> charge it to mm->owner as well? Something like this:

I think with the above applied, that is no longer required. (current->mm ==
vma->vm_mm AFAIKS)

But below is clearer, so I'll fold that in as well, thanks!


--
Cheers,

David