netfilter: nf_tables: switch trans_elem to real flex array
authorFlorian Westphal <fw@strlen.de>
Wed, 13 Nov 2024 15:35:52 +0000 (16:35 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 14 Nov 2024 11:40:55 +0000 (12:40 +0100)
commitb0c49466043a4878d8ef1263a4c9020698958a4c
treec359f0f83163d2dc14364d56da62d2ff09900184
parent466c9b3b2a92602360e9fa25943b8aa191122dfc
netfilter: nf_tables: switch trans_elem to real flex array

When queueing a set element add or removal operation to the transaction
log, check if the previous operation already asks for a the identical
operation on the same set.

If so, store the element reference in the preceding operation.
This significantlty reduces memory consumption when many set add/delete
operations appear in a single transaction.

Example: 10k elements require 937kb of memory (10k allocations from
kmalloc-96 slab).

Assuming we can compact 4 elements in the same set, 468 kbytes
are needed (64 bytes for base struct, nft_trans_elemn, 32 bytes
for nft_trans_one_elem structure, so 2500 allocations from kmalloc-192
slab).

For large batch updates we can compact up to 62 elements
into one single nft_trans_elem structure (~65% mem reduction):
(64 bytes for base struct, nft_trans_elem, 32 byte for nft_trans_one_elem
 struct).

We can halve size of nft_trans_one_elem struct by moving
timeout/expire/update_flags into a dynamically allocated structure,
this allows to store 124 elements in a 2k slab nft_trans_elem struct.
This is done in a followup patch.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/nf_tables_api.c