Skip to content

Commit fee83d0

Browse files
Haishuang Yandavem330
authored andcommitted
ipv4: Namespaceify tcp_max_syn_backlog knob
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>
1 parent 1946e67 commit fee83d0

7 files changed

Lines changed: 16 additions & 18 deletions

File tree

‎include/net/netns/ipv4.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ struct netns_ipv4 {
122122
unsigned int sysctl_tcp_notsent_lowat;
123123
int sysctl_tcp_tw_reuse;
124124
struct inet_timewait_death_row tcp_death_row;
125+
int sysctl_max_syn_backlog;
125126

126127
int sysctl_igmp_max_memberships;
127128
int sysctl_igmp_max_msf;

‎include/net/request_sock.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* NET Generic infrastructure for Network protocols.
33
*
4-
* Definitions for request_sock
4+
* Definitions for request_sock
55
*
66
* Authors: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
77
*
@@ -123,8 +123,6 @@ static inline void reqsk_put(struct request_sock *req)
123123
reqsk_free(req);
124124
}
125125

126-
extern int sysctl_max_syn_backlog;
127-
128126
/*
129127
* For a TCP Fast Open listener -
130128
* lock - protects the access to all the reqsk, which is co-owned by

‎net/core/request_sock.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
* and it will increase in proportion to the memory of machine.
3535
* Note : Dont forget somaxconn that may limit backlog too.
3636
*/
37-
int sysctl_max_syn_backlog = 256;
38-
EXPORT_SYMBOL(sysctl_max_syn_backlog);
3937

4038
void reqsk_queue_alloc(struct request_sock_queue *queue)
4139
{

‎net/ipv4/sysctl_net_ipv4.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,6 @@ static struct ctl_table ipv4_table[] = {
323323
.mode = 0644,
324324
.proc_handler = proc_dointvec
325325
},
326-
{
327-
.procname = "tcp_max_syn_backlog",
328-
.data = &sysctl_max_syn_backlog,
329-
.maxlen = sizeof(int),
330-
.mode = 0644,
331-
.proc_handler = proc_dointvec
332-
},
333326
{
334327
.procname = "inet_peer_threshold",
335328
.data = &inet_peer_threshold,
@@ -960,6 +953,13 @@ static struct ctl_table ipv4_net_table[] = {
960953
.mode = 0644,
961954
.proc_handler = proc_dointvec
962955
},
956+
{
957+
.procname = "tcp_max_syn_backlog",
958+
.data = &init_net.ipv4.sysctl_max_syn_backlog,
959+
.maxlen = sizeof(int),
960+
.mode = 0644,
961+
.proc_handler = proc_dointvec
962+
},
963963
#ifdef CONFIG_IP_ROUTE_MULTIPATH
964964
{
965965
.procname = "fib_multipath_use_neigh",

‎net/ipv4/tcp.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3378,9 +3378,7 @@ void __init tcp_init(void)
33783378

33793379

33803380
cnt = tcp_hashinfo.ehash_mask + 1;
3381-
33823381
sysctl_tcp_max_orphans = cnt / 2;
3383-
sysctl_max_syn_backlog = max(128, cnt / 256);
33843382

33853383
tcp_init_mem();
33863384
/* Set per-socket limits to no more than 1/128 the pressure threshold */

‎net/ipv4/tcp_input.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6377,8 +6377,8 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
63776377
}
63786378
/* Kill the following clause, if you dislike this way. */
63796379
else if (!net->ipv4.sysctl_tcp_syncookies &&
6380-
(sysctl_max_syn_backlog - inet_csk_reqsk_queue_len(sk) <
6381-
(sysctl_max_syn_backlog >> 2)) &&
6380+
(net->ipv4.sysctl_max_syn_backlog - inet_csk_reqsk_queue_len(sk) <
6381+
(net->ipv4.sysctl_max_syn_backlog >> 2)) &&
63826382
!tcp_peer_is_proven(req, dst, false,
63836383
tmp_opt.saw_tstamp)) {
63846384
/* Without syncookies last quarter of

‎net/ipv4/tcp_ipv4.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,7 +2419,7 @@ static void __net_exit tcp_sk_exit(struct net *net)
24192419

24202420
static int __net_init tcp_sk_init(struct net *net)
24212421
{
2422-
int res, cpu;
2422+
int res, cpu, cnt;
24232423

24242424
net->ipv4.tcp_sk = alloc_percpu(struct sock *);
24252425
if (!net->ipv4.tcp_sk)
@@ -2458,10 +2458,13 @@ static int __net_init tcp_sk_init(struct net *net)
24582458
net->ipv4.sysctl_tcp_notsent_lowat = UINT_MAX;
24592459
net->ipv4.sysctl_tcp_tw_reuse = 0;
24602460

2461+
cnt = tcp_hashinfo.ehash_mask + 1;
24612462
net->ipv4.tcp_death_row.sysctl_tw_recycle = 0;
2462-
net->ipv4.tcp_death_row.sysctl_max_tw_buckets = (tcp_hashinfo.ehash_mask + 1) / 2;
2463+
net->ipv4.tcp_death_row.sysctl_max_tw_buckets = (cnt + 1) / 2;
24632464
net->ipv4.tcp_death_row.hashinfo = &tcp_hashinfo;
24642465

2466+
net->ipv4.sysctl_max_syn_backlog = max(128, cnt / 256);
2467+
24652468
return 0;
24662469
fail:
24672470
tcp_sk_exit(net);

0 commit comments

Comments
 (0)