evaluate: use chain hashtable for lookups
Pablo Neira Ayuso
maintainerPATCH 1/1 evaluate: use chain hashtable for lookups
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 <[email protected]>
--- src/evaluate.c | 15 ++++++++++----- src/rule.c | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-)
src/evaluate.c +10 -5
@@ -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 ;
src/rule.c +1 -1
@@ -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 :
Signature · 1 line
2.20.1