Linux cgroups development
 help / color / mirror / Atom feed
From: Yingjie Wang <x-professor@outlook.com>
To: "netdev@vger.kernel.org" <netdev@vger.kernel.org>
Cc: David Ahern <dsahern@kernel.org>,
	Ido Schimmel <idosch@nvidia.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Michal Hocko <mhocko@kernel.org>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	Muchun Song <muchun.song@linux.dev>,
	Andrew Morton <akpm@linux-foundation.org>,
	Vladimir Davydov <vdavydov.dev@gmail.com>,
	"cgroups@vger.kernel.org" <cgroups@vger.kernel.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH net 0/3] net: account socket and multicast allocations to memcg
Date: Thu, 19 Nov 2026 15:34:34 +0000	[thread overview]
Message-ID: <cover.1795102467.git.x-professor@outlook.com> (raw)

Several allocations retained by sockets or multicast device state are
not charged to memory cgroups. A task can retain substantially more
kernel memory than its memory.max limit permits.

With the default optmem_max, an unprivileged user retaining 2,000
IPV6_2292PKTOPTIONS buffers consumed about 254 MiB of slab while a
cgroup limited to 64 MiB reported about 5.5 MiB in memory.current. In a
user and network namespace with raised multicast limits, 1,200 IPv4
memberships with 1,024 sources each retained about 85 MiB of slab while
the cgroup reported less than 1 MiB. Both were measured on the base of
this series.

Patch 1 fixes source-filter error handling before making more
allocations failable at a memcg limit. Removing a never-added source
from an any-source membership returns EADDRNOTAVAIL but changes the
empty filter to INCLUDE, so the socket stops receiving the group. The
patch restores the old mode on failure, checks device-side source
allocation errors before publishing the socket filter, and removes a
membership created by a failed source join.

Patch 2 accounts IPV6_2292PKTOPTIONS buffers and IPv4/IPv6 socket
membership and source-list allocations. It leaves sock_kmalloc()
unchanged because its other callers have different execution contexts
and charge attribution. Patch 3 accounts device source and tomb entries,
deleted IPv6 group records, and live IPv6 device groups created by
socket joins. Live groups created by automatic address configuration
keep their existing allocation policy. IPv4 keeps GFP_ATOMIC, so its
charges are forced and can temporarily exceed memory.max. IPv6 uses
GFP_KERNEL_ACCOUNT.

IPv4 device group records remain unaccounted: their allocation helper
cannot report failure and has callers with different GFP constraints.
Accounting socket memberships limits the membership-only case, but each
socket record can still pin a larger unaccounted device group when every
membership uses a different group. This series does not close that case.

The pending patch "igmp: use copy-on-write RCU updates in
ip_mc_source()"
(https://lore.kernel.org/r/20261102095312.47767-1-18983559317@163.com)
also changes the IPv4 function. It is not in this base; this series
leaves the existing in-place RCU update races to that work.

Validation on this base and the corresponding patched tree:
 - full x86_64 W=1 bzImage builds;
 - affected-object W=1 builds at each intermediate commit, plus final
   allmodconfig, i386 and CONFIG_IP_MULTICAST=n builds;
 - IPv4/IPv6 group reception changed from 4/4 to 0/4 after an invalid
   source leave on the base, and stayed 4/4 with the series;
 - valid source join/leave sequences passed, and FAILSLAB tests
   confirmed ENOBUFS with preserved filter/membership state on the
   patched kernel;
 - large option, membership and source-filter cases were constrained by
   a 64 MiB cgroup limit; small operations succeeded;
 - with delayed MLD reports and a 16 MiB cgroup limit on both kernels,
   the base completed 200,000 IPv6 join/leave operations without a
   memory.max event; the memcg OOM killer stopped the patched run after
   at least 60,000 operations;
 - no unexpected BUG, WARNING, Oops or panic in the guest consoles.

Kernel selftests were not run, and the large membership case was run
only on the patched kernel.

Patch 1 is an independent correctness fix suitable for stable. Patches 2
and 3 change charging behaviour and are marked noautosel. If you would
rather take patches 2 and 3 through net-next, I can resend them there
once patch 1 has been merged.

Yingjie Wang (3):
  net: multicast: keep source filter state when a source update fails
  net: account IPV6_2292PKTOPTIONS and multicast socket state to memcg
  net: multicast: account group and source allocations to memcg

 net/ipv4/igmp.c          | 88 ++++++++++++++++++++++++++--------------
 net/ipv4/ip_sockglue.c   | 33 ++++++++-------
 net/ipv6/ipv6_sockglue.c | 13 +++++-
 net/ipv6/mcast.c         | 50 +++++++++++++++--------
 4 files changed, 120 insertions(+), 64 deletions(-)


base-commit: e203d8a4751d48aa00eda31e3b320ba8e0d47dbf
-- 
2.43.0


             reply	other threads:[~2026-11-19 15:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 15:34 Yingjie Wang [this message]
2026-11-19 15:34 ` [PATCH net 1/3] net: multicast: keep source filter state when a source update fails Yingjie Wang
2026-11-19 15:34 ` [PATCH net 2/3] net: account IPV6_2292PKTOPTIONS and multicast socket state to memcg Yingjie Wang
2026-11-19 15:34 ` [PATCH net 3/3] net: multicast: account group and source allocations " Yingjie Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1795102467.git.x-professor@outlook.com \
    --to=x-professor@outlook.com \
    --cc=akpm@linux-foundation.org \
    --cc=cgroups@vger.kernel.org \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=vdavydov.dev@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox