Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

netfilter: flowtable: dedicated slab for flow entry

The size of `struct flow_offload` has grown beyond 256 bytes on 64-bit
kernels (currently 280 bytes) because of the `flow_offload_tunnel`
member added recently. So kmalloc() allocates from the kmalloc-512 slab,
causing significant memory waste per entry.

Introduce a dedicated slab cache for flow entries to reduce memory
footprint. Results in a reduction from 512 bytes to 320 bytes per entry
on x86_64 kernels.

Signed-off-by: Qingfang Deng <dqfext@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>

authored by

Qingfang Deng and committed by
Florian Westphal
2a441a9a 59ecffa3

+10 -2
+10 -2
net/netfilter/nf_flow_table_core.c
··· 16 16 17 17 static DEFINE_MUTEX(flowtable_lock); 18 18 static LIST_HEAD(flowtables); 19 + static __read_mostly struct kmem_cache *flow_offload_cachep; 19 20 20 21 static void 21 22 flow_offload_fill_dir(struct flow_offload *flow, ··· 57 56 if (unlikely(nf_ct_is_dying(ct))) 58 57 return NULL; 59 58 60 - flow = kzalloc(sizeof(*flow), GFP_ATOMIC); 59 + flow = kmem_cache_zalloc(flow_offload_cachep, GFP_ATOMIC); 61 60 if (!flow) 62 61 return NULL; 63 62 ··· 813 812 { 814 813 int ret; 815 814 815 + flow_offload_cachep = KMEM_CACHE(flow_offload, SLAB_HWCACHE_ALIGN); 816 + if (!flow_offload_cachep) 817 + return -ENOMEM; 818 + 816 819 ret = register_pernet_subsys(&nf_flow_table_net_ops); 817 820 if (ret < 0) 818 - return ret; 821 + goto out_pernet; 819 822 820 823 ret = nf_flow_table_offload_init(); 821 824 if (ret) ··· 835 830 nf_flow_table_offload_exit(); 836 831 out_offload: 837 832 unregister_pernet_subsys(&nf_flow_table_net_ops); 833 + out_pernet: 834 + kmem_cache_destroy(flow_offload_cachep); 838 835 return ret; 839 836 } 840 837 ··· 844 837 { 845 838 nf_flow_table_offload_exit(); 846 839 unregister_pernet_subsys(&nf_flow_table_net_ops); 840 + kmem_cache_destroy(flow_offload_cachep); 847 841 } 848 842 849 843 module_init(nf_flow_table_module_init);