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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFFF8C433F5 for ; Tue, 1 Feb 2022 22:10:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 36EB08D0090; Tue, 1 Feb 2022 17:10:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 305948D0077; Tue, 1 Feb 2022 17:10:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1979A8D0090; Tue, 1 Feb 2022 17:10:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay033.a.hostedemail.com [64.99.140.33]) by kanga.kvack.org (Postfix) with ESMTP id 036108D0077 for ; Tue, 1 Feb 2022 17:10:57 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id ACC8420A87 for ; Tue, 1 Feb 2022 22:10:56 +0000 (UTC) X-FDA: 79095606912.03.6AF4C63 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf09.hostedemail.com (Postfix) with ESMTP id 35673140004 for ; Tue, 1 Feb 2022 22:10:56 +0000 (UTC) Received: by mail-pf1-f175.google.com with SMTP id d187so17108462pfa.10 for ; Tue, 01 Feb 2022 14:10:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2xHEO6/IBGHMAC/QWKgy3q9RlJbp71AlC0JvRvEV/DE=; b=AMBjtxpi2+m2v8BOBUBBFm6evgAA7q21Mi7YpqNmsTNr+KPLlkkvJbAZRkeuTS2E27 e70+E6dfkmznoSqepcK4TGSZt7l3+P5pQduy7QwipHihcNH+zA670k59ivCOBH8H6ApS +bwhjb2dRevjYyZRsKEdHDLv8yED/2cviLvH2/0cz9YWK362fLAZcEwKiLVgqR/5lLPI Lh2fd3Y6m4g7lh6072LVTfFRZWVYM3JSZv4tN5L5K+JYVRc60iP0nkmmrW6OBaKhH97d leiGTK39Evv2EbTMtjdkGXvoolqhhax44LaZHCXQS7aoaV/+uqPQKqKlzk/6jgcsoXjo u9uA== 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; bh=2xHEO6/IBGHMAC/QWKgy3q9RlJbp71AlC0JvRvEV/DE=; b=fe6U+cDBFDZKZ/HgjGDpsENQesRrbYSNJdGVVhIx++M2/Cn+6Sl1b1zCq4F8xsFCm4 dYeYBQI/BC7whoaDhSntQlPp8Bo2R1uE/s8J30jdeqrHuJ/1KlU2VmKJsMosyGRsJGqV CGRLH2iHX3cQO/+0eiGto9vt8GKK/rSMxUAKsV+RkWzoo9ofr6UJ9gAIlFaeyx5p5BDK BYoPYqJCp4ghmMKeM4oDTONPv6K/rmy5O6nRPtKSza1E3HeILJhU7ampINLdFgIJpLWJ XI2cIU1oncaDT/8LlAxyNsid14n4RykF0Z9t+E1tj9WoEwWZl5F1Z0JSPgj72HhXwo4U 4qxw== X-Gm-Message-State: AOAM530lsRiDjkuarxly8D4PHJ9cfYex6PVD9t6VWpia1u55J9PKku4k jJl3X7nZ4/IoBFKy0gYoYFkks9l+Hkc2x8WIkVK6nA== X-Google-Smtp-Source: ABdhPJw95Z6BIWNIq4Ux1U5dRo6t0UlChSg6ajpZgF1yoghZAg6I52WPcd0fWNRigZqtiTqKl/OufKTdCeDrFiD3WDY= X-Received: by 2002:a62:8183:: with SMTP id t125mr26780654pfd.41.1643753454908; Tue, 01 Feb 2022 14:10:54 -0800 (PST) MIME-Version: 1.0 References: <20220201200823.3283171-1-yosryahmed@google.com> In-Reply-To: From: Yosry Ahmed Date: Tue, 1 Feb 2022 14:10:18 -0800 Message-ID: Subject: Re: [PATCH] memcg: add per-memcg total kernel memory stat To: Johannes Weiner Cc: Andrew Morton , Michal Hocko , Muchun Song , Shakeel Butt , linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 35673140004 X-Stat-Signature: zbwpe9a3apiwb38nbdobrowe3c6pouri X-Rspam-User: nil Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=AMBjtxpi; spf=pass (imf09.hostedemail.com: domain of yosryahmed@google.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1643753456-216382 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: Hello Johannes, Thanks so much for your review. On Tue, Feb 1, 2022 at 1:00 PM Johannes Weiner wrote: > > Hello Yosry, > > On Tue, Feb 01, 2022 at 08:08:23PM +0000, Yosry Ahmed wrote: > > Currently memcg stats show several types of kernel memory: > > kernel stack, page tables, sock, vmalloc, and slab. > > However, there are other allocations with __GFP_ACCOUNT > > (or supersets such as GFP_KERNEL_ACCOUNT) that are not accounted > > in any of those stats, a few examples are: > > - various kvm allocations (e.g. allocated pages to create vcpus) > > - io_uring > > - tmp_page in pipes during pipe_write() > > - bpf ringbuffers > > - unix sockets > > > > Keeping track of the total kernel memory is essential for the ease of > > migration from cgroup v1 to v2 as there are large discrepancies between > > v1's kmem.usage_in_bytes and the sum of the available kernel memory stats > > in v2. Adding separate memcg stats for all __GFP_ACCOUNT kernel > > allocations is an impractical maintenance burden as there a lot of those > > all over the kernel code, with more use cases likely to show up in the > > future. > > No objection, I'm just curious how it makes migration to v2 easier in > particular. Or is it just that you've used the v1 stat to track > application regressions and would like to continue doing that in v2? > We are using "memory.kmem.usage_in_bytes" in v1 to get the total kernel memory accounted to a memcg to maintain historical data of jobs memory (anon, file, kernel), and for debugging purposes. In v2 there is no equivalent. We found that the total of other existing v2 kernel memory stats (vmalloc, slab, stack, ..) is very different for some workloads compared to v1's "memory.kmem.usage_in_bytes". We need a v2 indicator of the total kernel memory accounted to a memcg." > > Therefore, add a "kernel" memcg stat that is analogous to kmem > > page counter, with added benefits such as using rstat infrastructure > > which aggregates stats more efficiently. Additionally, this provides a > > lighter alternative in case the legacy kmem is deprecated in the future > > > > Signed-off-by: Yosry Ahmed > > --- > > Documentation/admin-guide/cgroup-v2.rst | 5 +++++ > > include/linux/memcontrol.h | 1 + > > mm/memcontrol.c | 24 ++++++++++++++++++------ > > 3 files changed, 24 insertions(+), 6 deletions(-) > > > > diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst > > index 5aa368d165da..a0027d570a7f 100644 > > --- a/Documentation/admin-guide/cgroup-v2.rst > > +++ b/Documentation/admin-guide/cgroup-v2.rst > > @@ -1317,6 +1317,11 @@ PAGE_SIZE multiple when read back. > > vmalloc (npn) > > Amount of memory used for vmap backed memory. > > > > + kernel (npn) > > + Amount of total kernel memory, including > > + (kernel_stack, pagetables, percpu, vmalloc, slab) in > > + addition to other kernel memory use cases. > > + > > shmem > > Amount of cached filesystem data that is swap-backed, > > such as tmpfs, shm segments, shared anonymous mmap()s > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > > index b72d75141e12..fa51986365a4 100644 > > --- a/include/linux/memcontrol.h > > +++ b/include/linux/memcontrol.h > > @@ -34,6 +34,7 @@ enum memcg_stat_item { > > MEMCG_SOCK, > > MEMCG_PERCPU_B, > > MEMCG_VMALLOC, > > + MEMCG_KMEM, > > MEMCG_NR_STAT, > > }; > > > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > index 09d342c7cbd0..c55d7056ac98 100644 > > --- a/mm/memcontrol.c > > +++ b/mm/memcontrol.c > > @@ -1376,6 +1376,7 @@ static const struct memory_stat memory_stats[] = { > > { "percpu", MEMCG_PERCPU_B }, > > { "sock", MEMCG_SOCK }, > > { "vmalloc", MEMCG_VMALLOC }, > > + { "kernel", MEMCG_KMEM }, > > It's a superset of percpu, sock, vmalloc etc., so please move it ahead > of them. > > anon > file > kernel > kernel_stack > pagetables > ... > > and in the doc as well. > Done in v2. > > { "shmem", NR_SHMEM }, > > { "file_mapped", NR_FILE_MAPPED }, > > { "file_dirty", NR_FILE_DIRTY }, > > @@ -2979,6 +2980,19 @@ static void memcg_free_cache_id(int id) > > ida_simple_remove(&memcg_cache_ida, id); > > } > > > > +static void mem_cgroup_kmem_record(struct mem_cgroup *memcg, > > + int nr_pages) > > No real need for the namespace prefix since it's a static > function. How about account_kmem()? Avoids the line wrap, too. Does memcg_account_kmem() sound good? It avoids the line wrap too and is more consistent with most static functions in the file that have either a "memcg_" or "mem_cgroup_" prefix. Thanks! > > Otherwise, looks good to me, so with those changes: > > Acked-by: Johannes Weiner > > Thanks!