From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: nhofmeyr@sysmocom.de
Subject: [PATCH nft 2/2,v2] cache: recycle existing cache with incremental updates
Date: Tue, 28 May 2024 17:28:17 +0200 [thread overview]
Message-ID: <20240528152817.856211-2-pablo@netfilter.org> (raw)
In-Reply-To: <20240528152817.856211-1-pablo@netfilter.org>
Cache tracking has improved over time by incrementally adding/deleting
objects when evaluating commands that are going to be sent to the kernel.
nft_cache_is_complete() already checks that the cache contains objects
that are required to handle this batch of commands by comparing cache
flags.
Infer from the current generation ID if no other transaction has
invalidated the existing cache, this allows to skip unnecessary cache
flush then refill situations which slow down incremental updates.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
v2: no changes
nft_slew.c provided by Neels (on Cc) show better numbers now after this
series.
src/cache.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/cache.c b/src/cache.c
index e88cbae2ad95..4b797ec79ae5 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -1184,9 +1184,21 @@ static bool nft_cache_needs_refresh(struct nft_cache *cache, unsigned int flags)
(flags & NFT_CACHE_REFRESH);
}
-static bool nft_cache_is_updated(struct nft_cache *cache, uint16_t genid)
+static bool nft_cache_is_updated(struct nft_cache *cache, unsigned int flags,
+ uint16_t genid)
{
- return genid && genid == cache->genid;
+ if (!genid)
+ return false;
+
+ if (genid == cache->genid)
+ return true;
+
+ if (genid == cache->genid + 1) {
+ cache->genid++;
+ return true;
+ }
+
+ return false;
}
bool nft_cache_needs_update(struct nft_cache *cache)
@@ -1211,7 +1223,7 @@ replay:
genid = mnl_genid_get(&ctx);
if (!nft_cache_needs_refresh(cache, flags) &&
nft_cache_is_complete(cache, flags) &&
- nft_cache_is_updated(cache, genid))
+ nft_cache_is_updated(cache, flags, genid))
return 0;
if (cache->genid)
--
2.30.2
next prev parent reply other threads:[~2024-05-28 15:28 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-28 15:28 [PATCH nft 1/2,v2] cache: check for NFT_CACHE_REFRESH in current requested cache too Pablo Neira Ayuso
2024-05-28 15:28 ` Pablo Neira Ayuso [this message]
2024-07-22 20:48 ` [PATCH nft 2/2,v2] cache: recycle existing cache with incremental updates Eric Garver
2024-07-22 21:34 ` Pablo Neira Ayuso
2024-07-23 5:29 ` Phil Sutter
2024-07-23 11:56 ` Phil Sutter
2024-07-23 12:19 ` Pablo Neira Ayuso
2024-07-23 12:57 ` Pablo Neira Ayuso
2024-07-23 15:09 ` Phil Sutter
2024-07-24 7:51 ` Pablo Neira Ayuso
2024-07-23 14:34 ` Phil Sutter
2024-07-23 19:30 ` Eric Garver
2024-07-23 20:56 ` Phil Sutter
2024-07-24 7:44 ` Pablo Neira Ayuso
2024-07-24 11:51 ` Eric Garver
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240528152817.856211-2-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=nhofmeyr@sysmocom.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).