tcp: add receive queue awareness in tcp_rcv_space_adjust()
[ Upstream commit ea33537d82 ]
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 <edumazet@google.com>
Reviewed-by: Wei Wang <weiwan@google.com>
Link: https://patch.msgid.link/20250513193919.1089692-5-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
454a7a89b9
commit
e6854134ea
@@ -340,7 +340,7 @@ struct tcp_sock {
|
||||
} rcv_rtt_est;
|
||||
/* Receiver queue space */
|
||||
struct {
|
||||
u32 space;
|
||||
int space;
|
||||
u32 seq;
|
||||
u64 time;
|
||||
} rcvq_space;
|
||||
|
||||
@@ -748,8 +748,7 @@ static inline void tcp_rcv_rtt_measure_ts(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);
|
||||
|
||||
@@ -760,6 +759,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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user