Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3479738pxu; Sun, 11 Oct 2020 11:10:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMdpXYPS+9AKHNJeHLXdLWqzmRxEG7je043lQX/JY02+TW3YUMJ4BSiUsAhB49ZTSsUg5T X-Received: by 2002:a17:906:8297:: with SMTP id h23mr23770862ejx.383.1602439843464; Sun, 11 Oct 2020 11:10:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602439843; cv=none; d=google.com; s=arc-20160816; b=XnHamTFmqrsL1AKuDVNU/92yxDPtHMW2z59VHc7iv+zkIDimBOazDDlR6OqKv1Vqwb ilAEBqGx7VUUzlBj5onjfgQn5uL0ZHiqCLMhHJIHjpAL9Ac44Ux03hj/NQ2ItS3S6omr hrqSfzxAl5Rt2ObEokQXA04LxuDWeLywb6cm1txpraO8n04Tc6D9Ool453s2R51t72PI eqshTsFVyQKdz9PCFlub0Q8RE5/s3zmBJ2kw9kqgHArL5iB+gw36xvm3LldIMAFuDaAM I/AbLl5fzJAxGgO0XwKWszkuMpqvQNYbBS9LZourHGhU1rr15E3olbomcOrCIzlgRKnr BUcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ZeFjw3qLweAjOU35zoRBA8nXBOKUeG2GljXb+HxWSOw=; b=0uyi2BGGB8ethcBKB3vT+Ch1FIbwW5BYlZuof4bQocJo5QjN4nqCSibqAZuUlXN6wI 3XQXeQmsc5PtVf0VhTCV0SL0ghS5gW3SHTWnQgNXZgnd2O3pkdbmJqRcruz+WNnIlM6t GXi6K2G3rQKLzQqrJtJ1Eq5A05GGcNY5BwzcCx1KRLqBvF4cJXjoMYRKBUvNIjStWIL+ hXWz7yWYGj0o3KZTrIgTgm5uuIJlNNgTZZ/SrFJcAeiZ5tYefw2mlQCrnxE2zIgey3QN gpJmLYHUkbcZFGnP6OAdzV8qqW/2F2uJk30eOE9SwUqxvB3THBsr4s331VCr9u33QWPw EC5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=wAfLQMkt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q5si8034879edv.293.2020.10.11.11.10.20; Sun, 11 Oct 2020 11:10:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=wAfLQMkt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387808AbgJKQBE (ORCPT + 99 others); Sun, 11 Oct 2020 12:01:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387821AbgJKQBC (ORCPT ); Sun, 11 Oct 2020 12:01:02 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F4E8C0613D2 for ; Sun, 11 Oct 2020 09:01:01 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id o3so1630130pgr.11 for ; Sun, 11 Oct 2020 09:01:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZeFjw3qLweAjOU35zoRBA8nXBOKUeG2GljXb+HxWSOw=; b=wAfLQMktP3vX4gsrlyNS7bbn9fQ5HRsy2aJNNdt6ka30g9Ko/FJhQwWyAHrLsBd1W9 7AiJ5IaRRvN+HySKCHGDPwiC0KkE+cFhqzlUT4+q4MXFanvmSVhk/kzTw908Gp1DWunj zrQDcro6Gcwx4ETnK2/bI3WREkoPuUKNxqbhUDblGB+RWrRA87LcKUVozSjTa0x3aNMe TUQIZ6CB0bnK1Tsxxg9Y/KgqK9yXkn32E64iseUZsCkqK97b9VQugRYctPXTC92FZ3is k77wtpura5vda4j29hm2YPSItLsBTdPUa81UMEMC4p8nkdaVpbPPm3RHrSzFWPa5Tayd a3TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZeFjw3qLweAjOU35zoRBA8nXBOKUeG2GljXb+HxWSOw=; b=LUuIAEHUzw4yLJN9E2Egh9lKd8fisEKbR91Bs1uUJdKnd+U26QOYCxe7fJ2hx2q+qX Na9ecAaKn2Mwwu+0bigyLgI+t4YWK9aJuM1/l5KKZpi9RyMo814JkT14bd+cq7JhHC+d xs7P8UjoNf4mZKD/7Ncsif0KIIpAxh/6lX/JsrXJNURM5VhSjQyMZKTg9IZqFt+9AJje ri9SAj2J+os7d9G3Lb0DQSSKltAm5cTv63Xokdc9g/rDMZlzr2Pu9YO1W40QmwH5GS+1 nuPT5KBLgkRojues+hfnqgfu9bi2z1mAzXXP/xoUQHWDImm2rGD21YF5FXF1mgyVlZXI tI6w== X-Gm-Message-State: AOAM531tbDPvgDTTNQn7nBNTl8Q6cu5rQEYjm9LgNNYja1IqhAa95n5/ SWJT2mdBYi3KJ6od0mxL0fKx1j3Bg4EQbElGJZhuDA== X-Received: by 2002:a17:90a:4749:: with SMTP id y9mr2820055pjg.229.1602432060784; Sun, 11 Oct 2020 09:01:00 -0700 (PDT) MIME-Version: 1.0 References: <20201010103854.66746-1-songmuchun@bytedance.com> <20201011135244.GC4251@kernel.org> In-Reply-To: <20201011135244.GC4251@kernel.org> From: Muchun Song Date: Mon, 12 Oct 2020 00:00:24 +0800 Message-ID: Subject: Re: [External] Re: [PATCH] mm: proc: add Sock to /proc/meminfo To: Mike Rapoport Cc: Greg KH , rafael@kernel.org, mst@redhat.com, jasowang@redhat.com, David Miller , kuba@kernel.org, adobriyan@gmail.com, Andrew Morton , Eric Dumazet , kuznet@ms2.inr.ac.ru, yoshfuji@linux-ipv6.org, steffen.klassert@secunet.com, herbert@gondor.apana.org.au, Shakeel Butt , Will Deacon , Michal Hocko , Roman Gushchin , neilb@suse.de, Sami Tolvanen , kirill.shutemov@linux.intel.com, feng.tang@intel.com, pabeni@redhat.com, Willem de Bruijn , Randy Dunlap , fw@strlen.de, gustavoars@kernel.org, pablo@netfilter.org, decui@microsoft.com, jakub@cloudflare.com, Peter Zijlstra , christian.brauner@ubuntu.com, ebiederm@xmission.com, Thomas Gleixner , dave@stgolabs.net, Michel Lespinasse , Jann Horn , chenqiwu@xiaomi.com, christophe.leroy@c-s.fr, minchan@kernel.org, Martin KaFai Lau , Alexei Starovoitov , Daniel Borkmann , linmiaohe@huawei.com, Kees Cook , LKML , virtualization@lists.linux-foundation.org, Networking , linux-fsdevel@vger.kernel.org, Linux Memory Management List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Oct 11, 2020 at 9:53 PM Mike Rapoport wrote: > > On Sat, Oct 10, 2020 at 06:38:54PM +0800, Muchun Song wrote: > > The amount of memory allocated to sockets buffer can become significant. > > However, we do not display the amount of memory consumed by sockets > > buffer. In this case, knowing where the memory is consumed by the kernel > > is very difficult. On our server with 500GB RAM, sometimes we can see > > 25GB disappear through /proc/meminfo. After our analysis, we found the > > following memory allocation path which consumes the memory with page_owner > > enabled. > > I have a high lelel question. > There is accounting of the socket memory for memcg that gets called from > the networking layer. Did you check if the same call sites can be used > for the system-wide accounting as well? I also think about this. But we did not pass the `struct page` parameter to the sock accounting memcg API. So we did not know the NUMA node which allocated the socket buffer memory and cannot do node-level statistics. In addition, there is another problem. If the user sends a 4096-byte message, we only charge one page to the memcg but the system allocates 8 pages. So if we reuse the same call sites for the system-wide accounting, the statistical count we get is always smaller than the actual situation. > > > 849698 times: > > Page allocated via order 3, mask 0x4052c0(GFP_NOWAIT|__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP) > > __alloc_pages_nodemask+0x11d/0x290 > > skb_page_frag_refill+0x68/0xf0 > > sk_page_frag_refill+0x19/0x70 > > tcp_sendmsg_locked+0x2f4/0xd10 > > tcp_sendmsg+0x29/0xa0 > > sock_sendmsg+0x30/0x40 > > sock_write_iter+0x8f/0x100 > > __vfs_write+0x10b/0x190 > > vfs_write+0xb0/0x190 > > ksys_write+0x5a/0xd0 > > do_syscall_64+0x5d/0x110 > > entry_SYSCALL_64_after_hwframe+0x44/0xa9 > > > > Signed-off-by: Muchun Song > > --- > > drivers/base/node.c | 2 ++ > > drivers/net/virtio_net.c | 3 +-- > > Is virtio-net the only dirver that requred an update? Yeah, only virtio-net needs an update. Because only it uses the skb_page_frag_refill() API. > > > fs/proc/meminfo.c | 1 + > > include/linux/mmzone.h | 1 + > > include/linux/skbuff.h | 43 ++++++++++++++++++++++++++++++++++++++-- > > kernel/exit.c | 3 +-- > > mm/page_alloc.c | 7 +++++-- > > mm/vmstat.c | 1 + > > net/core/sock.c | 8 ++++---- > > net/ipv4/tcp.c | 3 +-- > > net/xfrm/xfrm_state.c | 3 +-- > > 11 files changed, 59 insertions(+), 16 deletions(-) > > -- Yours, Muchun