Skip to content

netfilter: nf_tables: reduce transaction log memory usage

Florian Westphal netfilter-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest11 patches 8 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/11netfilter: nf_tables: make struct nft_trans first member of derived subtypesinclude/net/netfilter/nf_tables.h net/netfilter/nf_tables_api.c+54 -442 replies
2/11netfilter: nf_tables: move bind list_head into relevant subtypesinclude/net/netfilter/nf_tables.h net/netfilter/nf_tables_api.c+88 -326 replies
3/11netfilter: nf_tables: compact chain+ft transaction objectsinclude/net/netfilter/nf_tables.h+2 -20 replies
4/11netfilter: nf_tables: reduce trans->ctx.table referencesnet/netfilter/nf_tables_api.c+41 -380 replies
5/11netfilter: nf_tables: pass nft_chain to destroy function, not nft_ctxinclude/net/netfilter/nf_tables.h net/netfilter/nf_tables_api.c net/netfilter/nft_immediate.c+10 -110 replies
6/11netfilter: nf_tables: pass more specific nft_trans_chain where possiblenet/netfilter/nf_tables_api.c+26 -250 replies
7/11netfilter: nf_tables: avoid usage of embedded nft_ctxnet/netfilter/nf_tables_api.c net/netfilter/nf_tables_offload.c+13 -130 replies
8/11netfilter: nf_tables: store chain pointer in rule transactioninclude/net/netfilter/nf_tables.h net/netfilter/nf_tables_api.c net/netfilter/nf_tables_offload.c+22 -180 replies
9/11netfilter: nf_tables: reduce trans->ctx.chain referencesnet/netfilter/nf_tables_api.c+7 -90 replies
10/11netfilter: nf_tables: pass nft_table to destroy functionnet/netfilter/nf_tables_api.c+9 -90 replies
11/11netfilter: nf_tables: do not store nft_ctx in transaction objectsinclude/net/netfilter/nf_tables.h net/netfilter/nf_tables_api.c net/netfilter/nf_tables_offload.c+125 -660 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH nf-next 00/11] netfilter: nf_tables: reduce transaction log memory usage

The transaction log can grow to huge values.
Insertion of 1.000.000 elements into a set, or flushing a set with 1.000.000 elements will eat 128 byte per element, i.e. 128 MiBi.

This series compacts the structures. After this series, struct nft_trans_elem can be allocated from kmalloc-96 slab, resulting in a 25% memory reduction.

To further reduce flush/mass-insert several approaches come to mind:

1. allow struct nft_trans_elem to hold several elements.
2. add a kernel-internal, dedicated nft_trans_elem_batch that is only used for flushing (similar to 1).
3. Remove 'struct net' from nft_trans struct. This reduces size of nft_trans_elem to 64 bytes, which would halve memory needs compared to the current state.

I have tried to do 3), its possible but not very elegant.

You can have a look at the general idea at
https://git.kernel.org/pub/scm/linux/kernel/git/fwestphal/nf-next.git/commit/?h=nft_trans_compact_01&id=5269e591563204490b9fad6ae1e33810a9f4c39d

I have started to look at 1) too, but unlike this compaction series it looks like this will make things even more complex as we'll need to be careful wrt. appending more set elements to an already-queued nft_trans_elem (must be same msg_type, same set, etc).

This series has seen brief testing with kasan+kmemleak and nftables.git selftests.

Feedback and comments welcome.

Florian Westphal (11):
netfilter: nf_tables: make struct nft_trans first member of derived subtypes
netfilter: nf_tables: move bind list_head into relevant subtypes
netfilter: nf_tables: compact chain+ft transaction objects
netfilter: nf_tables: reduce trans->ctx.table references
netfilter: nf_tables: pass nft_chain to destroy function, not nft_ctx
netfilter: nf_tables: pass more specific nft_trans_chain where possible
netfilter: nf_tables: avoid usage of embedded nft_ctx
netfilter: nf_tables: store chain pointer in rule transaction
netfilter: nf_tables: reduce trans->ctx.chain references
netfilter: nf_tables: pass nft_table to destroy function
netfilter: nf_tables: do not store nft_ctx in transaction objects

 include/net/netfilter/nf_tables.h | 152 +++++++----
 net/netfilter/nf_tables_api.c     | 402 +++++++++++++++++-------------
 net/netfilter/nf_tables_offload.c |  40 +--
 net/netfilter/nft_immediate.c     |   2 +-
 4 files changed, 363 insertions(+), 233 deletions(-)
Signature · 1 line
2.43.2