net: add new socket option SO_RESERVE_MEM
authorWei Wang <weiwan@google.com>
Wed, 29 Sep 2021 17:25:11 +0000 (10:25 -0700)
committerDavid S. Miller <davem@davemloft.net>
Thu, 30 Sep 2021 12:36:46 +0000 (13:36 +0100)
commit2bb2f5fb21b0486ff69b7b4a1fe03a760527d133
tree1e1b3e094fd135390997b383ccdd38a85eecbfe0
parent4075a6a047bbb4c67a0670f4ad981cfc5ffb5c76
net: add 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.

Note:
This socket option is only available when memory cgroup is enabled and we
require this reserved memory to be charged to the user's memcg. We hope
this could avoid mis-behaving users to abused this feature to reserve a
large amount on certain sockets and cause unfairness for others.

Signed-off-by: Wei Wang <weiwan@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/sock.h
include/uapi/asm-generic/socket.h
net/core/sock.c
net/core/stream.c
net/ipv4/af_inet.c