Commit e2142825 authored by Menglong Dong's avatar Menglong Dong Committed by David S. Miller

net: tcp: send zero-window ACK when no memory

For now, skb will be dropped when no memory, which makes client keep
retrans util timeout and it's not friendly to the users.

In this patch, we reply an ACK with zero-window in this case to update
the snd_wnd of the sender to 0. Therefore, the sender won't timeout the
connection and will probe the zero-window with the retransmits.
Signed-off-by: default avatarMenglong Dong <imagedong@tencent.com>
Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3e6860ec
...@@ -164,7 +164,8 @@ enum inet_csk_ack_state_t { ...@@ -164,7 +164,8 @@ enum inet_csk_ack_state_t {
ICSK_ACK_TIMER = 2, ICSK_ACK_TIMER = 2,
ICSK_ACK_PUSHED = 4, ICSK_ACK_PUSHED = 4,
ICSK_ACK_PUSHED2 = 8, ICSK_ACK_PUSHED2 = 8,
ICSK_ACK_NOW = 16 /* Send the next ACK immediately (once) */ ICSK_ACK_NOW = 16, /* Send the next ACK immediately (once) */
ICSK_ACK_NOMEM = 32,
}; };
void inet_csk_init_xmit_timers(struct sock *sk, void inet_csk_init_xmit_timers(struct sock *sk,
......
...@@ -5059,13 +5059,19 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb) ...@@ -5059,13 +5059,19 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
/* Ok. In sequence. In window. */ /* Ok. In sequence. In window. */
queue_and_out: queue_and_out:
if (skb_queue_len(&sk->sk_receive_queue) == 0) if (tcp_try_rmem_schedule(sk, skb, skb->truesize)) {
sk_forced_mem_schedule(sk, skb->truesize); /* TODO: maybe ratelimit these WIN 0 ACK ? */
else if (tcp_try_rmem_schedule(sk, skb, skb->truesize)) { inet_csk(sk)->icsk_ack.pending |=
reason = SKB_DROP_REASON_PROTO_MEM; (ICSK_ACK_NOMEM | ICSK_ACK_NOW);
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPRCVQDROP); inet_csk_schedule_ack(sk);
sk->sk_data_ready(sk); sk->sk_data_ready(sk);
goto drop;
if (skb_queue_len(&sk->sk_receive_queue)) {
reason = SKB_DROP_REASON_PROTO_MEM;
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPRCVQDROP);
goto drop;
}
sk_forced_mem_schedule(sk, skb->truesize);
} }
eaten = tcp_queue_rcv(sk, skb, &fragstolen); eaten = tcp_queue_rcv(sk, skb, &fragstolen);
......
...@@ -257,11 +257,19 @@ EXPORT_SYMBOL(tcp_select_initial_window); ...@@ -257,11 +257,19 @@ EXPORT_SYMBOL(tcp_select_initial_window);
static u16 tcp_select_window(struct sock *sk) static u16 tcp_select_window(struct sock *sk)
{ {
struct tcp_sock *tp = tcp_sk(sk); struct tcp_sock *tp = tcp_sk(sk);
u32 old_win = tp->rcv_wnd;
u32 cur_win = tcp_receive_window(tp);
u32 new_win = __tcp_select_window(sk);
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
u32 old_win = tp->rcv_wnd;
u32 cur_win, new_win;
/* Make the window 0 if we failed to queue the data because we
* are out of memory. The window is temporary, so we don't store
* it on the socket.
*/
if (unlikely(inet_csk(sk)->icsk_ack.pending & ICSK_ACK_NOMEM))
return 0;
cur_win = tcp_receive_window(tp);
new_win = __tcp_select_window(sk);
if (new_win < cur_win) { if (new_win < cur_win) {
/* Danger Will Robinson! /* Danger Will Robinson!
* Don't update rcv_wup/rcv_wnd here or else * Don't update rcv_wup/rcv_wnd here or else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment