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 0509CC433EF for ; Tue, 1 Feb 2022 21:00:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B2B06B0157; Tue, 1 Feb 2022 16:00:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 761B86B0158; Tue, 1 Feb 2022 16:00:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 602466B015A; Tue, 1 Feb 2022 16:00:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0097.hostedemail.com [216.40.44.97]) by kanga.kvack.org (Postfix) with ESMTP id 4EA066B0157 for ; Tue, 1 Feb 2022 16:00:49 -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 12ED39A292 for ; Tue, 1 Feb 2022 21:00:49 +0000 (UTC) X-FDA: 79095430218.10.FF87FFC Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by imf08.hostedemail.com (Postfix) with ESMTP id 43D5016000B for ; Tue, 1 Feb 2022 21:00:48 +0000 (UTC) Received: by mail-qk1-f170.google.com with SMTP id o12so16340170qke.5 for ; Tue, 01 Feb 2022 13:00:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=zh2HRwuNKx7PT7oWtqov40bxLvcOISQVIPi4Cb5Lh+c=; b=tnSgEux4dZPsnVaqxHway29AhA57bv5PLRRygiXqKVibwwdjETk6IvbnE3QMijL9y5 shQga544etO5GTxQGwwQFliOrXPSARwDVLa3wEwR8Q46QKUO/wCRuprHOA9d+5ISACFz RmlugelKIMuCQEQjKWD2vI8qrOM02DxA4KlvEv+kbn/dpycAbP1Vm9HkHgF6RoOh0rWk J73VzG03L2JPTw+oW13GzI+9DpYqkOiCEN5hVWzITf+vY8Rv6Gx8vdWH2E99qFR96xoW dmn7PjPuHmLU/AibAkA+jJ6GcRj1IfphoPcpedD1QcBc0gHE4MgIrvf03CkfPFv9e6ZM uMxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=zh2HRwuNKx7PT7oWtqov40bxLvcOISQVIPi4Cb5Lh+c=; b=XW8UP6hbovYthW/G1PkjH8BSELbG+nFfXRyrlknNewTMeY0ZPPsoSMUGlxJrRez5dg 1sPtTbRmESzsBifjTxs5KLD1CbObNpJ5HlOIxKNdLAf3BiGYDOFSKQUAuS8p9gOVDlhv 0fixjpoFtzdMWCDLCAl/1mgJApes/WjtUUWNkWw8yDy/JGSmEC+i6DiqsD5/TbPxH8xY fn282IQBJf24EFDhI+qWnDGANmxy42eNw2mB9MvGN/eAJWXHD5onmYfebK/YuqBjTkhr LNU5K9j7E/7qeXf9PWadduSwHYlXtV0ACq4tJhiWMGkdRM/r90TqD/+S0V+5G/9v2DG5 htyQ== X-Gm-Message-State: AOAM530wQ+O8b38KXwQBd21brR8OYL+nveIJTAypufLYnXwIewv0BL2L oN0uNO7X+9KNgN+jDLQ2qzNIPA== X-Google-Smtp-Source: ABdhPJyEBFUvfWptUDHA9K+9o0hQjKPVc1wTo5h0vSVMJNGBl7AeDmnGhrh9plQ4kEkKXifPZmZelA== X-Received: by 2002:a05:620a:103c:: with SMTP id a28mr18143036qkk.417.1643749247140; Tue, 01 Feb 2022 13:00:47 -0800 (PST) Received: from localhost (cpe-98-15-154-102.hvc.res.rr.com. [98.15.154.102]) by smtp.gmail.com with ESMTPSA id q8sm11532990qkl.65.2022.02.01.13.00.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 13:00:46 -0800 (PST) Date: Tue, 1 Feb 2022 16:00:46 -0500 From: Johannes Weiner To: Yosry Ahmed Cc: Andrew Morton , Michal Hocko , Muchun Song , Shakeel Butt , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] memcg: add per-memcg total kernel memory stat Message-ID: References: <20220201200823.3283171-1-yosryahmed@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220201200823.3283171-1-yosryahmed@google.com> X-Stat-Signature: o93bax5t1hqfzcgbmtyxwzu7s3uj46a6 X-Rspam-User: nil Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=tnSgEux4; spf=pass (imf08.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.170 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 43D5016000B X-HE-Tag: 1643749248-909094 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 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? > 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. > { "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. Otherwise, looks good to me, so with those changes: Acked-by: Johannes Weiner Thanks!