Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4647757pxu; Tue, 13 Oct 2020 03:54:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuqXwhcQ5Z3PcYNWr/+Yz/XAtWVy7Xse+lRcgIkf8d8u2zoEYlvO9Tx8JitH/4L31eDbb0 X-Received: by 2002:a17:906:e2d7:: with SMTP id gr23mr33230207ejb.360.1602586467460; Tue, 13 Oct 2020 03:54:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602586467; cv=none; d=google.com; s=arc-20160816; b=KVqFUUK880JxrqGGiVChde5gQ37xa5BHZrBzebyJvffKMRZC2f5+hFNOmJrouj/5jT DU6gGI+NDaHX72nNhyGf1UigL1cED7FHJ7JI17Jvzgh8a3iQw2IHui51aIqCnH49Rav5 /vjEqZBs5K3xaWd5+suyrU040vwmtt/IP1zxjJIqHEGh642qYgZ/iwlgUuq+ItgNyWMH wbM46rsbL7n5XjCVHkreihOHyDRUkTO8crp8G3bjTSdIcw5AMwAFeefSkzeBPtHUMMLP Xus0hennJ+Gju8kh9TQFKy1Caj8a1q0pX14XIUbt9doDi4pYawyDYZ2ZH1R5TLESTMgT GJMQ== 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=h+F8apYj2Plr5dGtsp4Sn87icM0Gt/ZYiDUCGu5uXTA=; b=YFICIqWszBb9VO2Z0+qAhwnw/nKoyUxmyFvN6+plK7eNSPh6gPls/XThmhuLJlOoH9 u0ZtRPVrMhlq9ifGz8cWMsN/haq5QFLQ+tzIVW7kii7gXEmsxf7Iqhf5UVywvdsxxydk zaQZ9eKUX2cFPSUotaj2CRw5em8T4Y7PspKfGzVfxtOiZCXlev6wJ3kbrmDiF9lzW52j Nou58BUbL4LOyobhp6wa5JmXB0bRYYvTah6mvZbD/UFIe+4xqR/7RTsf8enJP4zc6hX0 j18ecEgWherSlgGLo9ulMj9JVlGrLo/dZr7g7QQqKqSr9t3ChJHAJ+WjVoA7oa6HQ0AF E1iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sYImlSuW; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z30si14329353edi.478.2020.10.13.03.54.04; Tue, 13 Oct 2020 03:54:27 -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=@gmail.com header.s=20161025 header.b=sYImlSuW; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730873AbgJLVrE (ORCPT + 99 others); Mon, 12 Oct 2020 17:47:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730022AbgJLVrD (ORCPT ); Mon, 12 Oct 2020 17:47:03 -0400 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A060CC0613D0; Mon, 12 Oct 2020 14:47:03 -0700 (PDT) Received: by mail-io1-xd44.google.com with SMTP id l8so19172577ioh.11; Mon, 12 Oct 2020 14:47:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=h+F8apYj2Plr5dGtsp4Sn87icM0Gt/ZYiDUCGu5uXTA=; b=sYImlSuWHY/0f/jfbP/5+gVgcuqOAtQjUMnXMHXED5umjtE3LPslOSL7etCXMHOofP OCpa+2Sz42CDxUNykjUuDhWyt5vFu1VQ2q4mLxaSnkvM0BeJYsRX2yVIf69oRTE9T67o HRSY3XMYMW81cX286ZryHP3m3P/6kZ5ItQS7iUkubm19T+mUJGaXaGWyUNZdJtMqQgmL zSpO8tHo17YhrEljp7eptvHzAhmOHFf/hJvg/N0IaJaR5HkeDupWi3U14lijEclKn9qq MEwXGSOFD9iX8EgjReyyv2j7VDxt6rk3rEUTRz5EOYXiuvy4JelYIs/WB2F89KX73aVI Mp9w== 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=h+F8apYj2Plr5dGtsp4Sn87icM0Gt/ZYiDUCGu5uXTA=; b=bw4nJYFsH3L6LXwBI0dvBAu3GG/YkGgk2gSymw9Jm2G8SbKXb0pDY69YJSD3b0XObx 7Q79hcTiYmydzI+UJa7vP95O1ZYRHwQNGeTQ3ak6iSQkbpkZGJ8C9R4hyUgP9X/rJGtK XrcA4V4GVIWgv9rg2fneiEijdkQhejhtWD/GnEQrqt1+oPgNoeTFDXgu2uY7hCtmk6AS Q8WrM4KMdHzLKRAobosryi60chagneE+Uedi3xrAi3uITKErio06oFfyd25WnRJdpStv gQuFmpUCrKcDkVOLrZcJrR38TphVDNmsZelza0YEel1QJPDoSUqrhNiXL7ZxiAwkNkmz uTAQ== X-Gm-Message-State: AOAM532ts66YoeTI3X4kC+fMw0c/khNRe5tnLbHMVznDUFdh0nqzbbvB dNg/QN1JjD3RwT3SFKGzHqgEh9oPqhGqeL1KuIo= X-Received: by 2002:a02:94cd:: with SMTP id x71mr20173978jah.124.1602539222864; Mon, 12 Oct 2020 14:47:02 -0700 (PDT) MIME-Version: 1.0 References: <20201010103854.66746-1-songmuchun@bytedance.com> In-Reply-To: From: Cong Wang Date: Mon, 12 Oct 2020 14:46:51 -0700 Message-ID: Subject: Re: [External] Re: [PATCH] mm: proc: add Sock to /proc/meminfo To: Muchun Song Cc: Greg KH , rafael@kernel.org, "Michael S. Tsirkin" , Jason Wang , David Miller , Jakub Kicinski , Alexey Dobriyan , Andrew Morton , Eric Dumazet , 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 , decui@microsoft.com, 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 Sun, Oct 11, 2020 at 9:22 PM 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 Interesting, we already have a few counters related to socket buffers, are you saying these are not accounted in /proc/meminfo either? If yes, why are page frags so special here? If not, they are more important than page frags, so you probably want to deal with them first. > 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. It looks like actually the socket page frag is already accounted, for example, the tcp_sendmsg_locked(): copy =3D min_t(int, copy, pfrag->size - pfrag->offs= et); if (!sk_wmem_schedule(sk, copy)) goto wait_for_memory; > > > > > > 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(). How is skb_page_frag_refill() possibly paired with __skb_frag_unref()? > 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. skb_page_frag_refill() is called on frags not within an skb, for instance, sk_page_frag_refill() uses it for a per-socket or per-process page frag. But, __skb_frag_unref() is specifically used for skb frags, which are supposed to be filled by skb_fill_page_desc() (page is allocated by driver)= . They are different things you are mixing them up, which looks clearly wrong or at least misleading. Thanks.