提交 eea86af6 编写于 作者: D Daniel Borkmann 提交者: David S. Miller

net: sock: adapt SOCK_MIN_RCVBUF and SOCK_MIN_SNDBUF

The current situation is that SOCK_MIN_RCVBUF is 2048 + sizeof(struct sk_buff))
while SOCK_MIN_SNDBUF is 2048. Since in both cases, skb->truesize is used for
sk_{r,w}mem_alloc accounting, we should have both sizes adjusted via defining a
TCP_SKB_MIN_TRUESIZE.

Further, as Eric Dumazet points out, the minimal skb truesize in transmit path is
SKB_TRUESIZE(2048) after commit f07d960d ("tcp: avoid frag allocation for
small frames"), and tcp_sendmsg() tries to limit skb size to half the congestion
window, meaning we try to build two skbs at minimum. Thus, having SOCK_MIN_SNDBUF
as 2048 can hit a small regression for some applications setting to low
SO_SNDBUF / SO_RCVBUF. Note that we define a TCP_SKB_MIN_TRUESIZE, because
SKB_TRUESIZE(2048) adds SKB_DATA_ALIGN(sizeof(struct skb_shared_info)), but in
case of TCP skbs, the skb_shared_info is part of the 2048 bytes allocation for
skb->head.

The minor adaption in sk_stream_moderate_sndbuf() is to silence a warning by
using a typed max macro, as similarly done in SOCK_MIN_RCVBUF occurences, that
would appear otherwise.
Suggested-by: NEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: NDaniel Borkmann <dborkman@redhat.com>
Signed-off-by: NEric Dumazet <edumazet@google.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 dc25c676
...@@ -2047,18 +2047,21 @@ static inline void sk_wake_async(struct sock *sk, int how, int band) ...@@ -2047,18 +2047,21 @@ static inline void sk_wake_async(struct sock *sk, int how, int band)
sock_wake_async(sk->sk_socket, how, band); sock_wake_async(sk->sk_socket, how, band);
} }
#define SOCK_MIN_SNDBUF 2048 /* Since sk_{r,w}mem_alloc sums skb->truesize, even a small frame might
/* * need sizeof(sk_buff) + MTU + padding, unless net driver perform copybreak.
* Since sk_rmem_alloc sums skb->truesize, even a small frame might need * Note: for send buffers, TCP works better if we can build two skbs at
* sizeof(sk_buff) + MTU + padding, unless net driver perform copybreak * minimum.
*/ */
#define SOCK_MIN_RCVBUF (2048 + sizeof(struct sk_buff)) #define TCP_SKB_MIN_TRUESIZE (2048 + sizeof(struct sk_buff))
#define SOCK_MIN_SNDBUF (TCP_SKB_MIN_TRUESIZE * 2)
#define SOCK_MIN_RCVBUF TCP_SKB_MIN_TRUESIZE
static inline void sk_stream_moderate_sndbuf(struct sock *sk) static inline void sk_stream_moderate_sndbuf(struct sock *sk)
{ {
if (!(sk->sk_userlocks & SOCK_SNDBUF_LOCK)) { if (!(sk->sk_userlocks & SOCK_SNDBUF_LOCK)) {
sk->sk_sndbuf = min(sk->sk_sndbuf, sk->sk_wmem_queued >> 1); sk->sk_sndbuf = min(sk->sk_sndbuf, sk->sk_wmem_queued >> 1);
sk->sk_sndbuf = max(sk->sk_sndbuf, SOCK_MIN_SNDBUF); sk->sk_sndbuf = max_t(u32, sk->sk_sndbuf, SOCK_MIN_SNDBUF);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册