Conntrack offload debuggability improvements
Subsystems (3)
v4 cover Conntrack offload debuggability improvements
Current conntrack offload implementation doesn't provide much visibility and control over offload code. There is no way to determine current load on workqueues that process the offload tasks which makes it hard to debug the cases where offload is significantly delayed due to rate of new connections being higher than driver or hardware offload rate.
Improve the debuggability by introducing procfs for current total of workqueue tasks for nf_ft_offload_add, nf_ft_offload_del and nf_ft_offload_stats queues. This allows visibility for flow offload delay due to system scheduling offload tasks faster than driver/hardware can process them.
Vlad Buslov (2):
net/sched: act_ct: set 'net' pointer when creating new nf_flow_table
netfilter: nf_flow_table: count pending offload workqueue tasks
include/net/net_namespace.h | 6 ++ include/net/netfilter/nf_flow_table.h | 21 +++++++ include/net/netns/flow_table.h | 14 +++++ net/netfilter/Kconfig | 9 +++ net/netfilter/Makefile | 1 + net/netfilter/nf_flow_table_core.c | 62 ++++++++++++++++++++- net/netfilter/nf_flow_table_offload.c | 17 +++++- net/netfilter/nf_flow_table_procfs.c | 80 +++++++++++++++++++++++++++ net/sched/act_ct.c | 5 +- 9 files changed, 209 insertions(+), 6 deletions(-) create mode 100644 include/net/netns/flow_table.h create mode 100644 net/netfilter/nf_flow_table_procfs.c
Signature · 1 line
2.36.1
PATCH v4 1/2 net/sched: act_ct: set 'net' pointer when creating new nf_flow_table
Following patches in series use the pointer to access flow table offload debug variables.
--- net/sched/act_ct.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/sched/act_ct.c +3 -2
@@ -277,7 +277,7 @@ static struct nf_flowtable_type flowtable_ct = { .owner = THIS_MODULE, }; -static int tcf_ct_flow_table_get (struct tcf_ct_params *params) +static int tcf_ct_flow_table_get (struct net *net,struct tcf_ct_params *params) {struct tcf_ct_flow_table *ct_ft;int err = -ENOMEM ;
@@ -303,6 +303,7 @@ static int tcf_ct_flow_table_get(struct tcf_ct_params *params) err =nf_flow_table_init (&ct_ft->nf_ft);if (err) goto err_init; +write_pnet (&ct_ft->nf_ft.net, net);__module_get (THIS_MODULE ); out_unlock:
@@ -1391,7 +1392,7 @@ static int tcf_ct_init(struct net *net, struct nlattr *nla,if (err) goto cleanup; - err =tcf_ct_flow_table_get (params); + err =tcf_ct_flow_table_get (net, params);if (err) goto cleanup;
Signature · 1 line
2.36.1
PATCH v4 2/2 netfilter: nf_flow_table: count pending offload workqueue tasks
In reply to Vlad BuslovTo improve hardware offload debuggability count pending 'add', 'del' and 'stats' flow_table offload workqueue tasks. Counters are incremented before scheduling new task and decremented when workqueue handler finishes executing. These counters allow user to diagnose congestion on hardware offload workqueues that can happen when either CPU is starved and workqueue jobs are executed at lower rate than new ones are added or when hardware/driver can't keep up with the rate.
Implement the described counters as percpu counters inside new struct netns_ft which is stored inside struct net. Expose them via new procfs file '/proc/net/stats/nf_flowtable' that is similar to existing 'nf_conntrack' file.
---
Notes:
Changes V3 -> V4:
- Move basic infrastructure code that registers pernet ops for flow table from previous patch in series that got nacked to this one.
- Since sysctl functionality from previous patch got removed from the series and the new file is now only used for procfs-related code, rename it from nf_flow_table_sysctl.c to nf_flow_table_procfs.c.
- Make nf_flow_table_procfs.c compiled conditionally depending on CONFIG_NF_FLOW_TABLE_PROCFS and remove ifdefs from the source file.
Changes V2 -> V3:
- Add CONFIG_NF_FLOW_TABLE_PROCFS dependency on SYSCTL.
- Move dummy definitions of nf_flow_table_{init|fini}_proc() from source to nf_flow_table.h file in order to not break compilation when CONFIG_SYSCTL is disabled.
Changes V1 -> V2:
- Combine patches that expose add, del, stats tasks.
- Use percpu stats to count pending workqueue tasks instead of atomics.
- Expose the stats via /proc/net/stats/nf_flowtable file instead of sysctls.
include/net/net_namespace.h | 6 ++ include/net/netfilter/nf_flow_table.h | 21 +++++++ include/net/netns/flow_table.h | 14 +++++ net/netfilter/Kconfig | 9 +++ net/netfilter/Makefile | 1 + net/netfilter/nf_flow_table_core.c | 62 ++++++++++++++++++++- net/netfilter/nf_flow_table_offload.c | 17 +++++- net/netfilter/nf_flow_table_procfs.c | 80 +++++++++++++++++++++++++++ 8 files changed, 206 insertions(+), 4 deletions(-) create mode 100644 include/net/netns/flow_table.h create mode 100644 net/netfilter/nf_flow_table_procfs.c
include/net/net_namespace.h +6 -0
@@ -26,6 +26,9 @@#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )#include <net/netns/conntrack.h> #endif +#if IS_ENABLED (CONFIG_NF_FLOW_TABLE ) +#include <net/netns/flow_table.h> +#endif #include <net/netns/nftables.h> #include <net/netns/xfrm.h> #include <net/netns/mpls.h>
@@ -140,6 +143,9 @@ struct net {#if defined(CONFIG_NF_TABLES ) || defined(CONFIG_NF_TABLES_MODULE )struct netns_nftables nft;#endif +#if IS_ENABLED (CONFIG_NF_FLOW_TABLE ) +struct netns_ft ft; +#endif #endif #ifdef CONFIG_WEXT_CORE struct sk_buff_head wext_nlevents;
include/net/netfilter/nf_flow_table.h +21 -0
@@ -335,4 +335,25 @@ static inline __be16 nf_flow_pppoe_proto(const struct sk_buff *skb) return 0; } +#define NF_FLOW_TABLE_STAT_INC (net, count) __this_cpu_inc((net)->ft.stat->count) +#define NF_FLOW_TABLE_STAT_DEC (net, count) __this_cpu_dec((net)->ft.stat->count) +#define NF_FLOW_TABLE_STAT_INC_ATOMIC (net, count) \ + this_cpu_inc((net)->ft.stat->count) +#define NF_FLOW_TABLE_STAT_DEC_ATOMIC (net, count) \ + this_cpu_dec((net)->ft.stat->count) + +#ifdef CONFIG_NF_FLOW_TABLE_PROCFS +int nf_flow_table_init_proc (struct net *net); +void nf_flow_table_fini_proc (struct net *net); +#else +static inline int nf_flow_table_init_proc (struct net *net) +{ +return 0 ; +} + +static inline void nf_flow_table_fini_proc (struct net *net) +{ +} +#endif /* CONFIG_NF_FLOW_TABLE_PROCFS */ +#endif /* _NF_FLOW_TABLE_H */
include/net/netns/flow_table.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __NETNS_FLOW_TABLE_H +#define __NETNS_FLOW_TABLE_H + +struct nf_flow_table_stat { +unsigned int count_wq_add; +unsigned int count_wq_del; +unsigned int count_wq_stats; +}; + +struct netns_ft { +struct nf_flow_table_stat __percpu *stat; +}; +#endif
net/netfilter/Kconfig +9 -0
@@ -734,6 +734,15 @@ config NF_FLOW_TABLE To compile it as a module, choose M here. +config NF_FLOW_TABLE_PROCFS + bool "Supply flow table statistics in procfs" + default y + depends on PROC_FS + depends on SYSCTL + help + This option enables for the flow table offload statistics + to be shown in procfs under net/netfilter/nf_flowtable. + config NETFILTER_XTABLES tristate "Netfilter Xtables support (required for ip_tables)" default m if NETFILTER_ADVANCED=n
net/netfilter/Makefile +1 -0
@@ -128,6 +128,7 @@ obj-$(CONFIG_NFT_FWD_NETDEV) += nft_fwd_netdev.o obj-$(CONFIG_NF_FLOW_TABLE) += nf_flow_table.o nf_flow_table-objs := nf_flow_table_core.o nf_flow_table_ip.o \ nf_flow_table_offload.o +nf_flow_table-$(CONFIG_NF_FLOW_TABLE_PROCFS) += nf_flow_table_procfs.o obj-$(CONFIG_NF_FLOW_TABLE_INET) += nf_flow_table_inet.o
net/netfilter/nf_flow_table_core.c +61 -1
75 lines not on this page · raw message
net/netfilter/nf_flow_table_offload.c +14 -3
@@ -967,17 +967,22 @@ static void flow_offload_work_stats(struct flow_offload_work *offload)static void flow_offload_work_handler (struct work_struct *work) {struct flow_offload_work *offload; +struct net *net; offload = container_of(work, struct flow_offload_work, work); + net =read_pnet (&offload->flowtable->net);switch (offload->cmd) {case FLOW_CLS_REPLACE :flow_offload_work_add (offload); +NF_FLOW_TABLE_STAT_DEC_ATOMIC (net, count_wq_add);break ;case FLOW_CLS_DESTROY :flow_offload_work_del (offload); +NF_FLOW_TABLE_STAT_DEC_ATOMIC (net, count_wq_del);break ;case FLOW_CLS_STATS :flow_offload_work_stats (offload); +NF_FLOW_TABLE_STAT_DEC_ATOMIC (net, count_wq_stats);break ;default :WARN_ON_ONCE (1 );
@@ -989,12 +994,18 @@ static void flow_offload_work_handler(struct work_struct *work)static void flow_offload_queue_work (struct flow_offload_work *offload) { -if (offload->cmd ==FLOW_CLS_REPLACE ) +struct net *net =read_pnet (&offload->flowtable->net); + +if (offload->cmd ==FLOW_CLS_REPLACE ) { +NF_FLOW_TABLE_STAT_INC (net, count_wq_add);queue_work (nf_flow_offload_add_wq, &offload->work); -else if (offload->cmd ==FLOW_CLS_DESTROY ) + }else if (offload->cmd ==FLOW_CLS_DESTROY ) { +NF_FLOW_TABLE_STAT_INC (net, count_wq_del);queue_work (nf_flow_offload_del_wq, &offload->work); -else + }else { +NF_FLOW_TABLE_STAT_INC (net, count_wq_stats);queue_work (nf_flow_offload_stats_wq, &offload->work); + } } static struct flow_offload_work *
net/netfilter/nf_flow_table_procfs.c new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.36.1
Pablo Neira Ayuso
maintainerQuoted 11 lines · Vlad Buslov
Current conntrack offload implementation doesn't provide much visibility and control over offload code. There is no way to determine current load on workqueues that process the offload tasks which makes it hard to debug the cases where offload is significantly delayed due to rate of new connections being higher than driver or hardware offload rate.
Improve the debuggability by introducing procfs for current total of workqueue tasks for
nf_ft_offload_add,nf_ft_offload_delandnf_ft_offload_statsqueues. This allows visibility for flow offload delay due to system scheduling offload tasks faster than driver/hardware can process them.
Series applied, thanks