From: Roman Gushchin <guro@fb.com>
To: Dennis Zhou <dennis@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Tejun Heo <tj@kernel.org>, Christoph Lameter <cl@linux.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Shakeel Butt <shakeelb@google.com>, <linux-mm@kvack.org>,
<kernel-team@fb.com>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v1 5/5] kselftests: cgroup: add perpcu memory accounting test
Date: Fri, 5 Jun 2020 15:47:05 -0700 [thread overview]
Message-ID: <20200605224705.GD561977@carbon.DHCP.thefacebook.com> (raw)
In-Reply-To: <20200605200751.GE224745@google.com>
On Fri, Jun 05, 2020 at 08:07:51PM +0000, Dennis Zhou wrote:
> On Thu, May 28, 2020 at 04:25:08PM -0700, Roman Gushchin wrote:
> > Add a simple test to check the percpu memory accounting.
> > The test creates a cgroup tree with 1000 child cgroups
> > and checks values of memory.current and memory.stat::percpu.
> >
> > Signed-off-by: Roman Gushchin <guro@fb.com>
> > ---
> > tools/testing/selftests/cgroup/test_kmem.c | 59 ++++++++++++++++++++++
> > 1 file changed, 59 insertions(+)
> >
> > diff --git a/tools/testing/selftests/cgroup/test_kmem.c b/tools/testing/selftests/cgroup/test_kmem.c
> > index 5224dae216e5..a0d4f1a3137d 100644
> > --- a/tools/testing/selftests/cgroup/test_kmem.c
> > +++ b/tools/testing/selftests/cgroup/test_kmem.c
> > @@ -331,6 +331,64 @@ static int test_kmem_dead_cgroups(const char *root)
> > return ret;
> > }
> >
> > +/*
> > + * This test creates a sub-tree with 1000 memory cgroups.
> > + * Then it checks that the memory.current on the parent level
> > + * is greater than 0 and approximates matches the percpu value
> > + * from memory.stat.
> > + */
> > +static int test_percpu_basic(const char *root)
> > +{
> > + int ret = KSFT_FAIL;
> > + char *parent, *child;
> > + long current, percpu;
> > + int i;
> > +
> > + parent = cg_name(root, "percpu_basic_test");
> > + if (!parent)
> > + goto cleanup;
> > +
> > + if (cg_create(parent))
> > + goto cleanup;
> > +
> > + if (cg_write(parent, "cgroup.subtree_control", "+memory"))
> > + goto cleanup;
> > +
> > + for (i = 0; i < 1000; i++) {
> > + child = cg_name_indexed(parent, "child", i);
> > + if (!child)
> > + return -1;
> > +
> > + if (cg_create(child))
> > + goto cleanup_children;
> > +
> > + free(child);
> > + }
> > +
> > + current = cg_read_long(parent, "memory.current");
> > + percpu = cg_read_key_long(parent, "memory.stat", "percpu ");
> > +
> > + if (current > 0 && percpu > 0 && abs(current - percpu) <
> > + 4096 * 32 * get_nprocs())
>
> So this is checking that we've allocated less than 32 pages per cpu over
> 1000 child cgroups that's not percpu memory? Is there a more definitive
> measurement or at least a comment we can leave saying why this limit was
> chosen.
It simple means that "current" should be approximately equal to "percpu" statistics.
Both charging and vmstat paths are using percpu batching, and the batch size is
32 pages.
I'll add a comment to make it more obvious.
Thanks!
>
> > + ret = KSFT_PASS;
> > + else
> > + printf("memory.current %ld\npercpu %ld\n",
> > + current, percpu);
> > +
> > +cleanup_children:
> > + for (i = 0; i < 1000; i++) {
> > + child = cg_name_indexed(parent, "child", i);
> > + cg_destroy(child);
> > + free(child);
> > + }
> > +
> > +cleanup:
> > + cg_destroy(parent);
> > + free(parent);
> > +
> > + return ret;
> > +}
> > +
> > #define T(x) { x, #x }
> > struct kmem_test {
> > int (*fn)(const char *root);
> > @@ -341,6 +399,7 @@ struct kmem_test {
> > T(test_kmem_proc_kpagecgroup),
> > T(test_kmem_kernel_stacks),
> > T(test_kmem_dead_cgroups),
> > + T(test_percpu_basic),
> > };
> > #undef T
> >
> > --
> > 2.25.4
> >
> >
prev parent reply other threads:[~2020-06-05 22:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20200528232508.1132382-1-guro@fb.com>
[not found] ` <20200528232508.1132382-2-guro@fb.com>
2020-06-05 19:44 ` [PATCH v1 1/5] percpu: return number of released bytes from pcpu_free_area() Dennis Zhou
[not found] ` <20200528232508.1132382-3-guro@fb.com>
2020-06-05 19:49 ` [PATCH v1 2/5] mm: memcg/percpu: account percpu memory to memory cgroups Dennis Zhou
2020-06-05 22:44 ` Roman Gushchin
[not found] ` <20200528232508.1132382-4-guro@fb.com>
2020-06-05 19:53 ` [PATCH v1 3/5] mm: memcg/percpu: per-memcg percpu memory statistics Dennis Zhou
[not found] ` <20200528232508.1132382-5-guro@fb.com>
2020-06-05 19:54 ` [PATCH v1 4/5] mm: memcg: charge memcg percpu memory to the parent cgroup Dennis Zhou
[not found] ` <20200528232508.1132382-6-guro@fb.com>
2020-06-05 20:07 ` [PATCH v1 5/5] kselftests: cgroup: add perpcu memory accounting test Dennis Zhou
2020-06-05 22:47 ` Roman Gushchin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200605224705.GD561977@carbon.DHCP.thefacebook.com \
--to=guro@fb.com \
--cc=akpm@linux-foundation.org \
--cc=cl@linux.com \
--cc=dennis@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=shakeelb@google.com \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).