From 61d7e2b266fe00b0af43ec53cca6ca694efb709e Mon Sep 17 00:00:00 2001 From: Hongbo Li Date: Wed, 1 Jul 2020 10:58:03 +0800 Subject: [PATCH] net: sched when reading tcp proc cat /proc/net/tcp may cause long latency. Add cond_resched() when reading this proc file. Signed-off-by: Hongbo Li --- include/net/tcp.h | 1 + net/ipv4/sysctl_net_ipv4.c | 7 +++++++ net/ipv4/tcp_ipv4.c | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/include/net/tcp.h b/include/net/tcp.h index bb17aa302..ff22dad4f 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -278,6 +278,7 @@ extern int sysctl_tcp_loss_init_cwnd; extern int sysctl_tcp_init_cwnd; extern int sysctl_tcp_rto_min; extern int sysctl_tcp_rto_max; +extern int sysctl_tcp_proc_sched; extern atomic_long_t tcp_memory_allocated; extern struct percpu_counter tcp_sockets_allocated; diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c index c286f88f1..a6f6b1af4 100644 --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c @@ -771,6 +771,13 @@ static struct ctl_table ipv4_table[] = { .mode = 0644, .proc_handler = proc_dointvec, }, + { + .procname = "tcp_proc_sched", + .data = &sysctl_tcp_proc_sched, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, { } }; diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 9c07e9fd8..ffb45284d 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -85,6 +85,8 @@ #include #include +int sysctl_tcp_proc_sched __read_mostly = 1; + #ifdef CONFIG_TCP_MD5SIG static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key, __be32 daddr, __be32 saddr, const struct tcphdr *th); @@ -1966,6 +1968,8 @@ get_sk: return sk; } spin_unlock(&ilb->lock); + if (sysctl_tcp_proc_sched) + cond_resched(); st->offset = 0; if (++st->bucket < INET_LHTABLE_SIZE) goto get_head; @@ -2023,6 +2027,8 @@ static void *established_get_first(struct seq_file *seq) goto out; } spin_unlock_bh(lock); + if (sysctl_tcp_proc_sched) + cond_resched(); } out: return rc;