Skip to content

Commit 0e1ea65

Browse files
committed
netfilter: nf_tables: shrink memory consumption of set elements
Instead of copying struct nft_set_elem into struct nft_trans_elem, store the pointer to the opaque set element object in the transaction. Adapt set backend API (and set backend implementations) to take the pointer to opaque set element representation whenever required. This patch deconstifies .remove() and .activate() set backend API since these modify the set element opaque object. And it also constify nft_set_elem_ext() this provides access to the nft_set_ext struct without updating the object. According to pahole on x86_64, this patch shrinks struct nft_trans_elem size from 216 to 24 bytes. This patch also reduces stack memory consumption by removing the template struct nft_set_elem object, using the opaque set element object instead such as from the set iterator API, catchall elements and the get element command. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 9dad402 commit 0e1ea65

File tree

6 files changed

+116
-160
lines changed

6 files changed

+116
-160
lines changed

include/net/netfilter/nf_tables.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ struct nft_set_iter {
314314
int (*fn)(const struct nft_ctx *ctx,
315315
struct nft_set *set,
316316
const struct nft_set_iter *iter,
317-
struct nft_set_elem *elem);
317+
struct nft_elem_priv *elem_priv);
318318
};
319319

320320
/**
@@ -454,7 +454,7 @@ struct nft_set_ops {
454454
struct nft_set_ext **ext);
455455
void (*activate)(const struct net *net,
456456
const struct nft_set *set,
457-
const struct nft_set_elem *elem);
457+
struct nft_elem_priv *elem_priv);
458458
struct nft_elem_priv * (*deactivate)(const struct net *net,
459459
const struct nft_set *set,
460460
const struct nft_set_elem *elem);
@@ -463,7 +463,7 @@ struct nft_set_ops {
463463
struct nft_elem_priv *priv);
464464
void (*remove)(const struct net *net,
465465
const struct nft_set *set,
466-
const struct nft_set_elem *elem);
466+
struct nft_elem_priv *elem_priv);
467467
void (*walk)(const struct nft_ctx *ctx,
468468
struct nft_set *set,
469469
struct nft_set_iter *iter);
@@ -1073,7 +1073,7 @@ struct nft_chain {
10731073
int nft_chain_validate(const struct nft_ctx *ctx, const struct nft_chain *chain);
10741074
int nft_setelem_validate(const struct nft_ctx *ctx, struct nft_set *set,
10751075
const struct nft_set_iter *iter,
1076-
struct nft_set_elem *elem);
1076+
struct nft_elem_priv *elem_priv);
10771077
int nft_set_catchall_validate(const struct nft_ctx *ctx, struct nft_set *set);
10781078
int nf_tables_bind_chain(const struct nft_ctx *ctx, struct nft_chain *chain);
10791079
void nf_tables_unbind_chain(const struct nft_ctx *ctx, struct nft_chain *chain);
@@ -1650,14 +1650,14 @@ struct nft_trans_table {
16501650

16511651
struct nft_trans_elem {
16521652
struct nft_set *set;
1653-
struct nft_set_elem elem;
1653+
struct nft_elem_priv *elem_priv;
16541654
bool bound;
16551655
};
16561656

16571657
#define nft_trans_elem_set(trans) \
16581658
(((struct nft_trans_elem *)trans->data)->set)
1659-
#define nft_trans_elem(trans) \
1660-
(((struct nft_trans_elem *)trans->data)->elem)
1659+
#define nft_trans_elem_priv(trans) \
1660+
(((struct nft_trans_elem *)trans->data)->elem_priv)
16611661
#define nft_trans_elem_set_bound(trans) \
16621662
(((struct nft_trans_elem *)trans->data)->bound)
16631663

@@ -1698,7 +1698,7 @@ struct nft_trans_gc {
16981698
struct nft_set *set;
16991699
u32 seq;
17001700
u16 count;
1701-
void *priv[NFT_TRANS_GC_BATCHCOUNT];
1701+
struct nft_elem_priv *priv[NFT_TRANS_GC_BATCHCOUNT];
17021702
struct rcu_head rcu;
17031703
};
17041704

@@ -1721,7 +1721,7 @@ struct nft_trans_gc *nft_trans_gc_catchall_sync(struct nft_trans_gc *gc);
17211721

17221722
void nft_setelem_data_deactivate(const struct net *net,
17231723
const struct nft_set *set,
1724-
struct nft_set_elem *elem);
1724+
struct nft_elem_priv *elem_priv);
17251725

17261726
int __init nft_chain_filter_init(void);
17271727
void nft_chain_filter_fini(void);

0 commit comments

Comments
 (0)