Skip to content

Commit

Permalink
ipv4: Namespaceify tcp_max_syn_backlog knob
Browse files Browse the repository at this point in the history
Different namespace application might require different maximal
number of remembered connection requests.

Signed-off-by: Haishuang Yan <yanhaishuang@cmss.chinamobile.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Haishuang Yan authored and David S. Miller committed Dec 29, 2016
1 parent 1946e67 commit fee83d0
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 18 deletions.
1 change: 1 addition & 0 deletions include/net/netns/ipv4.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ struct netns_ipv4 {
unsigned int sysctl_tcp_notsent_lowat;
int sysctl_tcp_tw_reuse;
struct inet_timewait_death_row tcp_death_row;
int sysctl_max_syn_backlog;

int sysctl_igmp_max_memberships;
int sysctl_igmp_max_msf;
Expand Down
4 changes: 1 addition & 3 deletions include/net/request_sock.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* NET Generic infrastructure for Network protocols.
*
* Definitions for request_sock
* Definitions for request_sock
*
* Authors: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
*
Expand Down Expand Up @@ -123,8 +123,6 @@ static inline void reqsk_put(struct request_sock *req)
reqsk_free(req);
}

extern int sysctl_max_syn_backlog;

/*
* For a TCP Fast Open listener -
* lock - protects the access to all the reqsk, which is co-owned by
Expand Down
2 changes: 0 additions & 2 deletions net/core/request_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
* and it will increase in proportion to the memory of machine.
* Note : Dont forget somaxconn that may limit backlog too.
*/
int sysctl_max_syn_backlog = 256;
EXPORT_SYMBOL(sysctl_max_syn_backlog);

void reqsk_queue_alloc(struct request_sock_queue *queue)
{
Expand Down
14 changes: 7 additions & 7 deletions net/ipv4/sysctl_net_ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,6 @@ static struct ctl_table ipv4_table[] = {
.mode = 0644,
.proc_handler = proc_dointvec
},
{
.procname = "tcp_max_syn_backlog",
.data = &sysctl_max_syn_backlog,
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec
},
{
.procname = "inet_peer_threshold",
.data = &inet_peer_threshold,
Expand Down Expand Up @@ -960,6 +953,13 @@ static struct ctl_table ipv4_net_table[] = {
.mode = 0644,
.proc_handler = proc_dointvec
},
{
.procname = "tcp_max_syn_backlog",
.data = &init_net.ipv4.sysctl_max_syn_backlog,
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec
},
#ifdef CONFIG_IP_ROUTE_MULTIPATH
{
.procname = "fib_multipath_use_neigh",
Expand Down
2 changes: 0 additions & 2 deletions net/ipv4/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3378,9 +3378,7 @@ void __init tcp_init(void)


cnt = tcp_hashinfo.ehash_mask + 1;

sysctl_tcp_max_orphans = cnt / 2;
sysctl_max_syn_backlog = max(128, cnt / 256);

tcp_init_mem();
/* Set per-socket limits to no more than 1/128 the pressure threshold */
Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/tcp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -6377,8 +6377,8 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
}
/* Kill the following clause, if you dislike this way. */
else if (!net->ipv4.sysctl_tcp_syncookies &&
(sysctl_max_syn_backlog - inet_csk_reqsk_queue_len(sk) <
(sysctl_max_syn_backlog >> 2)) &&
(net->ipv4.sysctl_max_syn_backlog - inet_csk_reqsk_queue_len(sk) <
(net->ipv4.sysctl_max_syn_backlog >> 2)) &&
!tcp_peer_is_proven(req, dst, false,
tmp_opt.saw_tstamp)) {
/* Without syncookies last quarter of
Expand Down
7 changes: 5 additions & 2 deletions net/ipv4/tcp_ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -2419,7 +2419,7 @@ static void __net_exit tcp_sk_exit(struct net *net)

static int __net_init tcp_sk_init(struct net *net)
{
int res, cpu;
int res, cpu, cnt;

net->ipv4.tcp_sk = alloc_percpu(struct sock *);
if (!net->ipv4.tcp_sk)
Expand Down Expand Up @@ -2458,10 +2458,13 @@ static int __net_init tcp_sk_init(struct net *net)
net->ipv4.sysctl_tcp_notsent_lowat = UINT_MAX;
net->ipv4.sysctl_tcp_tw_reuse = 0;

cnt = tcp_hashinfo.ehash_mask + 1;
net->ipv4.tcp_death_row.sysctl_tw_recycle = 0;
net->ipv4.tcp_death_row.sysctl_max_tw_buckets = (tcp_hashinfo.ehash_mask + 1) / 2;
net->ipv4.tcp_death_row.sysctl_max_tw_buckets = (cnt + 1) / 2;
net->ipv4.tcp_death_row.hashinfo = &tcp_hashinfo;

net->ipv4.sysctl_max_syn_backlog = max(128, cnt / 256);

return 0;
fail:
tcp_sk_exit(net);
Expand Down

0 comments on commit fee83d0

Please sign in to comment.