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.8 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 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 412E6C433E7 for ; Sun, 11 Oct 2020 16:01:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 930E622244 for ; Sun, 11 Oct 2020 16:01:04 +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" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 930E622244 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A527F900003; Sun, 11 Oct 2020 12:01:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9DBF6900002; Sun, 11 Oct 2020 12:01:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 85DCF900003; Sun, 11 Oct 2020 12:01:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 519BF900002 for ; Sun, 11 Oct 2020 12:01:03 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id CF60F1EE6 for ; Sun, 11 Oct 2020 16:01:02 +0000 (UTC) X-FDA: 77360108364.11.shoe61_1511cd0271f3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id AA4A2180F8B86 for ; Sun, 11 Oct 2020 16:01:02 +0000 (UTC) X-HE-Tag: shoe61_1511cd0271f3 X-Filterd-Recvd-Size: 6784 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Sun, 11 Oct 2020 16:01:02 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id r10so11618820pgb.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=qRGkABpOE7mqj4OOmYxVztQy5H0VadqDvvqlqaPdS9v7M+8yn8svp32uDDWRw5VPqZ ph/Q9oOSn9bnsl4iApfe0iZ2sbPBhXipYZ3Lo5NYW6qgzgjwD04mOgS0/FL09WTTETji aPD3DJQZLuH6DGRtWlM2RyvWXtAqCu0ENgQfVdjqCIyBOsz4LHDK6vMxerebH91NPuwX DSaTBdZXv95XWrdCsxO+SgunnHTsr1H3PQ2khw0xRcfH+lXBOi/pZoQvk8Xz1n/ibWDe Ema3jOUSy3vVeeJ+bfMD08nsYmNhfHlqOG43kF1rLHMeC8z9UsX4EwXPpATbo81WpmGo /54g== X-Gm-Message-State: AOAM531GjB0x5ALLQ5CS8Bp8dDLgQszpHz8xAzqDHXIGLDKrKuV+yu6C Niq5woW7dLi+gxX3qEOq1sysZGfhEF+erTVzsqFcLg== 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" 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: 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