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=-11.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 996CDC433DF for ; Mon, 12 Oct 2020 07:42:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3436020E65 for ; Mon, 12 Oct 2020 07:42:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gH4UHfk7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726974AbgJLHmt (ORCPT ); Mon, 12 Oct 2020 03:42:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726098AbgJLHms (ORCPT ); Mon, 12 Oct 2020 03:42:48 -0400 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5891BC0613CE for ; Mon, 12 Oct 2020 00:42:48 -0700 (PDT) Received: by mail-io1-xd42.google.com with SMTP id g7so16598130iov.13 for ; Mon, 12 Oct 2020 00:42:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=e5VG5wK84kKrdrvCjTeGkiyRx9C2ZrwL+s1ArEKKadQ=; b=gH4UHfk7+EsDB0g7VarNb/ZYNO10+OttrKc0yoGw5c7k6ayVzTN/IKevjdkPL+v3+3 eh/Q+AOKbMEQKAQQakARO/UePJJMAtw0QYem95+ENlywE4f8Fx0Y3gMADb1DD7NTEWh0 6XbiQVPMxB++vOsqCMibc/L8pVSSEvfiYVfzwVyX6OEscOdjkRbqtwtFr7bIybePTi39 bIqPGRAqYvEcDJbc6QN92YPgTxwP/KhzU/XrsucqzJjAIIJws1Wmc2o7hiEsAXpXJYtu p3FFHPw53qWv8A0lKhKrMj9OuhINBpS9A81PZnFFCWd6tId/PSoAspOjwwSs+fBWTHDi mTPg== 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:content-transfer-encoding; bh=e5VG5wK84kKrdrvCjTeGkiyRx9C2ZrwL+s1ArEKKadQ=; b=MJfgebdV5ca7biS4lV0fEcx9h6nvoSmT5uNfOgngurD0RIaiFNRsdqzYGXxT/ypKGW pEVVxyvzLkVhv1otFhsS7JuBQb0C9tHh0x/jl6iEU3RrhXbDkH6dEAKTjlWd5hZgUty+ 2XImPz0MrAxg9Yswu7vPVFmsNfCU+0m11TATTvQM9j3ZMxIboDtiI3Vr9hntfK1uiKNc OltqpkLK9nItOus872dy6sinDhwhOp46ym6mvBYNgqa2PA2fwgoOG3/C+X+QH7k8fuxg jehWGXYWIHpxtL3Gj7gOaj3bR5fw6thbZrMogG8nlwWxp5xY3+MCGkkI7u24q3961mqf MniA== X-Gm-Message-State: AOAM533JJV70y55IcaMTYQVC7/VXxAAHiy7z0pGkshzkkJq1KpEK1JAO V37YgiPWds90TrIXpdXK5TblGccRKGnGZPqffx4Lzg== X-Google-Smtp-Source: ABdhPJyLAEKXb/V0z8Sc1yAftRlthOIMiopejO4oj5Qv8BbgPH+8hwnRpR93RKKR1Wp3B/awtoePH7Xh2/hLRZBaHsQ= X-Received: by 2002:a02:7350:: with SMTP id a16mr19138927jae.53.1602488567382; Mon, 12 Oct 2020 00:42:47 -0700 (PDT) MIME-Version: 1.0 References: <20201010103854.66746-1-songmuchun@bytedance.com> In-Reply-To: From: Eric Dumazet Date: Mon, 12 Oct 2020 09:42:37 +0200 Message-ID: Subject: Re: [External] Re: [PATCH] mm: proc: add Sock to /proc/meminfo To: Muchun Song Cc: Cong Wang , Greg KH , rafael@kernel.org, "Michael S. Tsirkin" , Jason Wang , David Miller , Jakub Kicinski , Alexey Dobriyan , Andrew Morton , Alexey Kuznetsov , Hideaki YOSHIFUJI , Steffen Klassert , Herbert Xu , Shakeel Butt , Will Deacon , Michal Hocko , Roman Gushchin , Neil Brown , rppt@kernel.org, Sami Tolvanen , "Kirill A. Shutemov" , Feng Tang , Paolo Abeni , Willem de Bruijn , Randy Dunlap , Florian Westphal , gustavoars@kernel.org, Pablo Neira Ayuso , Dexuan Cui , Jakub Sitnicki , Peter Zijlstra , Christian Brauner , "Eric W. Biederman" , Thomas Gleixner , dave@stgolabs.net, Michel Lespinasse , Jann Horn , chenqiwu@xiaomi.com, christophe.leroy@c-s.fr, Minchan Kim , Martin KaFai Lau , Alexei Starovoitov , Daniel Borkmann , Miaohe Lin , Kees Cook , LKML , virtualization@lists.linux-foundation.org, Linux Kernel Network Developers , linux-fsdevel , linux-mm Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 12, 2020 at 6:22 AM Muchun Song wrot= e: > > On Mon, Oct 12, 2020 at 2:39 AM Cong Wang wrot= e: > > > > On Sat, Oct 10, 2020 at 3:39 AM Muchun Song = wrote: > > > > > > The amount of memory allocated to sockets buffer can become significa= nt. > > > However, we do not display the amount of memory consumed by sockets > > > buffer. In this case, knowing where the memory is consumed by the ker= nel > > > > We do it via `ss -m`. Is it not sufficient? And if not, why not adding = it there > > rather than /proc/meminfo? > > If the system has little free memory, we can know where the memory is via > /proc/meminfo. If a lot of memory is consumed by socket buffer, we cannot > know it when the Sock is not shown in the /proc/meminfo. If the unaware u= ser > can't think of the socket buffer, naturally they will not `ss -m`. The > end result > is that we still don=E2=80=99t know where the memory is consumed. And we = add the > Sock to the /proc/meminfo just like the memcg does('sock' item in the cgr= oup > v2 memory.stat). So I think that adding to /proc/meminfo is sufficient. > > > > > > static inline void __skb_frag_unref(skb_frag_t *frag) > > > { > > > - put_page(skb_frag_page(frag)); > > > + struct page *page =3D skb_frag_page(frag); > > > + > > > + if (put_page_testzero(page)) { > > > + dec_sock_node_page_state(page); > > > + __put_page(page); > > > + } > > > } > > > > You mix socket page frag with skb frag at least, not sure this is exact= ly > > what you want, because clearly skb page frags are frequently used > > by network drivers rather than sockets. > > > > Also, which one matches this dec_sock_node_page_state()? Clearly > > not skb_fill_page_desc() or __skb_frag_ref(). > > Yeah, we call inc_sock_node_page_state() in the skb_page_frag_refill(). > So if someone gets the page returned by skb_page_frag_refill(), it must > put the page via __skb_frag_unref()/skb_frag_unref(). We use PG_private > to indicate that we need to dec the node page state when the refcount of > page reaches zero. > Pages can be transferred from pipe to socket, socket to pipe (splice() and zerocopy friends...) If you want to track TCP memory allocations, you always can look at /proc/net/sockstat, without adding yet another expensive memory accounting. 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=-11.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 3D3E5C43457 for ; Mon, 12 Oct 2020 07:42:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 810942145D for ; Mon, 12 Oct 2020 07:42:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gH4UHfk7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 810942145D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B7CE9900003; Mon, 12 Oct 2020 03:42:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B05E1900002; Mon, 12 Oct 2020 03:42:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9CE10900003; Mon, 12 Oct 2020 03:42:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0235.hostedemail.com [216.40.44.235]) by kanga.kvack.org (Postfix) with ESMTP id 6C386900002 for ; Mon, 12 Oct 2020 03:42:49 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id EEA4E3626 for ; Mon, 12 Oct 2020 07:42:48 +0000 (UTC) X-FDA: 77362481616.05.boat98_2b11d39271f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id CCBF81801BB7B for ; Mon, 12 Oct 2020 07:42:48 +0000 (UTC) X-HE-Tag: boat98_2b11d39271f8 X-Filterd-Recvd-Size: 7122 Received: from mail-io1-f66.google.com (mail-io1-f66.google.com [209.85.166.66]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Mon, 12 Oct 2020 07:42:48 +0000 (UTC) Received: by mail-io1-f66.google.com with SMTP id d20so16668504iop.10 for ; Mon, 12 Oct 2020 00:42:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=e5VG5wK84kKrdrvCjTeGkiyRx9C2ZrwL+s1ArEKKadQ=; b=gH4UHfk7+EsDB0g7VarNb/ZYNO10+OttrKc0yoGw5c7k6ayVzTN/IKevjdkPL+v3+3 eh/Q+AOKbMEQKAQQakARO/UePJJMAtw0QYem95+ENlywE4f8Fx0Y3gMADb1DD7NTEWh0 6XbiQVPMxB++vOsqCMibc/L8pVSSEvfiYVfzwVyX6OEscOdjkRbqtwtFr7bIybePTi39 bIqPGRAqYvEcDJbc6QN92YPgTxwP/KhzU/XrsucqzJjAIIJws1Wmc2o7hiEsAXpXJYtu p3FFHPw53qWv8A0lKhKrMj9OuhINBpS9A81PZnFFCWd6tId/PSoAspOjwwSs+fBWTHDi mTPg== 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:content-transfer-encoding; bh=e5VG5wK84kKrdrvCjTeGkiyRx9C2ZrwL+s1ArEKKadQ=; b=C7YhJcVxPrAf73vSj+orE9d3Q7WAI+GoEvztAeRQ++bCSxdwBTykwav3yVS/Pt5Ugm a7oXcTCDNgb3qphfxB5aEyauOtFts7LhEI+PVgVxp7HEB5Ab7jupKZkjbMVfIi6OxkDc K2VzBJKRFlPnVKuVLcBrq4u8albE+UPVKDiLCMP3md7WDkmeriJp5T334rGd+BGERy8K 5TnBI6jeVnk2It5i8OTjSokVT0a7SmnL9in+d6LRLnTIHbpw+CBW4l3vIhLjm+0zoAmD NFb31J+PrH4idzAVIWzva6QgWaQ0av7AdDLXJdbVyoa+ghZnz9VjBuQ6VgCwI2lM2Jl2 XhAA== X-Gm-Message-State: AOAM533Q+WDC4ToGFuiyjUMWopcjQwv0N63oMwC+snXe+15+stIs3Olo ATX4pO4bzPVc8L0s8EgwiX6wv9bkBe7rOMoYNW80NQ== X-Google-Smtp-Source: ABdhPJyLAEKXb/V0z8Sc1yAftRlthOIMiopejO4oj5Qv8BbgPH+8hwnRpR93RKKR1Wp3B/awtoePH7Xh2/hLRZBaHsQ= X-Received: by 2002:a02:7350:: with SMTP id a16mr19138927jae.53.1602488567382; Mon, 12 Oct 2020 00:42:47 -0700 (PDT) MIME-Version: 1.0 References: <20201010103854.66746-1-songmuchun@bytedance.com> In-Reply-To: From: Eric Dumazet Date: Mon, 12 Oct 2020 09:42:37 +0200 Message-ID: Subject: Re: [External] Re: [PATCH] mm: proc: add Sock to /proc/meminfo To: Muchun Song Cc: Cong Wang , Greg KH , rafael@kernel.org, "Michael S. Tsirkin" , Jason Wang , David Miller , Jakub Kicinski , Alexey Dobriyan , Andrew Morton , Alexey Kuznetsov , Hideaki YOSHIFUJI , Steffen Klassert , Herbert Xu , Shakeel Butt , Will Deacon , Michal Hocko , Roman Gushchin , Neil Brown , rppt@kernel.org, Sami Tolvanen , "Kirill A. Shutemov" , Feng Tang , Paolo Abeni , Willem de Bruijn , Randy Dunlap , Florian Westphal , gustavoars@kernel.org, Pablo Neira Ayuso , Dexuan Cui , Jakub Sitnicki , Peter Zijlstra , Christian Brauner , "Eric W. Biederman" , Thomas Gleixner , dave@stgolabs.net, Michel Lespinasse , Jann Horn , chenqiwu@xiaomi.com, christophe.leroy@c-s.fr, Minchan Kim , Martin KaFai Lau , Alexei Starovoitov , Daniel Borkmann , Miaohe Lin , Kees Cook , LKML , virtualization@lists.linux-foundation.org, Linux Kernel Network Developers , linux-fsdevel , linux-mm Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 Mon, Oct 12, 2020 at 6:22 AM Muchun Song wrot= e: > > On Mon, Oct 12, 2020 at 2:39 AM Cong Wang wrot= e: > > > > On Sat, Oct 10, 2020 at 3:39 AM Muchun Song = wrote: > > > > > > The amount of memory allocated to sockets buffer can become significa= nt. > > > However, we do not display the amount of memory consumed by sockets > > > buffer. In this case, knowing where the memory is consumed by the ker= nel > > > > We do it via `ss -m`. Is it not sufficient? And if not, why not adding = it there > > rather than /proc/meminfo? > > If the system has little free memory, we can know where the memory is via > /proc/meminfo. If a lot of memory is consumed by socket buffer, we cannot > know it when the Sock is not shown in the /proc/meminfo. If the unaware u= ser > can't think of the socket buffer, naturally they will not `ss -m`. The > end result > is that we still don=E2=80=99t know where the memory is consumed. And we = add the > Sock to the /proc/meminfo just like the memcg does('sock' item in the cgr= oup > v2 memory.stat). So I think that adding to /proc/meminfo is sufficient. > > > > > > static inline void __skb_frag_unref(skb_frag_t *frag) > > > { > > > - put_page(skb_frag_page(frag)); > > > + struct page *page =3D skb_frag_page(frag); > > > + > > > + if (put_page_testzero(page)) { > > > + dec_sock_node_page_state(page); > > > + __put_page(page); > > > + } > > > } > > > > You mix socket page frag with skb frag at least, not sure this is exact= ly > > what you want, because clearly skb page frags are frequently used > > by network drivers rather than sockets. > > > > Also, which one matches this dec_sock_node_page_state()? Clearly > > not skb_fill_page_desc() or __skb_frag_ref(). > > Yeah, we call inc_sock_node_page_state() in the skb_page_frag_refill(). > So if someone gets the page returned by skb_page_frag_refill(), it must > put the page via __skb_frag_unref()/skb_frag_unref(). We use PG_private > to indicate that we need to dec the node page state when the refcount of > page reaches zero. > Pages can be transferred from pipe to socket, socket to pipe (splice() and zerocopy friends...) If you want to track TCP memory allocations, you always can look at /proc/net/sockstat, without adding yet another expensive memory accounting.