* [PATCH nft] evaluate: use chain hashtable for lookups
@ 2021-04-01 11:37 Pablo Neira Ayuso
0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2021-04-01 11:37 UTC (permalink / raw)
To: netfilter-devel
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH nft] evaluate: use chain hashtable for lookups
@ 2021-04-01 11:40 Pablo Neira Ayuso
0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2021-04-01 11:40 UTC (permalink / raw)
To: netfilter-devel
Instead of the linear list lookup.
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-04-01 18:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-01 11:40 [PATCH nft] evaluate: use chain hashtable for lookups Pablo Neira Ayuso
-- strict thread matches above, loose matches on Subject: below --
2021-04-01 11:37 Pablo Neira Ayuso
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).