From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nft] evaluate: use chain hashtable for lookups
Date: Thu, 1 Apr 2021 13:37:32 +0200 [thread overview]
Message-ID: <20210401113732.8328-1-pablo@netfilter.org> (raw)
Instead of the linear list.
Before this patch:
real 0m21,735s
user 0m20,329s
sys 0m1,384s
After:
real 0m10,910s
user 0m9,448s
sys 0m1,434s
This patch requires a small adjust: Allocate a clone of the existing
chain in the cache, instead of recycling the object to avoid a list
corruption.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/evaluate.c | 15 ++++++++++-----
src/rule.c | 2 +-
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/src/evaluate.c b/src/evaluate.c
index cebf7cb8ef2c..5f64979453ad 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -4106,15 +4106,20 @@ static int chain_evaluate(struct eval_ctx *ctx, struct chain *chain)
return table_not_found(ctx);
if (chain == NULL) {
- if (chain_lookup(table, &ctx->cmd->handle) == NULL) {
+ if (chain_cache_find(table, &ctx->cmd->handle) == NULL) {
chain = chain_alloc(NULL);
handle_merge(&chain->handle, &ctx->cmd->handle);
chain_cache_add(chain, table);
}
return 0;
} else if (!(chain->flags & CHAIN_F_BINDING)) {
- if (chain_lookup(table, &chain->handle) == NULL)
- chain_cache_add(chain_get(chain), table);
+ if (chain_cache_find(table, &chain->handle) == NULL) {
+ struct chain *newchain;
+
+ newchain = chain_alloc(NULL);
+ handle_merge(&newchain->handle, &chain->handle);
+ chain_cache_add(newchain, table);
+ }
}
if (chain->flags & CHAIN_F_BASECHAIN) {
@@ -4440,7 +4445,7 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)
if (table == NULL)
return table_not_found(ctx);
- if (chain_lookup(table, &cmd->handle) == NULL)
+ if (chain_cache_find(table, &cmd->handle) == NULL)
return chain_not_found(ctx);
return 0;
@@ -4600,7 +4605,7 @@ static int cmd_evaluate_rename(struct eval_ctx *ctx, struct cmd *cmd)
if (table == NULL)
return table_not_found(ctx);
- if (chain_lookup(table, &ctx->cmd->handle) == NULL)
+ if (chain_cache_find(table, &ctx->cmd->handle) == NULL)
return chain_not_found(ctx);
break;
diff --git a/src/rule.c b/src/rule.c
index 969318008933..4f1ca22ec9e7 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -2621,7 +2621,7 @@ static int do_command_rename(struct netlink_ctx *ctx, struct cmd *cmd)
switch (cmd->obj) {
case CMD_OBJ_CHAIN:
- chain = chain_lookup(table, &cmd->handle);
+ chain = chain_cache_find(table, &cmd->handle);
return mnl_nft_chain_rename(ctx, cmd, chain);
default:
--
2.20.1
next reply other threads:[~2021-04-01 17:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-01 11:37 Pablo Neira Ayuso [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-04-01 11:40 [PATCH nft] evaluate: use chain hashtable for lookups Pablo Neira Ayuso
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=20210401113732.8328-1-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
/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).