Commit fa76ce73 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

inet: get rid of central tcp/dccp listener timer

One of the major issue for TCP is the SYNACK rtx handling,
done by inet_csk_reqsk_queue_prune(), fired by the keepalive
timer of a TCP_LISTEN socket.

This function runs for awful long times, with socket lock held,
meaning that other cpus needing this lock have to spin for hundred of ms.

SYNACK are sent in huge bursts, likely to cause severe drops anyway.

This model was OK 15 years ago when memory was very tight.

We now can afford to have a timer per request sock.

Timer invocations no longer need to lock the listener,
and can be run from all cpus in parallel.

With following patch increasing somaxconn width to 32 bits,
I tested a listener with more than 4 million active request sockets,
and a steady SYNFLOOD of ~200,000 SYN per second.
Host was sending ~830,000 SYNACK per second.

This is ~100 times more what we could achieve before this patch.

Later, we will get rid of the listener hash and use ehash instead.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 52452c54
...@@ -28,7 +28,7 @@ int inet6_csk_bind_conflict(const struct sock *sk, ...@@ -28,7 +28,7 @@ int inet6_csk_bind_conflict(const struct sock *sk,
struct dst_entry *inet6_csk_route_req(struct sock *sk, struct flowi6 *fl6, struct dst_entry *inet6_csk_route_req(struct sock *sk, struct flowi6 *fl6,
const struct request_sock *req); const struct request_sock *req);
struct request_sock *inet6_csk_search_req(const struct sock *sk, struct request_sock *inet6_csk_search_req(struct sock *sk,
const __be16 rport, const __be16 rport,
const struct in6_addr *raddr, const struct in6_addr *raddr,
const struct in6_addr *laddr, const struct in6_addr *laddr,
......
...@@ -256,7 +256,7 @@ inet_csk_rto_backoff(const struct inet_connection_sock *icsk, ...@@ -256,7 +256,7 @@ inet_csk_rto_backoff(const struct inet_connection_sock *icsk,
struct sock *inet_csk_accept(struct sock *sk, int flags, int *err); struct sock *inet_csk_accept(struct sock *sk, int flags, int *err);
struct request_sock *inet_csk_search_req(const struct sock *sk, struct request_sock *inet_csk_search_req(struct sock *sk,
const __be16 rport, const __be16 rport,
const __be32 raddr, const __be32 raddr,
const __be32 laddr); const __be32 laddr);
...@@ -282,15 +282,13 @@ void inet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req, ...@@ -282,15 +282,13 @@ void inet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req,
static inline void inet_csk_reqsk_queue_removed(struct sock *sk, static inline void inet_csk_reqsk_queue_removed(struct sock *sk,
struct request_sock *req) struct request_sock *req)
{ {
if (reqsk_queue_removed(&inet_csk(sk)->icsk_accept_queue, req) == 0) reqsk_queue_removed(&inet_csk(sk)->icsk_accept_queue, req);
inet_csk_delete_keepalive_timer(sk);
} }
static inline void inet_csk_reqsk_queue_added(struct sock *sk, static inline void inet_csk_reqsk_queue_added(struct sock *sk,
const unsigned long timeout) const unsigned long timeout)
{ {
if (reqsk_queue_added(&inet_csk(sk)->icsk_accept_queue) == 0) reqsk_queue_added(&inet_csk(sk)->icsk_accept_queue);
inet_csk_reset_keepalive_timer(sk, timeout);
} }
static inline int inet_csk_reqsk_queue_len(const struct sock *sk) static inline int inet_csk_reqsk_queue_len(const struct sock *sk)
...@@ -319,14 +317,9 @@ static inline void inet_csk_reqsk_queue_drop(struct sock *sk, ...@@ -319,14 +317,9 @@ static inline void inet_csk_reqsk_queue_drop(struct sock *sk,
{ {
inet_csk_reqsk_queue_unlink(sk, req); inet_csk_reqsk_queue_unlink(sk, req);
inet_csk_reqsk_queue_removed(sk, req); inet_csk_reqsk_queue_removed(sk, req);
reqsk_free(req); reqsk_put(req);
} }
void inet_csk_reqsk_queue_prune(struct sock *parent,
const unsigned long interval,
const unsigned long timeout,
const unsigned long max_rto);
void inet_csk_destroy_sock(struct sock *sk); void inet_csk_destroy_sock(struct sock *sk);
void inet_csk_prepare_forced_close(struct sock *sk); void inet_csk_prepare_forced_close(struct sock *sk);
......
...@@ -62,7 +62,7 @@ struct request_sock { ...@@ -62,7 +62,7 @@ struct request_sock {
u32 window_clamp; /* window clamp at creation time */ u32 window_clamp; /* window clamp at creation time */
u32 rcv_wnd; /* rcv_wnd offered first time */ u32 rcv_wnd; /* rcv_wnd offered first time */
u32 ts_recent; u32 ts_recent;
unsigned long expires; struct timer_list rsk_timer;
const struct request_sock_ops *rsk_ops; const struct request_sock_ops *rsk_ops;
struct sock *sk; struct sock *sk;
u32 secid; u32 secid;
...@@ -110,9 +110,6 @@ static inline void reqsk_free(struct request_sock *req) ...@@ -110,9 +110,6 @@ static inline void reqsk_free(struct request_sock *req)
static inline void reqsk_put(struct request_sock *req) static inline void reqsk_put(struct request_sock *req)
{ {
/* temporary debugging, until req sock are put into ehash table */
WARN_ON_ONCE(atomic_read(&req->rsk_refcnt) != 1);
if (atomic_dec_and_test(&req->rsk_refcnt)) if (atomic_dec_and_test(&req->rsk_refcnt))
reqsk_free(req); reqsk_free(req);
} }
...@@ -124,12 +121,16 @@ extern int sysctl_max_syn_backlog; ...@@ -124,12 +121,16 @@ extern int sysctl_max_syn_backlog;
* @max_qlen_log - log_2 of maximal queued SYNs/REQUESTs * @max_qlen_log - log_2 of maximal queued SYNs/REQUESTs
*/ */
struct listen_sock { struct listen_sock {
u8 max_qlen_log; int qlen_inc; /* protected by listener lock */
int young_inc;/* protected by listener lock */
/* following fields can be updated by timer */
atomic_t qlen_dec; /* qlen = qlen_inc - qlen_dec */
atomic_t young_dec;
u8 max_qlen_log ____cacheline_aligned_in_smp;
u8 synflood_warned; u8 synflood_warned;
/* 2 bytes hole, try to use */ /* 2 bytes hole, try to use */
int qlen;
int qlen_young;
int clock_hand;
u32 hash_rnd; u32 hash_rnd;
u32 nr_table_entries; u32 nr_table_entries;
struct request_sock *syn_table[0]; struct request_sock *syn_table[0];
...@@ -182,9 +183,7 @@ struct fastopen_queue { ...@@ -182,9 +183,7 @@ struct fastopen_queue {
struct request_sock_queue { struct request_sock_queue {
struct request_sock *rskq_accept_head; struct request_sock *rskq_accept_head;
struct request_sock *rskq_accept_tail; struct request_sock *rskq_accept_tail;
rwlock_t syn_wait_lock;
u8 rskq_defer_accept; u8 rskq_defer_accept;
/* 3 bytes hole, try to pack */
struct listen_sock *listen_opt; struct listen_sock *listen_opt;
struct fastopen_queue *fastopenq; /* This is non-NULL iff TFO has been struct fastopen_queue *fastopenq; /* This is non-NULL iff TFO has been
* enabled on this listener. Check * enabled on this listener. Check
...@@ -192,6 +191,9 @@ struct request_sock_queue { ...@@ -192,6 +191,9 @@ struct request_sock_queue {
* to determine if TFO is enabled * to determine if TFO is enabled
* right at this moment. * right at this moment.
*/ */
/* temporary alignment, our goal is to get rid of this lock */
rwlock_t syn_wait_lock ____cacheline_aligned_in_smp;
}; };
int reqsk_queue_alloc(struct request_sock_queue *queue, int reqsk_queue_alloc(struct request_sock_queue *queue,
...@@ -223,11 +225,15 @@ static inline void reqsk_queue_unlink(struct request_sock_queue *queue, ...@@ -223,11 +225,15 @@ static inline void reqsk_queue_unlink(struct request_sock_queue *queue,
struct request_sock **prev; struct request_sock **prev;
write_lock(&queue->syn_wait_lock); write_lock(&queue->syn_wait_lock);
prev = &lopt->syn_table[req->rsk_hash]; prev = &lopt->syn_table[req->rsk_hash];
while (*prev != req) while (*prev != req)
prev = &(*prev)->dl_next; prev = &(*prev)->dl_next;
*prev = req->dl_next; *prev = req->dl_next;
write_unlock(&queue->syn_wait_lock); write_unlock(&queue->syn_wait_lock);
if (del_timer(&req->rsk_timer))
reqsk_put(req);
} }
static inline void reqsk_queue_add(struct request_sock_queue *queue, static inline void reqsk_queue_add(struct request_sock_queue *queue,
...@@ -260,64 +266,53 @@ static inline struct request_sock *reqsk_queue_remove(struct request_sock_queue ...@@ -260,64 +266,53 @@ static inline struct request_sock *reqsk_queue_remove(struct request_sock_queue
return req; return req;
} }
static inline int reqsk_queue_removed(struct request_sock_queue *queue, static inline void reqsk_queue_removed(struct request_sock_queue *queue,
struct request_sock *req) const struct request_sock *req)
{ {
struct listen_sock *lopt = queue->listen_opt; struct listen_sock *lopt = queue->listen_opt;
if (req->num_timeout == 0) if (req->num_timeout == 0)
--lopt->qlen_young; atomic_inc(&lopt->young_dec);
atomic_inc(&lopt->qlen_dec);
return --lopt->qlen;
} }
static inline int reqsk_queue_added(struct request_sock_queue *queue) static inline void reqsk_queue_added(struct request_sock_queue *queue)
{ {
struct listen_sock *lopt = queue->listen_opt; struct listen_sock *lopt = queue->listen_opt;
const int prev_qlen = lopt->qlen;
lopt->qlen_young++; lopt->young_inc++;
lopt->qlen++; lopt->qlen_inc++;
return prev_qlen; }
static inline int listen_sock_qlen(const struct listen_sock *lopt)
{
return lopt->qlen_inc - atomic_read(&lopt->qlen_dec);
}
static inline int listen_sock_young(const struct listen_sock *lopt)
{
return lopt->young_inc - atomic_read(&lopt->young_dec);
} }
static inline int reqsk_queue_len(const struct request_sock_queue *queue) static inline int reqsk_queue_len(const struct request_sock_queue *queue)
{ {
return queue->listen_opt != NULL ? queue->listen_opt->qlen : 0; const struct listen_sock *lopt = queue->listen_opt;
return lopt ? listen_sock_qlen(lopt) : 0;
} }
static inline int reqsk_queue_len_young(const struct request_sock_queue *queue) static inline int reqsk_queue_len_young(const struct request_sock_queue *queue)
{ {
return queue->listen_opt->qlen_young; return listen_sock_young(queue->listen_opt);
} }
static inline int reqsk_queue_is_full(const struct request_sock_queue *queue) static inline int reqsk_queue_is_full(const struct request_sock_queue *queue)
{ {
return queue->listen_opt->qlen >> queue->listen_opt->max_qlen_log; return reqsk_queue_len(queue) >> queue->listen_opt->max_qlen_log;
} }
static inline void reqsk_queue_hash_req(struct request_sock_queue *queue, void reqsk_queue_hash_req(struct request_sock_queue *queue,
u32 hash, struct request_sock *req, u32 hash, struct request_sock *req,
unsigned long timeout) unsigned long timeout);
{
struct listen_sock *lopt = queue->listen_opt;
req->expires = jiffies + timeout;
req->num_retrans = 0;
req->num_timeout = 0;
req->sk = NULL;
/* before letting lookups find us, make sure all req fields
* are committed to memory and refcnt initialized.
*/
smp_wmb();
atomic_set(&req->rsk_refcnt, 1);
req->rsk_hash = hash;
write_lock(&queue->syn_wait_lock);
req->dl_next = lopt->syn_table[hash];
lopt->syn_table[hash] = req;
write_unlock(&queue->syn_wait_lock);
}
#endif /* _REQUEST_SOCK_H */ #endif /* _REQUEST_SOCK_H */
...@@ -94,21 +94,26 @@ void reqsk_queue_destroy(struct request_sock_queue *queue) ...@@ -94,21 +94,26 @@ void reqsk_queue_destroy(struct request_sock_queue *queue)
/* make all the listen_opt local to us */ /* make all the listen_opt local to us */
struct listen_sock *lopt = reqsk_queue_yank_listen_sk(queue); struct listen_sock *lopt = reqsk_queue_yank_listen_sk(queue);
if (lopt->qlen != 0) { if (listen_sock_qlen(lopt) != 0) {
unsigned int i; unsigned int i;
for (i = 0; i < lopt->nr_table_entries; i++) { for (i = 0; i < lopt->nr_table_entries; i++) {
struct request_sock *req; struct request_sock *req;
write_lock_bh(&queue->syn_wait_lock);
while ((req = lopt->syn_table[i]) != NULL) { while ((req = lopt->syn_table[i]) != NULL) {
lopt->syn_table[i] = req->dl_next; lopt->syn_table[i] = req->dl_next;
lopt->qlen--; atomic_inc(&lopt->qlen_dec);
if (del_timer(&req->rsk_timer))
reqsk_put(req);
reqsk_put(req); reqsk_put(req);
} }
write_unlock_bh(&queue->syn_wait_lock);
} }
} }
WARN_ON(lopt->qlen != 0); if (WARN_ON(listen_sock_qlen(lopt) != 0))
pr_err("qlen %u\n", listen_sock_qlen(lopt));
kvfree(lopt); kvfree(lopt);
} }
...@@ -187,7 +192,7 @@ void reqsk_fastopen_remove(struct sock *sk, struct request_sock *req, ...@@ -187,7 +192,7 @@ void reqsk_fastopen_remove(struct sock *sk, struct request_sock *req,
* *
* For more details see CoNext'11 "TCP Fast Open" paper. * For more details see CoNext'11 "TCP Fast Open" paper.
*/ */
req->expires = jiffies + 60*HZ; req->rsk_timer.expires = jiffies + 60*HZ;
if (fastopenq->rskq_rst_head == NULL) if (fastopenq->rskq_rst_head == NULL)
fastopenq->rskq_rst_head = req; fastopenq->rskq_rst_head = req;
else else
......
...@@ -2739,7 +2739,7 @@ static int req_prot_init(const struct proto *prot) ...@@ -2739,7 +2739,7 @@ static int req_prot_init(const struct proto *prot)
rsk_prot->slab = kmem_cache_create(rsk_prot->slab_name, rsk_prot->slab = kmem_cache_create(rsk_prot->slab_name,
rsk_prot->obj_size, 0, rsk_prot->obj_size, 0,
SLAB_HWCACHE_ALIGN, NULL); 0, NULL);
if (!rsk_prot->slab) { if (!rsk_prot->slab) {
pr_crit("%s: Can't create request sock SLAB cache!\n", pr_crit("%s: Can't create request sock SLAB cache!\n",
......
...@@ -306,6 +306,7 @@ static void dccp_v4_err(struct sk_buff *skb, u32 info) ...@@ -306,6 +306,7 @@ static void dccp_v4_err(struct sk_buff *skb, u32 info)
if (!between48(seq, dccp_rsk(req)->dreq_iss, if (!between48(seq, dccp_rsk(req)->dreq_iss,
dccp_rsk(req)->dreq_gss)) { dccp_rsk(req)->dreq_gss)) {
NET_INC_STATS_BH(net, LINUX_MIB_OUTOFWINDOWICMPS); NET_INC_STATS_BH(net, LINUX_MIB_OUTOFWINDOWICMPS);
reqsk_put(req);
goto out; goto out;
} }
/* /*
...@@ -315,6 +316,7 @@ static void dccp_v4_err(struct sk_buff *skb, u32 info) ...@@ -315,6 +316,7 @@ static void dccp_v4_err(struct sk_buff *skb, u32 info)
* errors returned from accept(). * errors returned from accept().
*/ */
inet_csk_reqsk_queue_drop(sk, req); inet_csk_reqsk_queue_drop(sk, req);
reqsk_put(req);
goto out; goto out;
case DCCP_REQUESTING: case DCCP_REQUESTING:
...@@ -451,9 +453,11 @@ static struct sock *dccp_v4_hnd_req(struct sock *sk, struct sk_buff *skb) ...@@ -451,9 +453,11 @@ static struct sock *dccp_v4_hnd_req(struct sock *sk, struct sk_buff *skb)
/* Find possible connection requests. */ /* Find possible connection requests. */
struct request_sock *req = inet_csk_search_req(sk, dh->dccph_sport, struct request_sock *req = inet_csk_search_req(sk, dh->dccph_sport,
iph->saddr, iph->daddr); iph->saddr, iph->daddr);
if (req) if (req) {
return dccp_check_req(sk, skb, req); nsk = dccp_check_req(sk, skb, req);
reqsk_put(req);
return nsk;
}
nsk = inet_lookup_established(sock_net(sk), &dccp_hashinfo, nsk = inet_lookup_established(sock_net(sk), &dccp_hashinfo,
iph->saddr, dh->dccph_sport, iph->saddr, dh->dccph_sport,
iph->daddr, dh->dccph_dport, iph->daddr, dh->dccph_dport,
......
...@@ -157,7 +157,7 @@ static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, ...@@ -157,7 +157,7 @@ static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
req = inet6_csk_search_req(sk, dh->dccph_dport, req = inet6_csk_search_req(sk, dh->dccph_dport,
&hdr->daddr, &hdr->saddr, &hdr->daddr, &hdr->saddr,
inet6_iif(skb)); inet6_iif(skb));
if (req == NULL) if (!req)
goto out; goto out;
/* /*
...@@ -169,10 +169,12 @@ static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, ...@@ -169,10 +169,12 @@ static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
if (!between48(seq, dccp_rsk(req)->dreq_iss, if (!between48(seq, dccp_rsk(req)->dreq_iss,
dccp_rsk(req)->dreq_gss)) { dccp_rsk(req)->dreq_gss)) {
NET_INC_STATS_BH(net, LINUX_MIB_OUTOFWINDOWICMPS); NET_INC_STATS_BH(net, LINUX_MIB_OUTOFWINDOWICMPS);
reqsk_put(req);
goto out; goto out;
} }
inet_csk_reqsk_queue_drop(sk, req); inet_csk_reqsk_queue_drop(sk, req);
reqsk_put(req);
goto out; goto out;
case DCCP_REQUESTING: case DCCP_REQUESTING:
...@@ -322,9 +324,11 @@ static struct sock *dccp_v6_hnd_req(struct sock *sk,struct sk_buff *skb) ...@@ -322,9 +324,11 @@ static struct sock *dccp_v6_hnd_req(struct sock *sk,struct sk_buff *skb)
req = inet6_csk_search_req(sk, dh->dccph_sport, &iph->saddr, req = inet6_csk_search_req(sk, dh->dccph_sport, &iph->saddr,
&iph->daddr, inet6_iif(skb)); &iph->daddr, inet6_iif(skb));
if (req != NULL) if (req) {
return dccp_check_req(sk, skb, req); nsk = dccp_check_req(sk, skb, req);
reqsk_put(req);
return nsk;
}
nsk = __inet6_lookup_established(sock_net(sk), &dccp_hashinfo, nsk = __inet6_lookup_established(sock_net(sk), &dccp_hashinfo,
&iph->saddr, dh->dccph_sport, &iph->saddr, dh->dccph_sport,
&iph->daddr, ntohs(dh->dccph_dport), &iph->daddr, ntohs(dh->dccph_dport),
......
...@@ -161,33 +161,11 @@ out: ...@@ -161,33 +161,11 @@ out:
sock_put(sk); sock_put(sk);
} }
/*
* Timer for listening sockets
*/
static void dccp_response_timer(struct sock *sk)
{
inet_csk_reqsk_queue_prune(sk, TCP_SYNQ_INTERVAL, DCCP_TIMEOUT_INIT,
DCCP_RTO_MAX);
}
static void dccp_keepalive_timer(unsigned long data) static void dccp_keepalive_timer(unsigned long data)
{ {
struct sock *sk = (struct sock *)data; struct sock *sk = (struct sock *)data;
/* Only process if socket is not in use. */ pr_err("dccp should not use a keepalive timer !\n");
bh_lock_sock(sk);
if (sock_owned_by_user(sk)) {
/* Try again later. */
inet_csk_reset_keepalive_timer(sk, HZ / 20);
goto out;
}
if (sk->sk_state == DCCP_LISTEN) {
dccp_response_timer(sk);
goto out;
}
out:
bh_unlock_sock(sk);
sock_put(sk); sock_put(sk);
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <net/route.h> #include <net/route.h>
#include <net/tcp_states.h> #include <net/tcp_states.h>
#include <net/xfrm.h> #include <net/xfrm.h>
#include <net/tcp.h>
#ifdef INET_CSK_DEBUG #ifdef INET_CSK_DEBUG
const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n"; const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
...@@ -476,31 +477,37 @@ static inline u32 inet_synq_hash(const __be32 raddr, const __be16 rport, ...@@ -476,31 +477,37 @@ static inline u32 inet_synq_hash(const __be32 raddr, const __be16 rport,
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
#define AF_INET_FAMILY(fam) ((fam) == AF_INET) #define AF_INET_FAMILY(fam) ((fam) == AF_INET)
#else #else
#define AF_INET_FAMILY(fam) 1 #define AF_INET_FAMILY(fam) true
#endif #endif
struct request_sock *inet_csk_search_req(const struct sock *sk, /* Note: this is temporary :
const __be16 rport, const __be32 raddr, * req sock will no longer be in listener hash table
*/
struct request_sock *inet_csk_search_req(struct sock *sk,
const __be16 rport,
const __be32 raddr,
const __be32 laddr) const __be32 laddr)
{ {
const struct inet_connection_sock *icsk = inet_csk(sk); struct inet_connection_sock *icsk = inet_csk(sk);
struct listen_sock *lopt = icsk->icsk_accept_queue.listen_opt; struct listen_sock *lopt = icsk->icsk_accept_queue.listen_opt;
struct request_sock *req; struct request_sock *req;
u32 hash = inet_synq_hash(raddr, rport, lopt->hash_rnd,
lopt->nr_table_entries);
for (req = lopt->syn_table[inet_synq_hash(raddr, rport, lopt->hash_rnd, write_lock(&icsk->icsk_accept_queue.syn_wait_lock);
lopt->nr_table_entries)]; for (req = lopt->syn_table[hash]; req != NULL; req = req->dl_next) {
req != NULL;
req = req->dl_next) {
const struct inet_request_sock *ireq = inet_rsk(req); const struct inet_request_sock *ireq = inet_rsk(req);
if (ireq->ir_rmt_port == rport && if (ireq->ir_rmt_port == rport &&
ireq->ir_rmt_addr == raddr && ireq->ir_rmt_addr == raddr &&
ireq->ir_loc_addr == laddr && ireq->ir_loc_addr == laddr &&
AF_INET_FAMILY(req->rsk_ops->family)) { AF_INET_FAMILY(req->rsk_ops->family)) {
atomic_inc(&req->rsk_refcnt);
WARN_ON(req->sk); WARN_ON(req->sk);
break; break;
} }
} }
write_unlock(&icsk->icsk_accept_queue.syn_wait_lock);
return req; return req;
} }
...@@ -556,23 +563,23 @@ int inet_rtx_syn_ack(struct sock *parent, struct request_sock *req) ...@@ -556,23 +563,23 @@ int inet_rtx_syn_ack(struct sock *parent, struct request_sock *req)
} }
EXPORT_SYMBOL(inet_rtx_syn_ack); EXPORT_SYMBOL(inet_rtx_syn_ack);
void inet_csk_reqsk_queue_prune(struct sock *parent, static void reqsk_timer_handler(unsigned long data)
const unsigned long interval,
const unsigned long timeout,
const unsigned long max_rto)
{ {
struct inet_connection_sock *icsk = inet_csk(parent); struct request_sock *req = (struct request_sock *)data;
struct sock *sk_listener = req->rsk_listener;
struct inet_connection_sock *icsk = inet_csk(sk_listener);
struct request_sock_queue *queue = &icsk->icsk_accept_queue; struct request_sock_queue *queue = &icsk->icsk_accept_queue;
struct listen_sock *lopt = queue->listen_opt; struct listen_sock *lopt = queue->listen_opt;
int max_retries = icsk->icsk_syn_retries ? : sysctl_tcp_synack_retries; int expire = 0, resend = 0;
int thresh = max_retries; int max_retries, thresh;
unsigned long now = jiffies;
struct request_sock **reqp, *req;
int i, budget;
if (lopt == NULL || lopt->qlen == 0) if (sk_listener->sk_state != TCP_LISTEN || !lopt) {
reqsk_put(req);
return; return;
}
max_retries = icsk->icsk_syn_retries ? : sysctl_tcp_synack_retries;
thresh = max_retries;
/* Normally all the openreqs are young and become mature /* Normally all the openreqs are young and become mature
* (i.e. converted to established socket) for first timeout. * (i.e. converted to established socket) for first timeout.
* If synack was not acknowledged for 1 second, it means * If synack was not acknowledged for 1 second, it means
...@@ -590,71 +597,63 @@ void inet_csk_reqsk_queue_prune(struct sock *parent, ...@@ -590,71 +597,63 @@ void inet_csk_reqsk_queue_prune(struct sock *parent,
* embrions; and abort old ones without pity, if old * embrions; and abort old ones without pity, if old
* ones are about to clog our table. * ones are about to clog our table.
*/ */
if (lopt->qlen>>(lopt->max_qlen_log-1)) { if (listen_sock_qlen(lopt) >> (lopt->max_qlen_log - 1)) {
int young = (lopt->qlen_young<<1); int young = listen_sock_young(lopt) << 1;
while (thresh > 2) { while (thresh > 2) {
if (lopt->qlen < young) if (listen_sock_qlen(lopt) < young)
break; break;
thresh--; thresh--;
young <<= 1; young <<= 1;
} }
} }
if (queue->rskq_defer_accept) if (queue->rskq_defer_accept)
max_retries = queue->rskq_defer_accept; max_retries = queue->rskq_defer_accept;
syn_ack_recalc(req, thresh, max_retries, queue->rskq_defer_accept,
budget = 2 * (lopt->nr_table_entries / (timeout / interval));
i = lopt->clock_hand;
do {
reqp = &lopt->syn_table[i];
if (!*reqp)
goto next_bucket;
write_lock(&queue->syn_wait_lock);
while ((req = *reqp) != NULL) {
if (time_after_eq(now, req->expires)) {
int expire = 0, resend = 0;
syn_ack_recalc(req, thresh, max_retries,
queue->rskq_defer_accept,
&expire, &resend); &expire, &resend);
req->rsk_ops->syn_ack_timeout(parent, req); req->rsk_ops->syn_ack_timeout(sk_listener, req);
if (!expire && if (!expire &&
(!resend || (!resend ||
!inet_rtx_syn_ack(parent, req) || !inet_rtx_syn_ack(sk_listener, req) ||
inet_rsk(req)->acked)) { inet_rsk(req)->acked)) {
unsigned long timeo; unsigned long timeo;
if (req->num_timeout++ == 0) if (req->num_timeout++ == 0)
lopt->qlen_young--; atomic_inc(&lopt->young_dec);
timeo = min(timeout << req->num_timeout, timeo = min(TCP_TIMEOUT_INIT << req->num_timeout, TCP_RTO_MAX);
max_rto); mod_timer_pinned(&req->rsk_timer, jiffies + timeo);
req->expires = now + timeo; return;
reqp = &req->dl_next;
continue;
} }
inet_csk_reqsk_queue_drop(sk_listener, req);
/* Drop this request */
*reqp = req->dl_next;
reqsk_queue_removed(queue, req);
reqsk_put(req); reqsk_put(req);
continue; }
}
reqp = &req->dl_next; void reqsk_queue_hash_req(struct request_sock_queue *queue,
} u32 hash, struct request_sock *req,
write_unlock(&queue->syn_wait_lock); unsigned long timeout)
next_bucket: {
i = (i + 1) & (lopt->nr_table_entries - 1); struct listen_sock *lopt = queue->listen_opt;
} while (--budget > 0); req->num_retrans = 0;
req->num_timeout = 0;
req->sk = NULL;