This series cleans up memcg's hugetlb charging logic by deprecating the current memcg hugetlb try-charge + {commit, cancel} logic present in alloc_hugetlb_folio. A single function mem_cgroup_charge_hugetlb takes its place instead. This makes the code more maintainable by simplifying the error path, and reduces memcg's footprint in hugetlb logic. This patch introduces a few changes in the allocation error path: (a) Instead of having multiple return paths, we consolidate them into a single error path. Failing when memcg's limit is reached no longer returns -ENOMEM, but -ENOSPEC like the other errors as well. This makes the memory controller error behavior the same as hugeTLB's. With this said, no callers handle -ENOMEM separately, so no existing behavior is affected by this change. (b) Previously, the memcg limit is checked before the folio is acquired, meaning the hugeTLB folio isn't acquired if the limit is reached. This patch performs the charging after the folio is reached, meaning if memcg's limit is reached, the acquired folio is freed right away. In the first patch, a check for whether memcg accounts hugetlb [1] is introduced. In the second patch, the charging mechanism is reworked. This patch builds on earlier work [2] which adds memcg hugeTLB counters. The request for this rework is also part of the original thread. Suggested-by: Shakeel Butt <shakeel.butt@xxxxxxxxx> Signed-off-by: Joshua Hahn <joshua.hahnjy@xxxxxxxxx> [1] https://lore.kernel.org/all/20231006184629.155543-1-nphamcs@xxxxxxxxx/ [2] https://lore.kernel.org/all/20241101204402.1885383-1-joshua.hahnjy@xxxxxxxxx/ Joshua Hahn (2): Introduce memcg_accounts_hugetlb Deprecate hugetlb memcg try-commit-cancel charging include/linux/memcontrol.h | 5 ++-- mm/hugetlb.c | 35 ++++++++++------------------ mm/memcontrol.c | 47 +++++++++++++++----------------------- 3 files changed, 33 insertions(+), 54 deletions(-) base-commit: 34d664f9c954f4bce85be506bd81024f64dd5fda -- 2.43.5