Re: [RFC PATCH 2/6] mm: memcg: make memcg huge page split support any order split.
From: Roman Gushchin
Date: Fri Nov 13 2020 - 19:23:37 EST
On Wed, Nov 11, 2020 at 03:40:04PM -0500, Zi Yan wrote:
> From: Zi Yan <ziy@xxxxxxxxxx>
>
> It reads thp_nr_pages and splits to provided new_nr. It prepares for
> upcoming changes to support split huge page to any lower order.
>
> Signed-off-by: Zi Yan <ziy@xxxxxxxxxx>
> ---
> include/linux/memcontrol.h | 5 +++--
> mm/huge_memory.c | 2 +-
> mm/memcontrol.c | 4 ++--
> 3 files changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index 0f4dd7829fb2..b3bac79ceed6 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -1105,7 +1105,7 @@ static inline void memcg_memory_event_mm(struct mm_struct *mm,
> }
>
> #ifdef CONFIG_TRANSPARENT_HUGEPAGE
> -void mem_cgroup_split_huge_fixup(struct page *head);
> +void mem_cgroup_split_huge_fixup(struct page *head, unsigned int new_nr);
> #endif
>
> #else /* CONFIG_MEMCG */
> @@ -1451,7 +1451,8 @@ unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order,
> return 0;
> }
>
> -static inline void mem_cgroup_split_huge_fixup(struct page *head)
> +static inline void mem_cgroup_split_huge_fixup(struct page *head,
> + unsigned int new_nr)
> {
> }
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index c4fead5ead31..f599f5b9bf7f 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -2429,7 +2429,7 @@ static void __split_huge_page(struct page *page, struct list_head *list,
> lruvec = mem_cgroup_page_lruvec(head, pgdat);
>
> /* complete memcg works before add pages to LRU */
> - mem_cgroup_split_huge_fixup(head);
> + mem_cgroup_split_huge_fixup(head, 1);
>
> if (PageAnon(head) && PageSwapCache(head)) {
> swp_entry_t entry = { .val = page_private(head) };
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 33f632689cee..e9705ba6bbcc 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3247,7 +3247,7 @@ void obj_cgroup_uncharge(struct obj_cgroup *objcg, size_t size)
> * Because tail pages are not marked as "used", set it. We're under
> * pgdat->lru_lock and migration entries setup in all page mappings.
> */
> -void mem_cgroup_split_huge_fixup(struct page *head)
> +void mem_cgroup_split_huge_fixup(struct page *head, unsigned int new_nr)
I'd go with unsigned int new_order, then it's obvious that we can split
the original page without any leftovers.
Other than that the patch looks good!
Acked-by: Roman Gushchin <guro@xxxxxx>
Thanks!
> {
> struct mem_cgroup *memcg = page_memcg(head);
> int i;
> @@ -3255,7 +3255,7 @@ void mem_cgroup_split_huge_fixup(struct page *head)
> if (mem_cgroup_disabled())
> return;
>
> - for (i = 1; i < thp_nr_pages(head); i++) {
> + for (i = new_nr; i < thp_nr_pages(head); i += new_nr) {
> css_get(&memcg->css);
> head[i].memcg_data = (unsigned long)memcg;
> }
> --
> 2.28.0
>