Enhance cache filter for list commands
Phil Sutter
reviewercover Enhance cache filter for list commands
Reducing the amount of data fetched from kernel improves performance with large rule sets but also reduces adverse side-effects if multiple versions of nftables access the same kernel rule set. Being able to ignore parts of the rule set one is not interested in allows for (more or less) safe coexistence if each tool is operating on the data it created itself only.
This series reduces caching for list commands which specify a family and/or table. To help testing this, patch 1 extends netlink debug output to include chains, flowtables and objects so a test case may check if they are fetched or not.
The remaining patches actually increase filter use.
Phil Sutter (5):
cache: Include chains, flowtables and objects in netlink debug output
cache: Respect family in all list commands
cache: Relax chain_cache_dump filter application
cache: Filter for table when listing sets or maps
cache: Filter for table when listing flowtables
src/cache.c | 11 ++-- src/mnl.c | 60 ++++++++++++++++++--- tests/shell/testcases/listing/cache_filters | 53 ++++++++++++++++++ 3 files changed, 113 insertions(+), 11 deletions(-) create mode 100755 tests/shell/testcases/listing/cache_filters
Signature · 1 line
2.51.0
Phil Sutter
reviewerPATCH 1/5 cache: Include chains, flowtables and objects in netlink debug output
In order to test cache filter effectiveness, netlink debug output is useful as it shows what is actually received from the kernel and maybe discarded immediately by user space. Therefore add dump calls for these rule set elements as well.
While at it, move the netlink_dump_rule() call to an earlier spot, namely into the nft_mnl_talk() callback to match other netlink dump calls.
--- src/cache.c | 1 - src/mnl.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 9 deletions(-)
src/cache.c +0 -1
@@ -698,7 +698,6 @@ static int list_rule_cb(struct nftnl_rule *nlr, void *data) (h->chain.name && strcmp(chain, h->chain.name) != 0))return 0 ; -netlink_dump_rule (nlr, ctx); rule =netlink_delinearize_rule (ctx, nlr);assert (rule);list_add_tail (&rule->list, &ctx->list);
src/mnl.c +52 -8
164 lines not on this page · raw message
Signature · 1 line
2.51.0
Phil Sutter
reviewerPATCH 2/5 cache: Respect family in all list commands
In reply to Phil SutterSome list commands did not set filter->list.family even if one was given on command line, fix this.
--- src/cache.c | 6 ++- tests/shell/testcases/listing/cache_filters | 46 +++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100755 tests/shell/testcases/listing/cache_filters
src/cache.c +5 -1
@@ -246,10 +246,12 @@ static unsigned int evaluate_cache_list(struct nft_ctx *nft, struct cmd *cmd, flags |=NFT_CACHE_FULL ;break ;case CMD_OBJ_CHAINS : + filter->list.family = cmd->handle.family; flags |=NFT_CACHE_TABLE |NFT_CACHE_CHAIN ;break ;case CMD_OBJ_SETS :case CMD_OBJ_MAPS : + filter->list.family = cmd->handle.family; flags |=NFT_CACHE_TABLE |NFT_CACHE_SET ;if (!nft_output_terse (&nft->output)) flags |=NFT_CACHE_SETELEM ;
@@ -257,12 +259,12 @@ static unsigned int evaluate_cache_list(struct nft_ctx *nft, struct cmd *cmd,case CMD_OBJ_FLOWTABLE :if (cmd->handle.table.name && cmd->handle.flowtable.name) { - filter->list.family = cmd->handle.family; filter->list.table = cmd->handle.table.name; filter->list.ft = cmd->handle.flowtable.name; }/* fall through */ case CMD_OBJ_FLOWTABLES : + filter->list.family = cmd->handle.family; flags |=NFT_CACHE_TABLE |NFT_CACHE_FLOWTABLE ;break ;case CMD_OBJ_COUNTER :
@@ -301,6 +303,8 @@ static unsigned int evaluate_cache_list(struct nft_ctx *nft, struct cmd *cmd,obj_filter_setup (cmd, &flags, filter,NFT_OBJECT_TUNNEL );break ;case CMD_OBJ_RULESET : + filter->list.family = cmd->handle.family; +/* fall through */ default : flags |=NFT_CACHE_FULL ;break ;
tests/shell/testcases/listing/cache_filters new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.51.0
Re: [nft PATCH 2/5] cache: Respect family in all list commands
Quoted 3 lines · Phil Sutter
Some list commands did not set
filter->list.familyeven if one was given on command line, fix this.
Quoted 1 line
Signed-off-by Phil Sutter <[email protected]>
Phil Sutter
reviewerRe: [nft PATCH 2/5] cache: Respect family in all list commands
Quoted 6 lines · Pablo Neira Ayuso
Quoted 3 lines · Phil Sutter
Some list commands did not set
filter->list.familyeven if one was given on command line, fix this.Fixes a1a6b0a5c3c4 ("cache: finer grain cache population for list commands")
Hmm. At that point, we didn't have 'filter' parameter in evaluate_cache_list(). Struct nft_cache_filter was introduced later, in commit 3f1d3912c3a6b ("cache: filter out tables that are not requested").
Assuming that Fixes: tags are used for semi-automated backporting (at least I do ;), pointing at that commit will cause trouble.
Do you still think we should add that tag?
Quoted 3 lines
Quoted 1 line
Signed-off-by Phil Sutter <[email protected]>Reviewed-by Pablo Neira Ayuso <[email protected]>
Thanks for reviewing!
Pablo Neira Ayuso
maintainerRe: [nft PATCH 2/5] cache: Respect family in all list commands
Quoted 8 lines · Phil Sutter
Quoted 6 lines · Pablo Neira Ayuso
Quoted 3 lines · Phil Sutter
Some list commands did not set
filter->list.familyeven if one was given on command line, fix this.Fixes a1a6b0a5c3c4 ("cache: finer grain cache population for list commands")
Quoted 7 lines
Hmm. At that point, we didn't have 'filter' parameter in
evaluate_cache_list(). Structnft_cache_filterwas introduced later, in commit3f1d3912c3a6b("cache: filter out tables that are not requested").Assuming that Fixes: tags are used for semi-automated backporting (at least I do ;), pointing at that commit will cause trouble.
Good point.
Helping identify backporting in a semi-automated way is good, specially for small fixes like this.
At least for me, it helps me identify if it is an update/enhancement/feature or fix, it is just a bit more context information.
Quoted 1 line
Do you still think we should add that tag?
I get your point that tags need to be right if we use them.
Phil Sutter
reviewerRe: [nft PATCH 2/5] cache: Respect family in all list commands
Quoted 22 lines · Pablo Neira Ayuso
Quoted 8 lines · Phil Sutter
Quoted 6 lines · Pablo Neira Ayuso
Quoted 3 lines · Phil Sutter
Some list commands did not set
filter->list.familyeven if one was given on command line, fix this.Fixes a1a6b0a5c3c4 ("cache: finer grain cache population for list commands")Quoted 7 lines
Hmm. At that point, we didn't have 'filter' parameter in
evaluate_cache_list(). Structnft_cache_filterwas introduced later, in commit3f1d3912c3a6b("cache: filter out tables that are not requested").Assuming that Fixes: tags are used for semi-automated backporting (at least I do ;), pointing at that commit will cause trouble.
Good point.
Helping identify backporting in a semi-automated way is good, specially for small fixes like this.
Quoted 7 lines
At least for me, it helps me identify if it is an update/enhancement/feature or fix, it is just a bit more context information.
Quoted 1 line
Do you still think we should add that tag?
I get your point that tags need to be right if we use them.
How about:
Phil Sutter
reviewerPATCH 3/5 cache: Relax chain_cache_dump filter application
In reply to Phil SutterWhile populating chain cache, a filter was only effective if it limited fetching to both a table and a chain. Make it apply to 'list chains' command as well which at most specifies a family and table.
Since the code is OK with filter->list fields being NULL, merely check for filter to be non-NULL (which is the case if nft_cache_update() is called by nft_cmd_enoent_chain()).
--- src/cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/cache.c +1 -1
@@ -625,7 +625,7 @@ chain_cache_dump(struct netlink_ctx *ctx,const char *chain =NULL ;int family =NFPROTO_UNSPEC ; -if (filter && filter->list.table && filter->list.chain) { +if (filter) { family = filter->list.family; table = filter->list.table; chain = filter->list.chain;
Signature · 1 line
2.51.0
Re: [nft PATCH 3/5] cache: Relax chain_cache_dump filter application
Quoted 7 lines · Phil Sutter
While populating chain cache, a filter was only effective if it limited fetching to both a table and a chain. Make it apply to 'list chains' command as well which at most specifies a family and table.
Since the code is OK with
filter->listfields being NULL, merely check for filter to be non-NULL (which is the case ifnft_cache_update()is called bynft_cmd_enoent_chain()).
Quoted 1 line
Signed-off-by Phil Sutter <[email protected]>
Phil Sutter
reviewerPATCH 4/5 cache: Filter for table when listing sets or maps
In reply to Phil SutterRespect an optionally specified table name to filter listed sets or maps to by populating the filter accordingly.
--- src/cache.c | 1 + tests/shell/testcases/listing/cache_filters | 4 ++++ 2 files changed, 5 insertions(+)
src/cache.c +1 -0
@@ -252,6 +252,7 @@ static unsigned int evaluate_cache_list(struct nft_ctx *nft, struct cmd *cmd,case CMD_OBJ_SETS :case CMD_OBJ_MAPS : filter->list.family = cmd->handle.family; + filter->list.table = cmd->handle.table.name; flags |=NFT_CACHE_TABLE |NFT_CACHE_SET ;if (!nft_output_terse (&nft->output)) flags |=NFT_CACHE_SETELEM ;
tests/shell/testcases/listing/cache_filters +4 -0
@@ -22,6 +22,8 @@ table ip ip_t { chain ip_t_c2 { } } +table ip ip_t2 { +} EOF $NFT --debug=netlink list ruleset | \
@@ -38,6 +40,8 @@ $NFT --debug=netlink list sets | \ grep -q 'family 2 ip_t_s ip_t' || fail "broken list sets" $NFT --debug=netlink list sets ip6 | \ grep -q 'family 2 ip_t_s ip_t' && fail "broken list sets family filter" +$NFT --debug=netlink list sets ip ip_t2 | \ + grep -q 'family 2 ip_t_s ip_t' && fail "broken list sets table filter" $NFT --debug=netlink list flowtables | \ grep -q 'flow table ip_t ip_t_ft' || fail "broken list flowtables"
Signature · 1 line
2.51.0
Re: [nft PATCH 4/5] cache: Filter for table when listing sets or maps
Quoted 3 lines · Phil Sutter
Respect an optionally specified table name to filter listed sets or maps to by populating the filter accordingly.
Quoted 1 line
Signed-off-by Phil Sutter <[email protected]>
Phil Sutter
reviewerPATCH 5/5 cache: Filter for table when listing flowtables
In reply to Phil SutterRespect an optionally specified table name to filter listed flowtables to by populating the filter accordingly.
--- src/cache.c | 1 + tests/shell/testcases/listing/cache_filters | 3 +++ 2 files changed, 4 insertions(+)
src/cache.c +1 -0
@@ -266,6 +266,7 @@ static unsigned int evaluate_cache_list(struct nft_ctx *nft, struct cmd *cmd,/* fall through */ case CMD_OBJ_FLOWTABLES : filter->list.family = cmd->handle.family; + filter->list.table = cmd->handle.table.name; flags |=NFT_CACHE_TABLE |NFT_CACHE_FLOWTABLE ;break ;case CMD_OBJ_COUNTER :
tests/shell/testcases/listing/cache_filters +3 -0
@@ -47,4 +47,7 @@ $NFT --debug=netlink list flowtables | \ grep -q 'flow table ip_t ip_t_ft' || fail "broken list flowtables" $NFT --debug=netlink list flowtables ip6 | \ grep -q 'flow table ip_t ip_t_ft' && fail "broken list flowtables family filter" +$NFT --debug=netlink list flowtables ip ip_t2 | \ + grep -q 'flow table ip_t ip_t_ft' && fail "broken list flowtables table filter" + exit 0
Signature · 1 line
2.51.0
Re: [nft PATCH 5/5] cache: Filter for table when listing flowtables
Quoted 2 lines · Phil Sutter
Respect an optionally specified table name to filter listed flowtables to by populating the filter accordingly.
Quoted 1 line
Signed-off-by Phil Sutter <[email protected]>
Quoted 21 lines · Phil Sutter
Reducing the amount of data fetched from kernel improves performance with large rule sets but also reduces adverse side-effects if multiple versions of nftables access the same kernel rule set. Being able to ignore parts of the rule set one is not interested in allows for (more or less) safe coexistence if each tool is operating on the data it created itself only.
This series reduces caching for list commands which specify a family and/or table. To help testing this, patch 1 extends netlink debug output to include chains, flowtables and objects so a test case may check if they are fetched or not.
The remaining patches actually increase filter use.
Phil Sutter (5):
cache: Include chains, flowtables and objects in netlink debug output
cache: Respect family in all list commands
cache: Relaxchain_cache_dumpfilter application
cache: Filter for table when listing sets or maps
cache: Filter for table when listing flowtables
Quoted 5 lines
src/cache.c | 11 ++-- src/mnl.c | 60 ++++++++++++++++++--- tests/shell/testcases/listing/cache_filters | 53 ++++++++++++++++++ 3 files changed, 113 insertions(+), 11 deletions(-) create mode 100755 tests/shell/testcases/listing/cache_filters
I ran this series against the firewalld testsuite. All green. Thanks Phil!
For the series:
Phil Sutter
reviewerQuoted 22 lines · Eric Garver
Quoted 21 lines · Phil Sutter
Reducing the amount of data fetched from kernel improves performance with large rule sets but also reduces adverse side-effects if multiple versions of nftables access the same kernel rule set. Being able to ignore parts of the rule set one is not interested in allows for (more or less) safe coexistence if each tool is operating on the data it created itself only.
This series reduces caching for list commands which specify a family and/or table. To help testing this, patch 1 extends netlink debug output to include chains, flowtables and objects so a test case may check if they are fetched or not.
The remaining patches actually increase filter use.
Phil Sutter (5):
cache: Include chains, flowtables and objects in netlink debug output
cache: Respect family in all list commands
cache: Relaxchain_cache_dumpfilter application
cache: Filter for table when listing sets or maps
cache: Filter for table when listing flowtables
Quoted 8 lines
Quoted 5 lines
src/cache.c | 11 ++-- src/mnl.c | 60 ++++++++++++++++++--- tests/shell/testcases/listing/cache_filters | 53 ++++++++++++++++++ 3 files changed, 113 insertions(+), 11 deletions(-) create mode 100755 tests/shell/testcases/listing/cache_filtersI ran this series against the firewalld testsuite. All green. Thanks Phil!
Thanks for testing, Eric! Shame on me for not putting you in Cc as you asked for. Next time I'll probably best add a Cc: tag to one of the commits immediately. ;)
Cheers, Phil
Phil Sutter
reviewerQuoted 12 lines · Phil Sutter
Reducing the amount of data fetched from kernel improves performance with large rule sets but also reduces adverse side-effects if multiple versions of nftables access the same kernel rule set. Being able to ignore parts of the rule set one is not interested in allows for (more or less) safe coexistence if each tool is operating on the data it created itself only.
This series reduces caching for list commands which specify a family and/or table. To help testing this, patch 1 extends netlink debug output to include chains, flowtables and objects so a test case may check if they are fetched or not.
Quoted 8 lines
The remaining patches actually increase filter use.
Phil Sutter (5):
cache: Include chains, flowtables and objects in netlink debug output
cache: Respect family in all list commands
cache: Relaxchain_cache_dumpfilter application
cache: Filter for table when listing sets or maps
cache: Filter for table when listing flowtables
Series applied after inserting suggested Fixes: tags.
Pablo Neira Ayuso
maintainerQuoted 15 lines · Phil Sutter
Quoted 14 lines · Phil Sutter
Reducing the amount of data fetched from kernel improves performance with large rule sets but also reduces adverse side-effects if multiple versions of nftables access the same kernel rule set. Being able to ignore parts of the rule set one is not interested in allows for (more or less) safe coexistence if each tool is operating on the data it created itself only.
This series reduces caching for list commands which specify a family and/or table. To help testing this, patch 1 extends netlink debug output to include chains, flowtables and objects so a test case may check if they are fetched or not.
The remaining patches actually increase filter use.
Quoted 8 lines
Quoted 6 lines
Phil Sutter (5):
cache: Include chains, flowtables and objects in netlink debug output
cache: Respect family in all list commands
cache: Relaxchain_cache_dumpfilter application
cache: Filter for table when listing sets or maps
cache: Filter for table when listing flowtablesSeries applied after inserting suggested Fixes: tags.
Uoh.
I did not even get here to review.
Pablo Neira Ayuso
maintainerQuoted 23 lines · Pablo Neira Ayuso
Quoted 22 lines · Phil Sutter
Quoted 20 lines · Phil Sutter
Reducing the amount of data fetched from kernel improves performance with large rule sets but also reduces adverse side-effects if multiple versions of nftables access the same kernel rule set. Being able to ignore parts of the rule set one is not interested in allows for (more or less) safe coexistence if each tool is operating on the data it created itself only.
This series reduces caching for list commands which specify a family and/or table. To help testing this, patch 1 extends netlink debug output to include chains, flowtables and objects so a test case may check if they are fetched or not.
The remaining patches actually increase filter use.
Phil Sutter (5):
cache: Include chains, flowtables and objects in netlink debug output
cache: Respect family in all list commands
cache: Relaxchain_cache_dumpfilter application
cache: Filter for table when listing sets or maps
cache: Filter for table when listing flowtables
Quoted 5 lines
Quoted 1 line
Series applied after inserting suggested Fixes: tags.
Uoh.
I did not even get here to review.
Oh sorry, it looks good to me.
I thought you applied the one to fix "list table ...; list table ...;".
That other series I would like to have a closer look.
Phil Sutter
reviewerQuoted 24 lines · Pablo Neira Ayuso
Quoted 23 lines · Pablo Neira Ayuso
Quoted 22 lines · Phil Sutter
Quoted 20 lines · Phil Sutter
Reducing the amount of data fetched from kernel improves performance with large rule sets but also reduces adverse side-effects if multiple versions of nftables access the same kernel rule set. Being able to ignore parts of the rule set one is not interested in allows for (more or less) safe coexistence if each tool is operating on the data it created itself only.
This series reduces caching for list commands which specify a family and/or table. To help testing this, patch 1 extends netlink debug output to include chains, flowtables and objects so a test case may check if they are fetched or not.
The remaining patches actually increase filter use.
Phil Sutter (5):
cache: Include chains, flowtables and objects in netlink debug output
cache: Respect family in all list commands
cache: Relaxchain_cache_dumpfilter application
cache: Filter for table when listing sets or maps
cache: Filter for table when listing flowtables
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Series applied after inserting suggested Fixes: tags.
Uoh.
I did not even get here to review.
Oh sorry, it looks good to me.
Yes, you gave your Reviewed-by: for all but the first patch! O:-)
Quoted 3 lines
I thought you applied the one to fix "list table ...; list table ...;".
That other series I would like to have a closer look.
Yes, I also appreciate some review of that one. Also I wanted to try implementing cache update per command, if only to see how troublesome that will be.
Thanks, Phil