Re: [PATCH v8] hugetlb: Add hugetlb.*.numa_stat file

From: Muchun Song
Date: Mon Nov 22 2021 - 21:37:32 EST


On Tue, Nov 23, 2021 at 8:10 AM Mina Almasry <almasrymina@xxxxxxxxxx> wrote:
>
> For hugetlb backed jobs/VMs it's critical to understand the numa
> information for the memory backing these jobs to deliver optimal
> performance.
>
> Currently this technically can be queried from /proc/self/numa_maps, but
> there are significant issues with that. Namely:
> 1. Memory can be mapped or unmapped.
> 2. numa_maps are per process and need to be aggregated across all
> processes in the cgroup. For shared memory this is more involved as
> the userspace needs to make sure it doesn't double count shared
> mappings.
> 3. I believe querying numa_maps needs to hold the mmap_lock which adds
> to the contention on this lock.
>
> For these reasons I propose simply adding hugetlb.*.numa_stat file,
> which shows the numa information of the cgroup similarly to
> memory.numa_stat.
>
> On cgroup-v2:
> cat /sys/fs/cgroup/unified/test/hugetlb.2MB.numa_stat
> total=2097152 N0=2097152 N1=0
>
> On cgroup-v1:
> cat /sys/fs/cgroup/hugetlb/test/hugetlb.2MB.numa_stat
> total=2097152 N0=2097152 N1=0
> hierarichal_total=2097152 N0=2097152 N1=0
>
> This patch was tested manually by allocating hugetlb memory and querying
> the hugetlb.*.numa_stat file of the cgroup and its parents.
>
> Cc: Mike Kravetz <mike.kravetz@xxxxxxxxxx>
> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Cc: Shuah Khan <shuah@xxxxxxxxxx>
> Cc: Miaohe Lin <linmiaohe@xxxxxxxxxx>
> Cc: Oscar Salvador <osalvador@xxxxxxx>
> Cc: Michal Hocko <mhocko@xxxxxxxx>
> Cc: Muchun Song <songmuchun@xxxxxxxxxxxxx>
> Cc: David Rientjes <rientjes@xxxxxxxxxx>
> Cc: Shakeel Butt <shakeelb@xxxxxxxxxx>
> Cc: Jue Wang <juew@xxxxxxxxxx>
> Cc: Yang Yao <ygyao@xxxxxxxxxx>
> Cc: Joanna Li <joannali@xxxxxxxxxx>
> Cc: Cannon Matthews <cannonmatthews@xxxxxxxxxx>
> Cc: linux-mm@xxxxxxxxx
> Cc: linux-kernel@xxxxxxxxxxxxxxx
>
> Signed-off-by: Mina Almasry <almasrymina@xxxxxxxxxx>

Reviewed-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>