Skip to content

Commit e169285

Browse files
Florian Westphalummakynes
Florian Westphal
authored andcommitted
netfilter: nf_tables: do not store nft_ctx in transaction objects
nft_ctx is huge and most of the information stored within isn't used at all. Remove nft_ctx member from the base transaction structure and store only what is needed. After this change, relevant struct sizes are: struct nft_trans_chain { /* size: 120 (-32), cachelines: 2, members: 10 */ struct nft_trans_elem { /* size: 72 (-40), cachelines: 2, members: 4 */ struct nft_trans_flowtable { /* size: 80 (-48), cachelines: 2, members: 5 */ struct nft_trans_obj { /* size: 72 (-40), cachelines: 2, members: 4 */ struct nft_trans_rule { /* size: 80 (-32), cachelines: 2, members: 6 */ struct nft_trans_set { /* size: 96 (-24), cachelines: 2, members: 8 */ struct nft_trans_table { /* size: 56 (-40), cachelines: 1, members: 2 */ struct nft_trans_elem can now be allocated from kmalloc-96 instead of kmalloc-128 slab. A further reduction by 8 bytes would even allow for kmalloc-64. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 0be9087 commit e169285

File tree

3 files changed

+125
-66
lines changed

3 files changed

+125
-66
lines changed

include/net/netfilter/nf_tables.h

+39-4
Original file line numberDiff line numberDiff line change
@@ -1611,18 +1611,26 @@ static inline int nft_set_elem_is_dead(const struct nft_set_ext *ext)
16111611
* struct nft_trans - nf_tables object update in transaction
16121612
*
16131613
* @list: used internally
1614+
* @net: struct net
1615+
* @table: struct nft_table the object resides in
16141616
* @msg_type: message type
1615-
* @put_net: ctx->net needs to be put
1616-
* @ctx: transaction context
1617+
* @seq: netlink sequence number
1618+
* @flags: modifiers to new request
1619+
* @report: notify via unicast netlink message
1620+
* @put_net: net needs to be put
16171621
*
16181622
* This is the information common to all objects in the transaction,
16191623
* this must always be the first member of derived sub-types.
16201624
*/
16211625
struct nft_trans {
16221626
struct list_head list;
1627+
struct net *net;
1628+
struct nft_table *table;
16231629
int msg_type;
1624-
bool put_net;
1625-
struct nft_ctx ctx;
1630+
u32 seq;
1631+
u16 flags;
1632+
u8 report:1;
1633+
u8 put_net:1;
16261634
};
16271635

16281636
/**
@@ -1794,6 +1802,33 @@ struct nft_trans_gc {
17941802
struct rcu_head rcu;
17951803
};
17961804

1805+
static inline void nft_ctx_update(struct nft_ctx *ctx,
1806+
const struct nft_trans *trans)
1807+
{
1808+
switch (trans->msg_type) {
1809+
case NFT_MSG_NEWRULE:
1810+
case NFT_MSG_DELRULE:
1811+
case NFT_MSG_DESTROYRULE:
1812+
ctx->chain = nft_trans_rule_chain(trans);
1813+
break;
1814+
case NFT_MSG_NEWCHAIN:
1815+
case NFT_MSG_DELCHAIN:
1816+
case NFT_MSG_DESTROYCHAIN:
1817+
ctx->chain = nft_trans_chain(trans);
1818+
break;
1819+
default:
1820+
ctx->chain = NULL;
1821+
break;
1822+
}
1823+
1824+
ctx->net = trans->net;
1825+
ctx->table = trans->table;
1826+
ctx->family = trans->table->family;
1827+
ctx->report = trans->report;
1828+
ctx->flags = trans->flags;
1829+
ctx->seq = trans->seq;
1830+
}
1831+
17971832
struct nft_trans_gc *nft_trans_gc_alloc(struct nft_set *set,
17981833
unsigned int gc_seq, gfp_t gfp);
17991834
void nft_trans_gc_destroy(struct nft_trans_gc *trans);

0 commit comments

Comments
 (0)