aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4
diff options
context:
space:
mode:
authorNikolay Aleksandrov <nikolay@redhat.com>2014-08-01 06:29:48 -0400
committerDavid S. Miller <davem@davemloft.net>2014-08-02 18:31:31 -0400
commitd4ad4d22e7ac6b8711b35d7e86eb29f03f8ac153 (patch)
tree929ebb9bc76b52037572bfb58475112989b51ba0 /net/ipv4
parent2e404f632f44979ddf0ce0808a438249a72d7015 (diff)
inet: frags: use kmem_cache for inet_frag_queue
Use kmem_cache to allocate/free inet_frag_queue objects since they're all the same size per inet_frags user and are alloced/freed in high volumes thus making it a perfect case for kmem_cache. Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com> Acked-by: Florian Westphal <fw@strlen.de> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r--net/ipv4/inet_fragment.c13
-rw-r--r--net/ipv4/ip_fragment.c5
2 files changed, 14 insertions, 4 deletions
diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
index 4baa76c60398..9eb89f3f0ee4 100644
--- a/net/ipv4/inet_fragment.c
+++ b/net/ipv4/inet_fragment.c
@@ -198,7 +198,7 @@ static void inet_frag_schedule_worker(struct inet_frags *f)
198 schedule_work(&f->frags_work); 198 schedule_work(&f->frags_work);
199} 199}
200 200
201void inet_frags_init(struct inet_frags *f) 201int inet_frags_init(struct inet_frags *f)
202{ 202{
203 int i; 203 int i;
204 204
@@ -213,6 +213,12 @@ void inet_frags_init(struct inet_frags *f)
213 213
214 seqlock_init(&f->rnd_seqlock); 214 seqlock_init(&f->rnd_seqlock);
215 f->last_rebuild_jiffies = 0; 215 f->last_rebuild_jiffies = 0;
216 f->frags_cachep = kmem_cache_create(f->frags_cache_name, f->qsize, 0, 0,
217 NULL);
218 if (!f->frags_cachep)
219 return -ENOMEM;
220
221 return 0;
216} 222}
217EXPORT_SYMBOL(inet_frags_init); 223EXPORT_SYMBOL(inet_frags_init);
218 224
@@ -225,6 +231,7 @@ EXPORT_SYMBOL(inet_frags_init_net);
225void inet_frags_fini(struct inet_frags *f) 231void inet_frags_fini(struct inet_frags *f)
226{ 232{
227 cancel_work_sync(&f->frags_work); 233 cancel_work_sync(&f->frags_work);
234 kmem_cache_destroy(f->frags_cachep);
228} 235}
229EXPORT_SYMBOL(inet_frags_fini); 236EXPORT_SYMBOL(inet_frags_fini);
230 237
@@ -327,7 +334,7 @@ void inet_frag_destroy(struct inet_frag_queue *q, struct inet_frags *f)
327 334
328 if (f->destructor) 335 if (f->destructor)
329 f->destructor(q); 336 f->destructor(q);
330 kfree(q); 337 kmem_cache_free(f->frags_cachep, q);
331} 338}
332EXPORT_SYMBOL(inet_frag_destroy); 339EXPORT_SYMBOL(inet_frag_destroy);
333 340
@@ -377,7 +384,7 @@ static struct inet_frag_queue *inet_frag_alloc(struct netns_frags *nf,
377 return NULL; 384 return NULL;
378 } 385 }
379 386
380 q = kzalloc(f->qsize, GFP_ATOMIC); 387 q = kmem_cache_zalloc(f->frags_cachep, GFP_ATOMIC);
381 if (q == NULL) 388 if (q == NULL)
382 return NULL; 389 return NULL;
383 390
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
index cb56bcc1eee2..15f0e2bad7ad 100644
--- a/net/ipv4/ip_fragment.c
+++ b/net/ipv4/ip_fragment.c
@@ -55,6 +55,7 @@
55 */ 55 */
56 56
57static int sysctl_ipfrag_max_dist __read_mostly = 64; 57static int sysctl_ipfrag_max_dist __read_mostly = 64;
58static const char ip_frag_cache_name[] = "ip4-frags";
58 59
59struct ipfrag_skb_cb 60struct ipfrag_skb_cb
60{ 61{
@@ -860,5 +861,7 @@ void __init ipfrag_init(void)
860 ip4_frags.qsize = sizeof(struct ipq); 861 ip4_frags.qsize = sizeof(struct ipq);
861 ip4_frags.match = ip4_frag_match; 862 ip4_frags.match = ip4_frag_match;
862 ip4_frags.frag_expire = ip_expire; 863 ip4_frags.frag_expire = ip_expire;
863 inet_frags_init(&ip4_frags); 864 ip4_frags.frags_cache_name = ip_frag_cache_name;
865 if (inet_frags_init(&ip4_frags))
866 panic("IP: failed to allocate ip4_frags cache\n");
864} 867}