Skip to contentSkip to conversation

Make flow cache name space aware

PATCH Superseded Fan Du 3 participants 5 messages Jan 15, 2014 – Jan 16, 2014

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Fan Du

author
#0 lore raw

v3 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.
v3:
- I made a mistake by spreading one unified patch into different patches, which break bisect operation. So forge into one piece patches advised by Cong and Sabrina.

Fan Du (2):
flowcache: Make flow cache name space aware
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
author
#1 lore raw

PATCH v3 1/2 flowcache: Make flow cache name space aware

Inserting 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.

Since flowcache is tightly coupled with IPsec, so it would be easier to put flow cache global parameters into xfrm namespace part. And one last thing needs to do is bumping flow cache genid, and flush flow cache should also be made in per net style.

---
 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 +--
 5 files changed, 100 insertions(+), 75 deletions(-)
 create mode 100644 include/net/flowcache.h
include/net/flow.h +3 -2
index d23e7fa..bee3741 100644
@@ -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
new file mode 100644
index 0000000..c8f665e
@@ -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 */
include/net/netns/xfrm.h +11 -0
index 1006a26..52d0086 100644
@@ -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
net/core/flow.c +57 -70

282 lines not on this page · raw message

net/xfrm/xfrm_policy.c +4 -3
index 0177082..9d60590 100644
@@ -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
author
#4 lore raw

PATCH v3 2/2 flowcache: Bring net/core/flow.c under IPsec maintain scope

In reply to Fan Du

As flow cache is mainly manipulated from IPsec.

---
 MAINTAINERS |    1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index e11d495..14ad385 100644
@@ -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
maintainer
#2 lore raw

Re: [PATCHv3 net-next 1/2] flowcache: Make flow cache name space aware

In reply to Fan Du
Quoted 7 lines · Fan Du

Inserting 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.

Since flowcache is tightly coupled with IPsec, so it would be easier to put flow cache global parameters into xfrm namespace part.

With this change the flow cache is not globally available any more, it becomes a part of IPsec. IPsec is the only user of the flow cache and I guess noone else want to use it (we removed the routing cache to avoid such caching recently).

So I would not mind to move this into IPsec, but I want to see an ack from David before I take this into ipsec-next.

maintainer
#3 lore raw

Re: [PATCHv3 net-next 1/2] flowcache: Make flow cache name space aware

From: Steffen Klassert <[email protected]>
Date: Thu, 16 Jan 2014 11:19:46 +0100

Quoted 2 lines

So I would not mind to move this into IPsec, but I want to see an ack from David before I take this into ipsec-next.

No objections from me.

And longer term I don't even think the flow cache makes sense as the most appropriate data structure for fast IPSEC lookups either.

Anything that requires GC has fundamental issues.