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 X-Spam-Level: X-Spam-Status: No, score=-6.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A291AC43467 for ; Sun, 11 Oct 2020 16:01:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E3F920776 for ; Sun, 11 Oct 2020 16:01:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="wAfLQMkt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387955AbgJKQBE (ORCPT ); Sun, 11 Oct 2020 12:01:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387799AbgJKQBB (ORCPT ); Sun, 11 Oct 2020 12:01:01 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A01EC0613CE for ; Sun, 11 Oct 2020 09:01:01 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id r10so11618819pgb.10 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=aaCIZvOfR5JiWYyTcvem75vZyJmlQYIm9LGtNWi3AGdNxHVMRD04ynWduX4h0zu61J cPvSv7oCDFPB/QKMtelUHDW7QumXDcY6Z//shO6+wUTJkadM0oCWbRJCeEzWwKVCa+At i3XOcRwztuRLvue8tuvDbSiYet+bOrMXR9u2ynchIK1zPNfJ6jlXRmgNuwOSWi9jTXuj 2OgDoQLQ3b1rZQLXtEpgxCrzTXBKdKlwHnOWyzmNggW7NV0i6CxsGHXFKQVkVL+A5sCU DDrEaphDhmfPZ0kizkPaASEXNR0c+On/p0g2r3zqHoJZJXtXtOu4QnW56s62ubu9Hwb5 lVHQ== X-Gm-Message-State: AOAM5322roSbUoxPFjUIajeoeoOEjhwLZcVPnLvQB2iVmrxZibFaxhE8 w8mLm2yf/P+QLsp9kRTV77nVXmxhpKSuF5DadtKzAQ== X-Google-Smtp-Source: ABdhPJx+35KZugbZDuYuwDppg2jtVfNyVvGyDLkEevimfuHCyJp9HQAuTr44pyJ85kH6+5R+ijtE2LOzbIG0aYnD3qI= 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: netdev@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