All of lore.kernel.org
 help / color / mirror / Atom feed
* nftables: Writers starve readers
@ 2023-06-01  9:37 Phil Sutter
  2023-06-01 15:11 ` Florian Westphal
  0 siblings, 1 reply; 7+ messages in thread
From: Phil Sutter @ 2023-06-01  9:37 UTC (permalink / raw)
  To: Pablo Neira Ayuso, Florian Westphal; +Cc: netfilter-devel

Hi!

I'm currently triaging a case where 'nft list ruleset' happens to take
more than 60s which causes trouble in the calling code. It is not
entirely clear what happens on the system that leads to this, so I'm
checking "suspicious" cases. One of them is "too many ruleset updates",
and indeed the following script is problematic:

| # init
| iptables-nft -N foo
| (
| 	echo "*filter";
| 	for ((i = 0; i < 100000; i++)); do
| 		echo "-A foo -m comment --comment \"rule $i\" -j ACCEPT"
| 	done
| 	echo "COMMIT"
| ) | iptables-nft-restore --noflush
| 
| # flood
| while true; do
| 	iptables-nft -A foo -j ACCEPT
| 	iptables-nft -D foo -j ACCEPT
| done

A call to 'nft list ruleset' in a second terminal hangs without output.
It apparently hangs in nft_cache_update() because rule_cache_dump()
returns EINTR. On kernel side, I guess it stems from
nl_dump_check_consistent() in __nf_tables_dump_rules(). I haven't
checked, but the generation counter likely increases while dumping the
100k rules.

One may deem this scenario unrealistic, but I had to insert a 'sleep 5'
into the while-loop to unblock 'nft list ruleset' again. A new rule
every 4s especially in such a large ruleset is not that unrealistic IMO.

I wonder if we can provide some fairness to readers? Ideally a reader
would just see the ruleset as it was when it started dumping, but
keeping a copy of the large ruleset is probably not feasible.

Cheers, Phil

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-06-02 22:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-01  9:37 nftables: Writers starve readers Phil Sutter
2023-06-01 15:11 ` Florian Westphal
2023-06-01 16:42   ` Phil Sutter
2023-06-01 20:06   ` Pablo Neira Ayuso
2023-06-02 12:23     ` Phil Sutter
2023-06-02 22:11       ` Pablo Neira Ayuso
2023-06-02 22:54         ` Pablo Neira Ayuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.