Make flow cache name space aware
Subsystems (3)
v2 cover Make flow cache name space aware
Hi,
This patch set aims to make flow cache operating in a per net style when inserting flow cache entry or flush flow cache. The reason to do so is not much compelling but reasonable, which is flushing flow cache in original implementation has global effective, the collateral damage is netns with only a few flow cache entries has gone.
So this patch make flow cache running in a per net scope. Operation from different netns won't interfere with each other. And the flushing operation is worthwhile for the netns which supposed to be.
v2:
- Pick up newly created file include/net/flowcache.h missed in v1.
Fan Du (4):
flowcache: Namespacify flowcache global parameters with xfrm
flowcache: Make flowcache entry inserting/flushing in per-net style
flowcache: Fixup flow cache part in xfrm policy
flowcache: Bring net/core/flow.c under IPsec maintain scope
MAINTAINERS | 1 + include/net/flow.h | 5 +- include/net/flowcache.h | 25 +++++++++ include/net/netns/xfrm.h | 11 ++++ net/core/flow.c | 127 +++++++++++++++++++++------------------------- net/xfrm/xfrm_policy.c | 7 +-- 6 files changed, 101 insertions(+), 75 deletions(-) create mode 100644 include/net/flowcache.h
Signature · 1 line
1.7.9.5
PATCH v2 1/4 flowcache: Namespacify flowcache global parameters with xfrm
Since flowcache is tightly coupled with IPsec, so it would be easier to put flow cache global parameters here into xfrm namespace part.
--- include/net/netns/xfrm.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
include/net/netns/xfrm.h +11 -0
@@ -6,6 +6,7 @@#include <linux/workqueue.h> #include <linux/xfrm.h> #include <net/dst_ops.h> +#include <net/flowcache.h> struct ctl_table_header ;
@@ -61,6 +62,16 @@ struct netns_xfrm {spinlock_t xfrm_policy_sk_bundle_lock;rwlock_t xfrm_policy_lock;struct mutex xfrm_cfg_mutex; + +/* flow cache part */ +struct flow_cache flow_cache_global; +struct kmem_cache *flow_cachep; +atomic_t flow_cache_genid; +struct list_head flow_cache_gc_list; +spinlock_t flow_cache_gc_lock; +struct work_struct flow_cache_gc_work; +struct work_struct flow_cache_flush_work; + struct mutex flow_flush_sem; };#endif
Signature · 1 line
1.7.9.5
Re: [PATCHv2 net-next 1/4] flowcache: Namespacify flowcache global parameters with xfrm
Quoted 14 lines · Fan Du
Since flowcache is tightly coupled with IPsec, so it would be easier to put flow cache global parameters here into xfrm namespace part.
Signed-off-by Fan Du <[email protected]>--- include/net/netns/xfrm.h | 11 +++++++++++ 1 file changed, 11 insertions(+)include/net/netns/xfrm.h +0
-0
include/net/netns/xfrm.h line 9
Quoted 4 lines
include/net/netns/xfrm.h +1
-0@@ -6,6 +6,7 @@#include <linux/workqueue.h> #include <linux/xfrm.h> #include <net/dst_ops.h> +#include <net/flowcache.h>
You are including a file that doesn't exist yet. You create it later, with patch 2. This breaks bisection.
Signature · 1 line
Sabrina
PATCH v2 2/4 flowcache: Make flowcache entry inserting/flushing in per-net style
In reply to Fan DuInserting a entry into flowcache, or flushing flowcache should be based on per net scope. The reason to do so is flushing operation from fat netns crammed with flow entries will also making the slim netns with only a few flow cache entries go away in original implementation.
--- include/net/flow.h | 5 +- include/net/flowcache.h | 25 ++++++++++ net/core/flow.c | 127 +++++++++++++++++++++-------------------------- 3 files changed, 85 insertions(+), 72 deletions(-) create mode 100644 include/net/flowcache.h
include/net/flow.h +3 -2
@@ -218,9 +218,10 @@ struct flow_cache_object *flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir, flow_resolve_t resolver, void *ctx); +int flow_cache_init (struct net *net); -void flow_cache_flush (void ); -void flow_cache_flush_deferred (void ); +void flow_cache_flush (struct net *net); +void flow_cache_flush_deferred (struct net *net);extern atomic_t flow_cache_genid;#endif
include/net/flowcache.h new file +25 -0
@@ -0,0 +1,25 @@ +#ifndef _NET_FLOWCACHE_H +#define _NET_FLOWCACHE_H + +#include <linux/interrupt.h> +#include <linux/types.h> +#include <linux/timer.h> +#include <linux/notifier.h> + +struct flow_cache_percpu { +struct hlist_head *hash_table; +int hash_count; +u32 hash_rnd; +int hash_rnd_recalc; +struct tasklet_struct flush_tasklet; +}; + +struct flow_cache { +u32 hash_shift; +struct flow_cache_percpu __percpu *percpu; +struct notifier_block hotcpu_notifier; +int low_watermark; +int high_watermark; +struct timer_list rnd_timer; +}; +#endif /* _NET_FLOWCACHE_H */
net/core/flow.c +57 -70
282 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v2 3/4 flowcache: Fixup flow cache part in xfrm policy
In reply to Fan DuBump flow cache genid, and flush flow cache should also be made in per net style.
--- net/xfrm/xfrm_policy.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/xfrm/xfrm_policy.c +4 -3
@@ -661,7 +661,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)hlist_add_head (&policy->bydst, chain);xfrm_pol_hold (policy); net->xfrm.policy_count[dir]++; -atomic_inc (&flow_cache_genid); +atomic_inc (&net->xfrm.flow_cache_genid);/* After previous checking, family can either be AF_INET or AF_INET6 */ if (policy->family ==AF_INET )
@@ -2567,14 +2567,14 @@ static void __xfrm_garbage_collect(struct net *net)void xfrm_garbage_collect (struct net *net) { -flow_cache_flush (); +flow_cache_flush (net);__xfrm_garbage_collect (net); }EXPORT_SYMBOL (xfrm_garbage_collect);static void xfrm_garbage_collect_deferred (struct net *net) { -flow_cache_flush_deferred (); +flow_cache_flush_deferred (net);__xfrm_garbage_collect (net); }
@@ -2947,6 +2947,7 @@ static int __net_init xfrm_net_init(struct net *net)spin_lock_init (&net->xfrm.xfrm_policy_sk_bundle_lock);mutex_init (&net->xfrm.xfrm_cfg_mutex); +flow_cache_init (net);return 0 ; out_sysctl:
Signature · 1 line
1.7.9.5
Re: [PATCHv2 net-next 3/4] flowcache: Fixup flow cache part in xfrm policy
Quoted 39 lines · Fan Du
Bump flow cache genid, and flush flow cache should also be made in per net style.
Signed-off-by Fan Du <[email protected]>--- net/xfrm/xfrm_policy.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)net/xfrm/xfrm_policy.c +3
-3@@ -661,7 +661,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)hlist_add_head (&policy->bydst, chain);xfrm_pol_hold (policy); net->xfrm.policy_count[dir]++; -atomic_inc (&flow_cache_genid); +atomic_inc (&net->xfrm.flow_cache_genid);/* After previous checking, family can either be AF_INET or AF_INET6 */ if (policy->family ==AF_INET )@@ -2567,14 +2567,14 @@ static void __xfrm_garbage_collect(struct net *net)void xfrm_garbage_collect (struct net *net) { -flow_cache_flush (); +flow_cache_flush (net);__xfrm_garbage_collect (net); }EXPORT_SYMBOL (xfrm_garbage_collect);static void xfrm_garbage_collect_deferred (struct net *net) { -flow_cache_flush_deferred (); +flow_cache_flush_deferred (net);__xfrm_garbage_collect (net); }
net/xfrm/xfrm_policy.c static int __net_init xfrm_net_init(struct net *net) · line 2953
Quoted 7 lines
net/xfrm/xfrm_policy.c +1
-0@@ -2947,6 +2947,7 @@ static int __net_init xfrm_net_init(struct net *net)spin_lock_init (&net->xfrm.xfrm_policy_sk_bundle_lock);mutex_init (&net->xfrm.xfrm_cfg_mutex); +flow_cache_init (net);return 0 ; out_sysctl:
You didn't address Cong Wang's comments for v1:
Quoted 19 lines · Cong Wang
Quoted 5 lines · Fan Du
void
xfrm_garbage_collect(struct net *net)
{net/xfrm/xfrm_policy.c +1
-1-flow_cache_flush (); +flow_cache_flush (net);net/xfrm/xfrm_policy.c static void __xfrm_garbage_collect(struct net *net) · line 2579
Quoted 10 lines
net/xfrm/xfrm_policy.c +1
-1__xfrm_garbage_collect (net); }EXPORT_SYMBOL (xfrm_garbage_collect);static void xfrm_garbage_collect_deferred (struct net *net) { -flow_cache_flush_deferred (); +flow_cache_flush_deferred (net);__xfrm_garbage_collect (net); }You changed the prototypes of flow_cache_flush*() in the previous patch, so, here you break bisect. They have to be in one commit.
Signature · 1 line
Sabrina
Re: [PATCHv2 net-next 3/4] flowcache: Fixup flow cache part in xfrm policy
Quoted 43 lines · Sabrina Dubroca
Quoted 42 lines · Fan Du
Bump flow cache genid, and flush flow cache should also be made in per net style.
Signed-off-by Fan Du<[email protected]>--- net/xfrm/xfrm_policy.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)net/xfrm/xfrm_policy.c +3
-3@@ -661,7 +661,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)hlist_add_head (&policy->bydst, chain);xfrm_pol_hold (policy); net->xfrm.policy_count[dir]++; -atomic_inc (&flow_cache_genid); +atomic_inc (&net->xfrm.flow_cache_genid);/* After previous checking, family can either be AF_INET or AF_INET6 */ if (policy->family ==AF_INET )@@ -2567,14 +2567,14 @@ static void __xfrm_garbage_collect(struct net *net)void xfrm_garbage_collect (struct net *net) { -flow_cache_flush (); +flow_cache_flush (net);__xfrm_garbage_collect (net); }EXPORT_SYMBOL (xfrm_garbage_collect);static void xfrm_garbage_collect_deferred (struct net *net) { -flow_cache_flush_deferred (); +flow_cache_flush_deferred (net);__xfrm_garbage_collect (net); }@@ -2947,6 +2947,7 @@ static int __net_init xfrm_net_init(struct net *net)spin_lock_init (&net->xfrm.xfrm_policy_sk_bundle_lock);mutex_init (&net->xfrm.xfrm_cfg_mutex);
Quoted 7 lines
net/xfrm/xfrm_policy.c static int __net_init xfrm_net_init(struct net *net) · line 2953
Quoted 4 lines
net/xfrm/xfrm_policy.c +1
-0+flow_cache_init (net);return 0 ; out_sysctl:You didn't address Cong Wang's comments for v1:
Sorry, seems company email server didn't forward below message to me。。。 but I saw yours. I'm happy to forge the relevant patches into one single patch in next next version :) if Steffen doesn't complain.
Quoted 23 lines
Quoted 19 lines · Cong Wang
Quoted 5 lines · Fan Du
void xfrm_garbage_collect(struct net *net) {net/xfrm/xfrm_policy.c +1
-1-flow_cache_flush (); +flow_cache_flush (net);net/xfrm/xfrm_policy.c static void __xfrm_garbage_collect(struct net *net) · line 2579
Quoted 10 lines
net/xfrm/xfrm_policy.c +1
-1__xfrm_garbage_collect (net); }EXPORT_SYMBOL (xfrm_garbage_collect);static void xfrm_garbage_collect_deferred (struct net *net) { -flow_cache_flush_deferred (); +flow_cache_flush_deferred (net);__xfrm_garbage_collect (net); }You changed the prototypes of flow_cache_flush*() in the previous patch, so, here you break bisect. They have to be in one commit.
Signature · 3 lines
浮沉随浪只记今朝笑 --fan
PATCH v2 4/4 flowcache: Bring net/core/flow.c under IPsec maintain scope
In reply to Fan DuAs flow cache is mainly manipulated from IPsec.
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -5916,6 +5916,7 @@ L: [email protected] T: git git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git T: git git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next.git S: Maintained +F: net/core/flow.c F: net/xfrm/ F: net/key/ F: net/ipv4/xfrm*
Signature · 1 line
1.7.9.5