netfilter: nf_tables: coalesce multiple notifications into one skbuff
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH v2 1/1 netfilter: nf_tables: coalesce multiple notifications into one skbuff
On x86_64, each notification results in one skbuff allocation which consumes at least 768 bytes due to the skbuff overhead.
This patch coalesces several notifications into one single skbuff, so each notification consumes at least ~211 bytes, that ~3.5 times less memory consumption. As a result, this is reducing the chances to exhaust the netlink socket receive buffer.
Rule of thumb is that each notification batch only contains netlink messages whose report flag is the same, nfnetlink_send() requires this to do appropriately delivery to userspace, either via unicast (echo mode) or multicast (monitor mode).
The skbuff control buffer is used to annotate the report flag for later handling at the new coalescing routine.
The batch skbuff notification size is NLMSG_GOODSIZE, using a larger skbuff would allow for more socket receiver buffer savings (to amortize the cost of the skbuff even more), however, going over that size might break userspace applications, so let's be conservative and stick to NLMSG_GOODSIZE.
---
v2: len = NLMSG_GOODSIZE - skb->len; reported by Phil Sutter.
include/net/netns/nftables.h | 1 + net/netfilter/nf_tables_api.c | 71 ++++++++++++++++++++++++++++------- 2 files changed, 59 insertions(+), 13 deletions(-)
include/net/netns/nftables.h +1 -0
@@ -8,6 +8,7 @@ struct netns_nftables {struct list_head tables;struct list_head commit_list;struct list_head module_list; +struct list_head notify_list;struct mutex commit_mutex;unsigned int base_seq;u8 gencursor;
net/netfilter/nf_tables_api.c +58 -13
143 lines not on this page · raw message
Signature · 1 line
2.20.1
Phil Sutter
reviewerOn Wed, Sep 02, 2020 at 04:52:02PM +0200, Pablo Neira Ayuso wrote:
[...]
net/netfilter/nf_tables_api.c static void nf_tables_commit_release(struct net *net) · line 7714
Quoted 11 lines
net/netfilter/nf_tables_api.c +11
-0+static void nft_commit_notify (struct net *net,u32 portid) +{ +struct sk_buff *batch_skb =NULL , *nskb, *skb; +unsigned char *data; +int len; + +list_for_each_entry_safe (skb, nskb, &net->nft.notify_list, list) { +if (!batch_skb) { +new_batch: + batch_skb = skb; +NFT_CB (batch_skb).report =NFT_CB (skb).report;
Is this assignment needed? NFT_CB() merely dereferences skb->cb, so after assigning 'batch_skb = skb', NFT_CB(batch_skb) == NFT_CB(skb), no?
(Sorry for the late complaint, I forgot about it until reviewing your v2.)
Cheers, Phil
Pablo Neira Ayuso
maintainerQuoted 16 lines · Phil Sutter
On Wed, Sep 02, 2020 at 04:52:02PM +0200, Pablo Neira Ayuso wrote:
[...]net/netfilter/nf_tables_api.c static void nf_tables_commit_release(struct net *net) · line 7714
Quoted 11 lines
net/netfilter/nf_tables_api.c +11
-0+static void nft_commit_notify (struct net *net,u32 portid) +{ +struct sk_buff *batch_skb =NULL , *nskb, *skb; +unsigned char *data; +int len; + +list_for_each_entry_safe (skb, nskb, &net->nft.notify_list, list) { +if (!batch_skb) { +new_batch: + batch_skb = skb; +NFT_CB (batch_skb).report =NFT_CB (skb).report;Is this assignment needed?
NFT_CB()merely dereferencesskb->cb, so after assigning 'batch_skb= skb',NFT_CB(batch_skb)==NFT_CB(skb), no?
That's right, thanks for reviewing.