Skip to content

Commit 2a441a9

Browse files
LGA1150Florian Westphal
authored andcommitted
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>
1 parent 59ecffa commit 2a441a9

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

net/netfilter/nf_flow_table_core.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
static DEFINE_MUTEX(flowtable_lock);
1818
static LIST_HEAD(flowtables);
19+
static __read_mostly struct kmem_cache *flow_offload_cachep;
1920

2021
static void
2122
flow_offload_fill_dir(struct flow_offload *flow,
@@ -56,7 +57,7 @@ struct flow_offload *flow_offload_alloc(struct nf_conn *ct)
5657
if (unlikely(nf_ct_is_dying(ct)))
5758
return NULL;
5859

59-
flow = kzalloc(sizeof(*flow), GFP_ATOMIC);
60+
flow = kmem_cache_zalloc(flow_offload_cachep, GFP_ATOMIC);
6061
if (!flow)
6162
return NULL;
6263

@@ -812,9 +813,13 @@ static int __init nf_flow_table_module_init(void)
812813
{
813814
int ret;
814815

816+
flow_offload_cachep = KMEM_CACHE(flow_offload, SLAB_HWCACHE_ALIGN);
817+
if (!flow_offload_cachep)
818+
return -ENOMEM;
819+
815820
ret = register_pernet_subsys(&nf_flow_table_net_ops);
816821
if (ret < 0)
817-
return ret;
822+
goto out_pernet;
818823

819824
ret = nf_flow_table_offload_init();
820825
if (ret)
@@ -830,13 +835,16 @@ static int __init nf_flow_table_module_init(void)
830835
nf_flow_table_offload_exit();
831836
out_offload:
832837
unregister_pernet_subsys(&nf_flow_table_net_ops);
838+
out_pernet:
839+
kmem_cache_destroy(flow_offload_cachep);
833840
return ret;
834841
}
835842

836843
static void __exit nf_flow_table_module_exit(void)
837844
{
838845
nf_flow_table_offload_exit();
839846
unregister_pernet_subsys(&nf_flow_table_net_ops);
847+
kmem_cache_destroy(flow_offload_cachep);
840848
}
841849

842850
module_init(nf_flow_table_module_init);

0 commit comments

Comments
 (0)