Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3803505pxu; Mon, 12 Oct 2020 01:15:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRm1cuRUq/fimVbfQaloxTk+tojZorxeWjZlJa8gbQoUrPvl5C90wT3i6yGTZXWH9SQMZT X-Received: by 2002:a17:906:1c50:: with SMTP id l16mr26389345ejg.144.1602490546738; Mon, 12 Oct 2020 01:15:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602490546; cv=none; d=google.com; s=arc-20160816; b=Oq1kNQEpKl8ulcceXl4o4cmzGTmiUjNFIuFdYl1bOruBg5ND1alNQSsFLijX0xATSC NrF929Mzc7R+tA6K1LjYim7cYH9KFuTaclxOlLhMQF7JJUA/njGJUDpghxRLKTNPs3hh Id822ffcXfMWQ5jUUo74lpID+VBEfISpInlrM3Lj5KAL7yBGyD7N0Q7wt/ddvTP+Z/v3 4QrJa6/URzhVZdcjJ/af+0HxcpnnvMb4Y7mzOAFkh9HlYJjyh93R1hIGUXAaWKJnnL76 nK730cqauneg5RCzyYRWdorcviTeiF7e3iReMowmpa9dVdEAHmz6SLD6ChnWw8ZJlQIW EBpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=e5VG5wK84kKrdrvCjTeGkiyRx9C2ZrwL+s1ArEKKadQ=; b=giRwLTxRB6Q5ZBWyl0oaNb41JjXjA9XNDhbNU2uKyNfHPyxi8QQLhQ0J/audUm/7Ox GqYN4eay8W8eC8CsPBOW4PQ8ihRlLhwhc+AEGhpW6APBGo6VRSl37NshNkXGQ+0pOgtI RaKf4dvF+GkbwELRHZbFQW20Xe9i6Q5QgFrkYusB01xW1gedIAJe2pVRPllLPNb76Nvn kMYg4nSAfM49o5UYKlR5oseJIPwByACmfPgE1aU6K+9Mzuu0LvLlCdgvW+C1rph0N4l0 rTbgSI24ZJXX3Za67Fas8/hPMIFtUoeQhsmXIShWoOmde/goWHyJC3exk0Q2FqLqJmBV joIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gH4UHfk7; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bd5si10334618edb.451.2020.10.12.01.15.22; Mon, 12 Oct 2020 01:15:46 -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=@google.com header.s=20161025 header.b=gH4UHfk7; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726513AbgJLHmt (ORCPT + 99 others); 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-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.