diff options
| author | Eric Dumazet <[email protected]> | 2025-05-13 19:39:12 +0000 |
|---|---|---|
| committer | Jakub Kicinski <[email protected]> | 2025-05-15 18:30:08 +0000 |
| commit | ea33537d82921e71f852ea2ed985acc562125efe (patch) | |
| tree | b7bd20c601e5b232f8a9f154ffb5efa86342c89d /net/ipv4/tcp_input.c | |
| parent | tcp: adjust rcvbuf in presence of reorders (diff) | |
| download | kernel-ea33537d82921e71f852ea2ed985acc562125efe.tar.gz kernel-ea33537d82921e71f852ea2ed985acc562125efe.zip | |
tcp: add receive queue awareness in tcp_rcv_space_adjust()
If the application can not drain fast enough a TCP socket queue,
tcp_rcv_space_adjust() can overestimate tp->rcvq_space.space.
Then sk->sk_rcvbuf can grow and hit tcp_rmem[2] for no good reason.
Fix this by taking into acount the number of available bytes.
Keeping sk->sk_rcvbuf at the right size allows better cache efficiency.
Signed-off-by: Eric Dumazet <[email protected]>
Reviewed-by: Wei Wang <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
Diffstat (limited to 'net/ipv4/tcp_input.c')
| -rw-r--r-- | net/ipv4/tcp_input.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index f799200db264..5d64a6ecfc8f 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -780,8 +780,7 @@ static void tcp_rcvbuf_grow(struct sock *sk) void tcp_rcv_space_adjust(struct sock *sk) { struct tcp_sock *tp = tcp_sk(sk); - u32 copied; - int time; + int time, inq, copied; trace_tcp_rcv_space_adjust(sk); @@ -792,6 +791,9 @@ void tcp_rcv_space_adjust(struct sock *sk) /* Number of bytes copied to user in last RTT */ copied = tp->copied_seq - tp->rcvq_space.seq; + /* Number of bytes in receive queue. */ + inq = tp->rcv_nxt - tp->copied_seq; + copied -= inq; if (copied <= tp->rcvq_space.space) goto new_measure; |
