From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B10FC433F5 for ; Wed, 10 Nov 2021 06:28:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1BFDE61168 for ; Wed, 10 Nov 2021 06:28:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1BFDE61168 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 8B9296B006C; Wed, 10 Nov 2021 01:28:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 868B76B0071; Wed, 10 Nov 2021 01:28:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 756FD6B0072; Wed, 10 Nov 2021 01:28:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0024.hostedemail.com [216.40.44.24]) by kanga.kvack.org (Postfix) with ESMTP id 664CD6B006C for ; Wed, 10 Nov 2021 01:28:23 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 227367F8F2 for ; Wed, 10 Nov 2021 06:28:23 +0000 (UTC) X-FDA: 78792041286.10.9F27098 Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) by imf06.hostedemail.com (Postfix) with ESMTP id 9FE82801A8AE for ; Wed, 10 Nov 2021 06:28:22 +0000 (UTC) Received: by mail-yb1-f180.google.com with SMTP id o12so3861690ybk.1 for ; Tue, 09 Nov 2021 22:28:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=AyFThLvs6UKw51gxhNX63dY3arYNMwAczrnoeEvicwM=; b=zmLZ5Ns3XHuwD2JA3cwajolo6nj4tD86lMFefSH0AgKDjQ/Ygjz6KXhxkdV6ar09WP QWb1LvLCmPn2l24KzVKS8n4GXntRuWkomu+r6x0QDPgEg3VreGKclK34hIZxEJU+F7h7 omfRnLdJMPjaGluYhdCRLWUTyO5HkzT3Ax6qWtfnkjr52gn8tzfOUWCsqZeFvgkayjDL kAXoEqFssJXYRknpebP+VCL+q74N+RjkEdYmQs7//3znXMbT6UQ30nzedl+ETmKM0T9D iexQfz9yNPGjhoh/Wc9A1zR4/brxWOgCBnPLy22qREapoyXZ1Q5bb/ghjwjvhhZrHWUQ v6OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=AyFThLvs6UKw51gxhNX63dY3arYNMwAczrnoeEvicwM=; b=UsLCkafYrpqVL7Lqn11yLKOlQfFzEYShEXIp80SPJCXW7XBsv6PfXBSDQ8s4JMilbO NgSy7q26u00zF/E0uUxpD2f6Ok/QCs/o6cH77W5whlmMjGdzr1iKMVECwplPWsyY5Jxz FZJbb+RLkrtbj6cDw80nUE74SMpXvxFcV79X6qbiX+XTpqmtQPLLIeGnrbVq6ebAusGs 2quWshzhTI10gV2iT8Pkj+UORvp3LrBnOC3xriKzGJz1YfFP2nvBEKJLx5piK/sqfvM+ uGe5oh3AaF5/lG8ZOht7k3UVMJxZdzW0zNQfN9y3Lyw29lGna7qBOcOjO7n5nALuZkaj nH7w== X-Gm-Message-State: AOAM530NMdSwFLvlkE5Q6P28SpA/kWn2hs/epzi/NhokNrqPEsS6jypP hBNdZjkuG1xBsaScJFQE4yMYBpkvFqoU6EUaIwMl2g== X-Google-Smtp-Source: ABdhPJwC7qskfs7QwZHbFyDxilMDue9zV6YG5pMGj0/sEbIADyRB1Y6lEadH5n/8f/+S7jw3uQGIC6W8cxVFJInuzyY= X-Received: by 2002:a5b:648:: with SMTP id o8mr16035315ybq.208.1636525701723; Tue, 09 Nov 2021 22:28:21 -0800 (PST) MIME-Version: 1.0 References: <20211108210456.1745788-1-almasrymina@google.com> In-Reply-To: <20211108210456.1745788-1-almasrymina@google.com> From: Muchun Song Date: Wed, 10 Nov 2021 14:27:43 +0800 Message-ID: Subject: Re: [PATCH v4] hugetlb: Add hugetlb.*.numa_stat file To: Mina Almasry Cc: Mike Kravetz , Andrew Morton , Shuah Khan , Miaohe Lin , Oscar Salvador , Michal Hocko , David Rientjes , Shakeel Butt , Jue Wang , Yang Yao , Joanna Li , Cannon Matthews , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 9FE82801A8AE X-Stat-Signature: uk6kpm7nyi15tndoq7bxcxizw8xh5pg8 Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=zmLZ5Ns3; spf=pass (imf06.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.219.180 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-HE-Tag: 1636525702-657350 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Nov 9, 2021 at 5:04 AM Mina Almasry 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 on 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=3D2097152 N0=3D2097152 N1=3D0 > > On cgroup-v1: > cat /sys/fs/cgroup/hugetlb/test/hugetlb.2MB.numa_stat > total=3D2097152 N0=3D2097152 N1=3D0 > hierarichal_total=3D2097152 N0=3D2097152 N1=3D0 > > This patch was tested manually by allocating hugetlb memory and querying > the hugetlb.*.numa_stat file of the cgroup and its parents. > =EF=BF=BC > Cc: Mike Kravetz > Cc: Andrew Morton > Cc: Shuah Khan > Cc: Miaohe Lin > Cc: Oscar Salvador > Cc: Michal Hocko > Cc: Muchun Song > Cc: David Rientjes > Cc: Shakeel Butt > Cc: Jue Wang > Cc: Yang Yao > Cc: Joanna Li > Cc: Cannon Matthews > Cc: linux-mm@kvack.org > Cc: linux-kernel@vger.kernel.org > > Signed-off-by: Mina Almasry > > --- > > Changes in v4: > - Removed unnecessary braces. > - usage is now counted in pages instead of bytes. > - Reverted unneeded changes to write_to_hugetlbfs.c > > Changes in v3: > - Fixed typos (sorry!) > - Used conventional locations for cgroups mount points in docs/commit > message. > - Updated docs. > - Handle kzalloc_node failure, and proper deallocation of per node data. > - Use struct_size() to calculate the struct size. > - Use nr_node_ids instead of MAX_NUMNODES. > - Updated comments per multi-line comment pattern. > > Changes in v2: > - Fix warning Reported-by: kernel test robot > --- > .../admin-guide/cgroup-v1/hugetlb.rst | 4 + > Documentation/admin-guide/cgroup-v2.rst | 5 + > include/linux/hugetlb.h | 4 +- > include/linux/hugetlb_cgroup.h | 7 ++ > mm/hugetlb_cgroup.c | 113 ++++++++++++++++-- > 5 files changed, 122 insertions(+), 11 deletions(-) > > diff --git a/Documentation/admin-guide/cgroup-v1/hugetlb.rst b/Documentat= ion/admin-guide/cgroup-v1/hugetlb.rst > index 338f2c7d7a1c..0fa724d82abb 100644 > --- a/Documentation/admin-guide/cgroup-v1/hugetlb.rst > +++ b/Documentation/admin-guide/cgroup-v1/hugetlb.rst > @@ -29,12 +29,14 @@ Brief summary of control files:: > hugetlb..max_usage_in_bytes # show max "hugep= agesize" hugetlb usage recorded > hugetlb..usage_in_bytes # show current us= age for "hugepagesize" hugetlb > hugetlb..failcnt # show the number= of allocation failure due to HugeTLB usage limit > + hugetlb..numa_stat # show the numa i= nformation of the hugetlb memory charged to this cgroup > > For a system supporting three hugepage sizes (64k, 32M and 1G), the cont= rol > files include:: > > hugetlb.1GB.limit_in_bytes > hugetlb.1GB.max_usage_in_bytes > + hugetlb.1GB.numa_stat > hugetlb.1GB.usage_in_bytes > hugetlb.1GB.failcnt > hugetlb.1GB.rsvd.limit_in_bytes > @@ -43,6 +45,7 @@ files include:: > hugetlb.1GB.rsvd.failcnt > hugetlb.64KB.limit_in_bytes > hugetlb.64KB.max_usage_in_bytes > + hugetlb.64KB.numa_stat > hugetlb.64KB.usage_in_bytes > hugetlb.64KB.failcnt > hugetlb.64KB.rsvd.limit_in_bytes > @@ -51,6 +54,7 @@ files include:: > hugetlb.64KB.rsvd.failcnt > hugetlb.32MB.limit_in_bytes > hugetlb.32MB.max_usage_in_bytes > + hugetlb.32MB.numa_stat > hugetlb.32MB.usage_in_bytes > hugetlb.32MB.failcnt > hugetlb.32MB.rsvd.limit_in_bytes > diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admi= n-guide/cgroup-v2.rst > index 4d8c27eca96b..356847f8f008 100644 > --- a/Documentation/admin-guide/cgroup-v2.rst > +++ b/Documentation/admin-guide/cgroup-v2.rst > @@ -2252,6 +2252,11 @@ HugeTLB Interface Files > are local to the cgroup i.e. not hierarchical. The file modified = event > generated on this file reflects only the local events. > > + hugetlb..numa_stat > + Similar to memory.numa_stat, it shows the numa information of the > + hugetlb pages of in this cgroup. Only active in > + use hugetlb pages are included. The per-node values are in byte= s. > + > Misc > ---- > > diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h > index 1faebe1cd0ed..0445faaa636e 100644 > --- a/include/linux/hugetlb.h > +++ b/include/linux/hugetlb.h > @@ -613,8 +613,8 @@ struct hstate { > #endif > #ifdef CONFIG_CGROUP_HUGETLB > /* cgroup control files */ > - struct cftype cgroup_files_dfl[7]; > - struct cftype cgroup_files_legacy[9]; > + struct cftype cgroup_files_dfl[8]; > + struct cftype cgroup_files_legacy[10]; > #endif > char name[HSTATE_NAME_LEN]; > }; > diff --git a/include/linux/hugetlb_cgroup.h b/include/linux/hugetlb_cgrou= p.h > index c137396129db..54ff6ec68ed3 100644 > --- a/include/linux/hugetlb_cgroup.h > +++ b/include/linux/hugetlb_cgroup.h > @@ -36,6 +36,11 @@ enum hugetlb_memory_event { > HUGETLB_NR_MEMORY_EVENTS, > }; > > +struct hugetlb_cgroup_per_node { > + /* hugetlb usage in bytes over all hstates. */ The accounting unit is pages not bytes here. Thanks.