Skip to content

net: add new socket option SO_RESERVE_MEM

Wei Wang netdev 3 versions – Applied

Status from this message: This series was applied to netdev/net-next.git (refs/heads/master):

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 0 repliesApplied 3/3
  2. v23 patches 0 repliesSuperseded
  3. v13 patches 2 repliesSuperseded

Changes in v3 from the cover letter

- Added description for new field added in struct sock in patch 1 Change since v1:
- Added performance stats in cover letter and rebased

Patches in v3 All 3 applied

#Subject and filesSizeRepliesApplied
1/3net: add new socket option SO_RESERVE_MEMinclude/net/sock.h include/uapi/asm-generic/socket.h net/core/sock.c +2 more+112 -70 repliesApplied
2/3tcp: adjust sndbuf according to sk_reserved_meminclude/net/sock.h net/ipv4/tcp_input.c+13 -20 repliesApplied
3/3tcp: adjust rcv_ssthresh according to sk_reserved_meminclude/net/tcp.h net/ipv4/tcp_input.c net/ipv4/tcp_output.c+22 -40 repliesApplied

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH v3 net-next 0/3] net: add new socket option SO_RESERVE_MEM

This patch series introduces a new socket option SO_RESERVE_MEM. This socket option provides a mechanism for users to reserve a certain amount of memory for the socket to use. When this option is set, kernel charges the user specified amount of memory to memcg, as well as sk_forward_alloc. This amount of memory is not reclaimable and is available in sk_forward_alloc for this socket.
With this socket option set, the networking stack spends less cycles doing forward alloc and reclaim, which should lead to better system performance, with the cost of an amount of pre-allocated and unreclaimable memory, even under memory pressure.
With a tcp_stream test with 10 flows running on a simulated 100ms RTT link, I can see the cycles spent in __sk_mem_raise_allocated() dropping by ~0.02%. Not a whole lot, since we already have logic in sk_mem_uncharge() to only reclaim 1MB when sk_forward_alloc has more than 2MB free space. But on a system suffering memory pressure constently, the savings should be more.

The first patch is the implementation of this socket option. The following 2 patches change the tcp stack to make use of this reserved memory when under memory pressure. This makes the tcp stack behavior more flexible when under memory pressure, and provides a way for user to control the distribution of the memory among its sockets. With a TCP connection on a simulated 100ms RTT link, the default throughput under memory pressure is ~500Kbps. With SO_RESERVE_MEM set to 100KB, the throughput under memory pressure goes up to ~3.5Mbps.

Change since v2:
- Added description for new field added in struct sock in patch 1 Change since v1:
- Added performance stats in cover letter and rebased

Wei Wang (3):
net: add new socket option SO_RESERVE_MEM
tcp: adjust sndbuf according to sk_reserved_mem
tcp: adjust rcv_ssthresh according to sk_reserved_mem

 include/net/sock.h                | 45 +++++++++++++++++---
 include/net/tcp.h                 | 11 +++++
 include/uapi/asm-generic/socket.h |  2 +
 net/core/sock.c                   | 69 +++++++++++++++++++++++++++++++
 net/core/stream.c                 |  2 +-
 net/ipv4/af_inet.c                |  2 +-
 net/ipv4/tcp_input.c              | 26 ++++++++++--
 net/ipv4/tcp_output.c             |  3 +-
 8 files changed, 147 insertions(+), 13 deletions(-)
Signature · 1 line
2.33.0.685.g46640cef36-goog