diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2010-12-18 12:35:15 -0500 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2011-01-13 06:05:12 -0500 |
commit | 255d0dc34068a976550ce555e153c0bfcfec7cc6 (patch) | |
tree | e936c3d55eaf144cbc4edf8f9332d8089719d0d4 /net/ipv6 | |
parent | b017900aac4a158b9bf7ffdcb8a369a91115b3e4 (diff) |
netfilter: x_table: speedup compat operations
One iptables invocation with 135000 rules takes 35 seconds of cpu time
on a recent server, using a 32bit distro and a 64bit kernel.
We eventually trigger NMI/RCU watchdog.
INFO: rcu_sched_state detected stall on CPU 3 (t=6000 jiffies)
COMPAT mode has quadratic behavior and consume 16 bytes of memory per
rule.
Switch the xt_compat algos to use an array instead of list, and use a
binary search to locate an offset in the sorted array.
This halves memory need (8 bytes per rule), and removes quadratic
behavior [ O(N*N) -> O(N*log2(N)) ]
Time of iptables goes from 35 s to 150 ms.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'net/ipv6')
-rw-r--r-- | net/ipv6/netfilter/ip6_tables.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c index 455582384ece..0c9973a657fb 100644 --- a/net/ipv6/netfilter/ip6_tables.c +++ b/net/ipv6/netfilter/ip6_tables.c | |||
@@ -1093,6 +1093,7 @@ static int compat_table_info(const struct xt_table_info *info, | |||
1093 | memcpy(newinfo, info, offsetof(struct xt_table_info, entries)); | 1093 | memcpy(newinfo, info, offsetof(struct xt_table_info, entries)); |
1094 | newinfo->initial_entries = 0; | 1094 | newinfo->initial_entries = 0; |
1095 | loc_cpu_entry = info->entries[raw_smp_processor_id()]; | 1095 | loc_cpu_entry = info->entries[raw_smp_processor_id()]; |
1096 | xt_compat_init_offsets(AF_INET6, info->number); | ||
1096 | xt_entry_foreach(iter, loc_cpu_entry, info->size) { | 1097 | xt_entry_foreach(iter, loc_cpu_entry, info->size) { |
1097 | ret = compat_calc_entry(iter, info, loc_cpu_entry, newinfo); | 1098 | ret = compat_calc_entry(iter, info, loc_cpu_entry, newinfo); |
1098 | if (ret != 0) | 1099 | if (ret != 0) |
@@ -1696,6 +1697,7 @@ translate_compat_table(struct net *net, | |||
1696 | duprintf("translate_compat_table: size %u\n", info->size); | 1697 | duprintf("translate_compat_table: size %u\n", info->size); |
1697 | j = 0; | 1698 | j = 0; |
1698 | xt_compat_lock(AF_INET6); | 1699 | xt_compat_lock(AF_INET6); |
1700 | xt_compat_init_offsets(AF_INET6, number); | ||
1699 | /* Walk through entries, checking offsets. */ | 1701 | /* Walk through entries, checking offsets. */ |
1700 | xt_entry_foreach(iter0, entry0, total_size) { | 1702 | xt_entry_foreach(iter0, entry0, total_size) { |
1701 | ret = check_compat_entry_size_and_hooks(iter0, info, &size, | 1703 | ret = check_compat_entry_size_and_hooks(iter0, info, &size, |