aboutsummaryrefslogtreecommitdiffstats
path: root/net/core/flow.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/core/flow.c')
-rw-r--r--net/core/flow.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/net/core/flow.c b/net/core/flow.c
index 1033725be40b..3937b1b68d5b 100644
--- a/net/core/flow.c
+++ b/net/core/flow.c
@@ -92,8 +92,11 @@ static void flow_cache_gc_task(struct work_struct *work)
92 list_splice_tail_init(&xfrm->flow_cache_gc_list, &gc_list); 92 list_splice_tail_init(&xfrm->flow_cache_gc_list, &gc_list);
93 spin_unlock_bh(&xfrm->flow_cache_gc_lock); 93 spin_unlock_bh(&xfrm->flow_cache_gc_lock);
94 94
95 list_for_each_entry_safe(fce, n, &gc_list, u.gc_list) 95 list_for_each_entry_safe(fce, n, &gc_list, u.gc_list) {
96 flow_entry_kill(fce, xfrm); 96 flow_entry_kill(fce, xfrm);
97 atomic_dec(&xfrm->flow_cache_gc_count);
98 WARN_ON(atomic_read(&xfrm->flow_cache_gc_count) < 0);
99 }
97} 100}
98 101
99static void flow_cache_queue_garbage(struct flow_cache_percpu *fcp, 102static void flow_cache_queue_garbage(struct flow_cache_percpu *fcp,
@@ -101,6 +104,7 @@ static void flow_cache_queue_garbage(struct flow_cache_percpu *fcp,
101 struct netns_xfrm *xfrm) 104 struct netns_xfrm *xfrm)
102{ 105{
103 if (deleted) { 106 if (deleted) {
107 atomic_add(deleted, &xfrm->flow_cache_gc_count);
104 fcp->hash_count -= deleted; 108 fcp->hash_count -= deleted;
105 spin_lock_bh(&xfrm->flow_cache_gc_lock); 109 spin_lock_bh(&xfrm->flow_cache_gc_lock);
106 list_splice_tail(gc_list, &xfrm->flow_cache_gc_list); 110 list_splice_tail(gc_list, &xfrm->flow_cache_gc_list);
@@ -232,6 +236,13 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
232 if (fcp->hash_count > fc->high_watermark) 236 if (fcp->hash_count > fc->high_watermark)
233 flow_cache_shrink(fc, fcp); 237 flow_cache_shrink(fc, fcp);
234 238
239 if (fcp->hash_count > 2 * fc->high_watermark ||
240 atomic_read(&net->xfrm.flow_cache_gc_count) > fc->high_watermark) {
241 atomic_inc(&net->xfrm.flow_cache_genid);
242 flo = ERR_PTR(-ENOBUFS);
243 goto ret_object;
244 }
245
235 fle = kmem_cache_alloc(flow_cachep, GFP_ATOMIC); 246 fle = kmem_cache_alloc(flow_cachep, GFP_ATOMIC);
236 if (fle) { 247 if (fle) {
237 fle->net = net; 248 fle->net = net;
@@ -446,6 +457,7 @@ int flow_cache_init(struct net *net)
446 INIT_WORK(&net->xfrm.flow_cache_gc_work, flow_cache_gc_task); 457 INIT_WORK(&net->xfrm.flow_cache_gc_work, flow_cache_gc_task);
447 INIT_WORK(&net->xfrm.flow_cache_flush_work, flow_cache_flush_task); 458 INIT_WORK(&net->xfrm.flow_cache_flush_work, flow_cache_flush_task);
448 mutex_init(&net->xfrm.flow_flush_sem); 459 mutex_init(&net->xfrm.flow_flush_sem);
460 atomic_set(&net->xfrm.flow_cache_gc_count, 0);
449 461
450 fc->hash_shift = 10; 462 fc->hash_shift = 10;
451 fc->low_watermark = 2 * flow_cache_hash_size(fc); 463 fc->low_watermark = 2 * flow_cache_hash_size(fc);