net: ipvs: add sysctl_run_estimation to support disable estimation
Subsystems (6)
PATCH 1/1 net: ipvs: add sysctl_run_estimation to support disable estimation
fix #31562403
estimation_timer will iterater the est_list to do estimation for each ipvs stats. When there are lots of services, the list can be very large.
We observiced estimation_timer() run for more then 200ms on a machine with 104 CPU and 50K services.
yunhong-cgl jiang report the same phenomenon before:
https://www.spinics.net/lists/lvs-devel/msg05426.html
In some cases(for example a large K8S cluster with many ipvs services), ipvs estimation may not be needed. So adding a sysctl blob to allow users to disable this completely.
Default is: 1 (enable)
--- Documentation/networking/ipvs-sysctl.rst | 17 ++++++ include/net/ip_vs.h | 3 + net/netfilter/ipvs/ip_vs_est.c | 73 ++++++++++++++++++++++++ 3 files changed, 93 insertions(+)
Documentation/networking/ipvs-sysctl.rst +17 -0
@@ -300,3 +300,20 @@ sync_version - INTEGER Kernels with this sync_version entry are able to receive messages of both version 1 and version 2 of the synchronisation protocol. + +run_estimation - BOOLEAN + 0 - disabled + not 0 - enabled (default) + + If disabled, the estimation will be stop, and you can't see + any update on speed estimation data. + + For example + 'Conns/s Pkts/s Pkts/s Bytes/s Bytes/s' + those data in /proc/net/ip_vs_stats will always be zero. + Note, this only affect the speed estimation, the total data + will still be updated. + + You can always re-enable estimation by setting this value to 1. + But be carefull, the first estimation after re-enable is not + accurate.
include/net/ip_vs.h +3 -0
@@ -941,6 +941,9 @@ struct netns_ipvs {struct ctl_table_header *lblcr_ctl_header;struct ctl_table *lblcr_ctl_table;/* ip_vs_est */ +int sysctl_run_estimation; +struct ctl_table_header *est_ctl_header; +struct ctl_table *est_ctl_table;struct list_head est_list;/* estimator list */ spinlock_t est_lock;struct timer_list est_timer;/* Estimation timer */
net/netfilter/ipvs/ip_vs_est.c +73 -0
99 lines not on this page · raw message
Signature · 1 line
2.19.1.3.ge56e4f7
Julian Anastasov
maintainerHello,
Quoted 8 lines · Dust Li
fix #31562403
estimation_timerwill iterater theest_listto do estimation for each ipvs stats. When there are lots of services, the list can be very large.
We observicedestimation_timer()run for more then 200ms on a machine with 104 CPU and 50K services.
Quoted 8 lines
yunhong-cgl jiang report the same phenomenon before:
https://www.spinics.net/lists/lvs-devel/msg05426.htmlIn some cases(for example a large K8S cluster with many ipvs services), ipvs estimation may not be needed. So adding a sysctl blob to allow users to disable this completely.
Default is: 1 (enable)
I guess, this patch should target net-next tree.
Quoted 37 lines
Signed-off-by Dust Li <[email protected]>--- Documentation/networking/ipvs-sysctl.rst | 17 ++++++ include/net/ip_vs.h | 3 + net/netfilter/ipvs/ip_vs_est.c | 73 ++++++++++++++++++++++++ 3 files changed, 93 insertions(+)Documentation/networking/ipvs-sysctl.rst +17
-0@@ -300,3 +300,20 @@ sync_version - INTEGER Kernels with this sync_version entry are able to receive messages of both version 1 and version 2 of the synchronisation protocol. + +run_estimation - BOOLEAN + 0 - disabled + not 0 - enabled (default) + + If disabled, the estimation will be stop, and you can't see + any update on speed estimation data. + + For example + 'Conns/s Pkts/s Pkts/s Bytes/s Bytes/s' + those data in /proc/net/ip_vs_stats will always be zero. + Note, this only affect the speed estimation, the total data + will still be updated. + + You can always re-enable estimation by setting this value to 1. + But be carefull, the first estimation after re-enable is not + accurate.include/net/ip_vs.h +0
-0
include/net/ip_vs.h struct netns_ipvs { · line 944
Quoted 4 lines
include/net/ip_vs.h +1
-0@@ -941,6 +941,9 @@ struct netns_ipvs {struct ctl_table_header *lblcr_ctl_header;struct ctl_table *lblcr_ctl_table;/* ip_vs_est */ +int sysctl_run_estimation;
We should keep such sysctl vars in a CONFIG_SYSCTL block
and we have corresponding inline functions for the two cases depending on CONFIG_SYSCTL. Still, many of the sysctl_* fields are not moved into such ifdef.
But you can get sysctl_pmtu_disc as example:
# grep -r sysctl_pmtu_disc include/net/ip_vs.h net/netfilter/ipvs/
Add the var in ip_vs_ctl.c as the other vars
and implement it just like sysctl_pmtu_disc.
include/net/ip_vs.h struct netns_ipvs { · line 946
Quoted 2 lines
include/net/ip_vs.h +2
-0+struct ctl_table_header *est_ctl_header; +struct ctl_table *est_ctl_table;
As result, we will not need specific ctl table
net/netfilter/ipvs/ip_vs_est.c static void estimation_timer(struct timer_list *t) · line 104
Quoted 13 lines
include/net/ip_vs.h +0
-0struct list_head est_list;/* estimator list */ spinlock_t est_lock;struct timer_list est_timer;/* Estimation timer */ net/netfilter/ipvs/ip_vs_est.c +2
-0@@ -100,6 +100,9 @@ static void estimation_timer(struct timer_list *t)u64 rate;struct netns_ipvs *ipvs =from_timer (ipvs, t, est_timer); +if (!ipvs->sysctl_run_estimation) + goto skip;
Some day this var will not be present if !CONFIG_SYSCTL,
so we should call the new inline function:
if (!sysctl_run_estimation(ipvs)) goto skip;
Quoted 72 lines
net/netfilter/ipvs/ip_vs_est.c +58
-0+spin_lock (&ipvs->est_lock);list_for_each_entry (e, &ipvs->est_list, list) { s = container_of(e, struct ip_vs_stats, est);@@ -131,6 +134,8 @@ static void estimation_timer(struct timer_list *t)spin_unlock (&s->lock); }spin_unlock (&ipvs->est_lock); + +skip:mod_timer (&ipvs->est_timer, jiffies +2 *HZ ); }@@ -184,10 +189,77 @@ void ip_vs_read_estimator(struct ip_vs_kstats *dst, struct ip_vs_stats *stats) dst->outbps = (e->outbps +0xF ) >>5 ; } +#ifdef CONFIG_SYSCTL +/* IPVS ESTIMATION sysctl table */ +static struct ctl_table vs_vars_table[] = { + { + .procname ="run_estimation" , + .data =NULL , + .maxlen =sizeof (int ), + .mode =0644 , + .proc_handler = proc_dointvec, + }, + { } +}; + +static int ip_vs_est_sysctl_init (struct netns_ipvs *ipvs) +{ +struct net *net = ipvs->net; + +if (!net_eq (net, &init_net)) { + ipvs->est_ctl_table =kmemdup (vs_vars_table, +sizeof (vs_vars_table), +GFP_KERNEL ); +if (!ipvs->est_ctl_table) +return -ENOMEM ; + +/* Don't export sysctls to unprivileged users */ +if (net->user_ns != &init_user_ns) + ipvs->est_ctl_table[0 ].procname =NULL ; + + }else { + ipvs->est_ctl_table = vs_vars_table; + } + + ipvs->sysctl_run_estimation =1 ; + ipvs->est_ctl_table[0 ].data = &ipvs->sysctl_run_estimation; + + ipvs->est_ctl_header = +register_net_sysctl (net,"net/ipv4/vs" , ipvs->est_ctl_table); +if (!ipvs->est_ctl_header) { +if (!net_eq (net, &init_net)) +kfree (ipvs->est_ctl_table); +return -ENOMEM ; + } + +return 0 ; +} + +static void ip_vs_est_sysctl_cleanup (struct netns_ipvs *ipvs) +{ +unregister_net_sysctl_table (ipvs->est_ctl_header); + +if (!net_eq (ipvs->net, &init_net)) +kfree (ipvs->est_ctl_table); +} + +#else
net/netfilter/ipvs/ip_vs_est.c void ip_vs_read_estimator(struct ip_vs_kstats *dst, struct ip_vs_stats *stats) · line 256
Quoted 10 lines
net/netfilter/ipvs/ip_vs_est.c +10
-0+ +static int ip_vs_est_sysctl_init (struct netns_ipvs *ipvs) +{ + ipvs->sysctl_run_estimation =1 ; +return 0 ; +} + +static void ip_vs_est_sysctl_cleanup (struct netns_ipvs *ipvs) { } + +#endif
Drop this ctl table. Just reset sysctl_run_estimation inip_vs_control_net_init_sysctl().
Quoted 17 lines
net/netfilter/ipvs/ip_vs_est.c +3
-0+int __net_init ip_vs_estimator_net_init (struct netns_ipvs *ipvs) {INIT_LIST_HEAD (&ipvs->est_list);spin_lock_init (&ipvs->est_lock); +ip_vs_est_sysctl_init (ipvs);timer_setup (&ipvs->est_timer, estimation_timer,0 );mod_timer (&ipvs->est_timer, jiffies +2 *HZ );return 0 ;@@ -196,4 +268,5 @@ int __net_init ip_vs_estimator_net_init(struct netns_ipvs *ipvs) void __net_exit ip_vs_estimator_net_cleanup(struct netns_ipvs *ipvs) {del_timer_sync (&ipvs->est_timer); +ip_vs_est_sysctl_cleanup (ipvs); }Signature · 1 line
2.19.1.3.ge56e4f7
Regards
--
Julian Anastasov <[email protected]>
Quoted 16 lines · Julian Anastasov
Hello,
Quoted 11 lines · Dust Li
fix #31562403
estimation_timerwill iterater theest_listto do estimation for each ipvs stats. When there are lots of services, the list can be very large.
We observicedestimation_timer()run for more then 200ms on a machine with 104 CPU and 50K services.yunhong-cgl jiang report the same phenomenon before:
https://www.spinics.net/lists/lvs-devel/msg05426.html
Quoted 7 lines
Quoted 5 lines
In some cases(for example a large K8S cluster with many ipvs services), ipvs estimation may not be needed. So adding a sysctl blob to allow users to disable this completely.
Default is: 1 (enable)
I guess, this patch should target net-next tree.
Yes. I will change the patch and send a v2 with net-next prefix.
Quoted 52 lines
Quoted 38 lines
Signed-off-by Dust Li <[email protected]>--- Documentation/networking/ipvs-sysctl.rst | 17 ++++++ include/net/ip_vs.h | 3 + net/netfilter/ipvs/ip_vs_est.c | 73 ++++++++++++++++++++++++ 3 files changed, 93 insertions(+)Documentation/networking/ipvs-sysctl.rst +17
-0@@ -300,3 +300,20 @@ sync_version - INTEGER Kernels with this sync_version entry are able to receive messages of both version 1 and version 2 of the synchronisation protocol. + +run_estimation - BOOLEAN + 0 - disabled + not 0 - enabled (default) + + If disabled, the estimation will be stop, and you can't see + any update on speed estimation data. + + For example + 'Conns/s Pkts/s Pkts/s Bytes/s Bytes/s' + those data in /proc/net/ip_vs_stats will always be zero. + Note, this only affect the speed estimation, the total data + will still be updated. + + You can always re-enable estimation by setting this value to 1. + But be carefull, the first estimation after re-enable is not + accurate.include/net/ip_vs.h +0
-0include/net/ip_vs.h struct netns_ipvs { · line 944
Quoted 4 lines
include/net/ip_vs.h +1
-0@@ -941,6 +941,9 @@ struct netns_ipvs {struct ctl_table_header *lblcr_ctl_header;struct ctl_table *lblcr_ctl_table;/* ip_vs_est */ +int sysctl_run_estimation;We should keep such sysctl vars in a
CONFIG_SYSCTLblock
and we have corresponding inline functions for the two cases depending onCONFIG_SYSCTL. Still, many of the sysctl_* fields are not moved into such ifdef.But you can get
sysctl_pmtu_discas example:# grep -r sysctl_pmtu_disc include/net/ip_vs.h net/netfilter/ipvs/
Quoted 7 lines
Add the var in
ip_vs_ctl.cas the other vars
and implement it just likesysctl_pmtu_disc.include/net/ip_vs.h struct netns_ipvs { · line 946
Quoted 2 lines
include/net/ip_vs.h +2
-0+struct ctl_table_header *est_ctl_header; +struct ctl_table *est_ctl_table;As result, we will not need specific ctl table
OK, will do, thanks for the advice.
Quoted 12 lines
Quoted 12 lines
include/net/ip_vs.h +0
-0struct list_head est_list;/* estimator list */ spinlock_t est_lock;struct timer_list est_timer;/* Estimation timer */ net/netfilter/ipvs/ip_vs_est.c +0
-0@@ -100,6 +100,9 @@ static void estimation_timer(struct timer_list *t)u64 rate;struct netns_ipvs *ipvs =from_timer (ipvs, t, est_timer);
Quoted 8 lines
net/netfilter/ipvs/ip_vs_est.c static void estimation_timer(struct timer_list *t) · line 104
Quoted 2 lines
net/netfilter/ipvs/ip_vs_est.c +2
-0+if (!ipvs->sysctl_run_estimation) + goto skip;Some day this var will not be present if !CONFIG_SYSCTL,
so we should call the new inline function:if (!sysctl_run_estimation(ipvs)) goto skip;
Yeah, this is better, will do.
Quoted 78 lines
Quoted 78 lines
net/netfilter/ipvs/ip_vs_est.c +63
-0+spin_lock (&ipvs->est_lock);list_for_each_entry (e, &ipvs->est_list, list) { s = container_of(e, struct ip_vs_stats, est);@@ -131,6 +134,8 @@ static void estimation_timer(struct timer_list *t)spin_unlock (&s->lock); }spin_unlock (&ipvs->est_lock); + +skip:mod_timer (&ipvs->est_timer, jiffies +2 *HZ ); }@@ -184,10 +189,77 @@ void ip_vs_read_estimator(struct ip_vs_kstats *dst, struct ip_vs_stats *stats) dst->outbps = (e->outbps +0xF ) >>5 ; } +#ifdef CONFIG_SYSCTL +/* IPVS ESTIMATION sysctl table */ +static struct ctl_table vs_vars_table[] = { + { + .procname ="run_estimation" , + .data =NULL , + .maxlen =sizeof (int ), + .mode =0644 , + .proc_handler = proc_dointvec, + }, + { } +}; + +static int ip_vs_est_sysctl_init (struct netns_ipvs *ipvs) +{ +struct net *net = ipvs->net; + +if (!net_eq (net, &init_net)) { + ipvs->est_ctl_table =kmemdup (vs_vars_table, +sizeof (vs_vars_table), +GFP_KERNEL ); +if (!ipvs->est_ctl_table) +return -ENOMEM ; + +/* Don't export sysctls to unprivileged users */ +if (net->user_ns != &init_user_ns) + ipvs->est_ctl_table[0 ].procname =NULL ; + + }else { + ipvs->est_ctl_table = vs_vars_table; + } + + ipvs->sysctl_run_estimation =1 ; + ipvs->est_ctl_table[0 ].data = &ipvs->sysctl_run_estimation; + + ipvs->est_ctl_header = +register_net_sysctl (net,"net/ipv4/vs" , ipvs->est_ctl_table); +if (!ipvs->est_ctl_header) { +if (!net_eq (net, &init_net)) +kfree (ipvs->est_ctl_table); +return -ENOMEM ; + } + +return 0 ; +} + +static void ip_vs_est_sysctl_cleanup (struct netns_ipvs *ipvs) +{ +unregister_net_sysctl_table (ipvs->est_ctl_header); + +if (!net_eq (ipvs->net, &init_net)) +kfree (ipvs->est_ctl_table); +} + +#else + +static int ip_vs_est_sysctl_init (struct netns_ipvs *ipvs) +{ + ipvs->sysctl_run_estimation =1 ; +return 0 ;
Quoted 8 lines
net/netfilter/ipvs/ip_vs_est.c void ip_vs_read_estimator(struct ip_vs_kstats *dst, struct ip_vs_stats *stats) · line 256
Quoted 5 lines
net/netfilter/ipvs/ip_vs_est.c +5
-0+} + +static void ip_vs_est_sysctl_cleanup (struct netns_ipvs *ipvs) { } + +#endif Drop this ctl table. Just reset
sysctl_run_estimationinip_vs_control_net_init_sysctl().
Will do.
Quoted 23 lines
Quoted 18 lines
net/netfilter/ipvs/ip_vs_est.c +3
-0+int __net_init ip_vs_estimator_net_init (struct netns_ipvs *ipvs) {INIT_LIST_HEAD (&ipvs->est_list);spin_lock_init (&ipvs->est_lock); +ip_vs_est_sysctl_init (ipvs);timer_setup (&ipvs->est_timer, estimation_timer,0 );mod_timer (&ipvs->est_timer, jiffies +2 *HZ );return 0 ;@@ -196,4 +268,5 @@ int __net_init ip_vs_estimator_net_init(struct netns_ipvs *ipvs) void __net_exit ip_vs_estimator_net_cleanup(struct netns_ipvs *ipvs) {del_timer_sync (&ipvs->est_timer); +ip_vs_est_sysctl_cleanup (ipvs); }Signature · 1 line
2.19.1.3.ge56e4f7Regards
--
Julian Anastasov <[email protected]>