selftests/net: add SO_RESERVE_MEM test
Subsystems (3)
Eric Dumazet
maintainerPATCH v3 1/1 selftests/net: add SO_RESERVE_MEM test
Add a kselftest suite covering SO_RESERVE_MEM behavior:
- Reject unsupported socket types (UDP/SOCK_DGRAM, UNIX/SOCK_STREAM, SOCK_RAW, MPTCP) with EOPNOTSUPP, for both zero and non-zero values.
- Validate bounds (negative values and values > SZ_1G return EINVAL).
- Verify reserve adjustments (increase, decrease, page rounding, and reset to 0) and corresponding sk_meminfo[SK_MEMINFO_FWD_ALLOC] changes via getsockopt(SO_MEMINFO).
- Exercise cgroup v2 memory.max enforcement returning ENOMEM when the requested reservation exceeds the cgroup limit.
- Verify that a child socket returned by accept() starts with a 0 reserve even when its parent listener configured a non-zero SO_RESERVE_MEM.
- Verify reserve retention across TCP send/receive/ACK cycles.
Each test runs in private mount and network namespaces. cgroup2 is mounted on a private tmpfs, so nothing is left behind in the host filesystem. The test process is moved to a dedicated leaf cgroup, and back to its original cgroup on teardown. The memory controller is enabled in the root of the hierarchy if needed, and left enabled like selftests/cgroup do, as disabling it could break other users.
Also enable CONFIG_CGROUPS=y and CONFIG_MEMCG=y in tools/testing/selftests/net/config.
---
v3: (net-next submission)
- run in a private netns, bring lo up
- mount cgroup2 on a private tmpfs, check MS_PRIVATE remount
- move back to the original cgroup instead of the hierarchy root (Sashiko)
- never disable the memory controller (Sashiko)
- accept EPERM/EACCES for SOCK_RAW creation (Sashiko)
- also check val == 0 on non-TCP sockets (Wei)
- wait for WMEM_QUEUED == 0 and FWD_ALLOC >= reserve in one snapshot (Sashiko)
v2: https://lore.kernel.org/netdev/[email protected]/
tools/testing/selftests/net/.gitignore | 1 + tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/config | 2 + tools/testing/selftests/net/so_reserve_mem.c | 448 +++++++++++++++++++ 4 files changed, 452 insertions(+) create mode 100644 tools/testing/selftests/net/so_reserve_mem.c
tools/testing/selftests/net/.gitignore +1 -0
@@ -41,6 +41,7 @@ skf_net_off socket so_incoming_cpu so_netns_cookie +so_reserve_mem so_rcv_listener stress_reuseport_listen tap
tools/testing/selftests/net/Makefile +1 -0
@@ -197,6 +197,7 @@ TEST_GEN_PROGS := \ sk_connect_zero_addr \ sk_so_peek_off \ so_incoming_cpu \ + so_reserve_mem \ tap \ tcp_port_share \ tls \
tools/testing/selftests/net/config +2 -0
@@ -7,6 +7,7 @@ CONFIG_BRIDGE_VLAN_FILTERING=y CONFIG_CAN=m CONFIG_CAN_DEV=m CONFIG_CAN_VXCAN=m +CONFIG_CGROUPS=y CONFIG_CRYPTO_ARIA=y CONFIG_CRYPTO_CHACHA20POLY1305=m CONFIG_CRYPTO_SHA1=y
@@ -61,6 +62,7 @@ CONFIG_L2TP_V3=y CONFIG_MACSEC=m CONFIG_MACVLAN=y CONFIG_MACVTAP=y +CONFIG_MEMCG=y CONFIG_MPLS=y CONFIG_MPLS_IPTUNNEL=m CONFIG_MPLS_ROUTING=m
tools/testing/selftests/net/so_reserve_mem.c new file +448 -0
448 lines not on this page · raw message
Signature · 1 line
2.53.0
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 14 lines · On Thu, 1 Oct 2026 21:21:37 +0200 you wrote:
Add a kselftest suite covering
SO_RESERVE_MEMbehavior:
- Reject unsupported socket types (UDP/SOCK_DGRAM, UNIX/SOCK_STREAM,SOCK_RAW, MPTCP) with EOPNOTSUPP, for both zero and non-zero values.
- Validate bounds (negative values and values >SZ_1Greturn EINVAL).
- Verify reserve adjustments (increase, decrease, page rounding, and reset to 0) and corresponding sk_meminfo[SK_MEMINFO_FWD_ALLOC] changes viagetsockopt(SO_MEMINFO).
- Exercise cgroup v2 memory.max enforcement returning ENOMEM when the requested reservation exceeds the cgroup limit.
- Verify that a child socket returned byaccept()starts with a 0 reserve even when its parent listener configured a non-zeroSO_RESERVE_MEM.
- Verify reserve retention across TCP send/receive/ACK cycles.
Quoted 1 line
[...]
Here is the summary with links:
- [v3,net-next] selftests/net: add SO_RESERVE_MEM test
https://git.kernel.org/netdev/net-next/c/095dc989f002
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html