Re: [PATCH v4 5/6] mm: hugetlb: Move mem_cgroup_charge_hugetlb() earlier in allocation

From: Andrew Morton

Date: Thu Jul 02 2026 - 18:03:59 EST


On Thu, 02 Jul 2026 09:21:49 -0700 Ackerley Tng via B4 Relay <devnull+ackerleytng.google.com@xxxxxxxxxx> wrote:

> Move mem_cgroup_charge_hugetlb() earlier in the folio allocation
> process. This change draws a cleaner line between memcg charging and the
> subsequent hugetlb-specific reservation logic for VMAs and subpools.
>
> While it would be ideal to make all accounting and reservations perfectly
> symmetric, mem_cgroup_charge_hugetlb() is a complex operation that cannot
> be performed under the hugetlb_lock. Moving the charge to this earlier
> point ensures that memcg charging is handled before the code begins
> manipulating subpool and VMA-specific state. These two types of accounting
> will be separated in a future patch.
>
> If mem_cgroup_charge_hugetlb() fails, the code now branches to
> out_subpool_put to ensure the folio is freed and the subpool references are
> handled correctly.

Is this patch also "No functional change intended"?