cache: populate chains on demand from error path
Updates on verdict maps that require many non-base chains are slowed
down due to fetching existing non-base chains into the cache.
Chains are only required for error reporting hints if kernel reports
ENOENT. Populate the cache from this error path only.
Similar approach already exists from rule ENOENT error path since:
deb7c5927fad ("cmd: add misspelling suggestions for rule commands")
however, NFT_CACHE_CHAIN was toggled inconditionally for rule
commands, rendering this on-demand cache population useless.
before this patch, running Neels' nft_slew benchmark (peak values):
created idx 4992 in
52587950 ns (128 in 7122 ms)
...
deleted idx 128 in
43542500 ns (127 in 6187 ms)
after this patch:
created idx 4992 in
11361299 ns (128 in 1612 ms)
...
deleted idx 1664 in
5239633 ns (128 in 733 ms)
Tested-by: Eric Garver <eric@garver.life>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>