History

netfilter: xtables: stackptr should be percpu

commit f3c5c1bfd4 (netfilter: xtables: make ip_tables reentrant) introduced a performance regression, because stackptr array is shared by all cpus, adding cache line ping pongs. (16 cpus share a 64 bytes cache line) Fix this using alloc_percpu()

Eric Dumazet committed 16 years ago

Commit 7489aec1 parent c936e8b4 files · +6 −13Browse files

Unified · Split

4 files
  1. include/linux/netfilter/x_tables.h +1 −1
  2. net/ipv4/netfilter/ip_tables.c +1 −1
  3. net/ipv6/netfilter/ip6_tables.c +1 −1
  4. net/netfilter/x_tables.c +3 −10
include/linux/netfilter/x_tables.h+1−1
@@ -397,7 +397,7 @@ struct xt_table_info { · 396 unmodified lines
397397 * @stacksize jumps (number of user chains) can possibly be made.
398398 */
399399 unsigned int stacksize;
400− unsigned int *stackptr;
400+ unsigned int __percpu *stackptr;
401401 void ***jumpstack;
402402 /* ipt_entry tables: one per CPU */
403403 /* Note : this field MUST be the last one, see XT_TABLE_INFO_SZ */
net/ipv4/netfilter/ip_tables.c+1−1
@@ -336,7 +336,7 @@ ipt_do_table(struct sk_buff *skb, · 335 unmodified lines
336336 cpu = smp_processor_id();
337337 table_base = private->entries[cpu];
338338 jumpstack = (struct ipt_entry **)private->jumpstack[cpu];
339− stackptr = &private->stackptr[cpu];
339+ stackptr = per_cpu_ptr(private->stackptr, cpu);
340340 origptr = *stackptr;
341341
342342 e = get_entry(table_base, private->hook_entry[hook]);
net/ipv6/netfilter/ip6_tables.c+1−1
@@ -363,7 +363,7 @@ ip6t_do_table(struct sk_buff *skb, · 362 unmodified lines
363363 cpu = smp_processor_id();
364364 table_base = private->entries[cpu];
365365 jumpstack = (struct ip6t_entry **)private->jumpstack[cpu];
366− stackptr = &private->stackptr[cpu];
366+ stackptr = per_cpu_ptr(private->stackptr, cpu);
367367 origptr = *stackptr;
368368
369369 e = get_entry(table_base, private->hook_entry[hook]);
net/netfilter/x_tables.c+3−10
@@ -699,10 +699,8 @@ void xt_free_table_info(struct xt_table_info *info) · 698 unmodified lines
699699 vfree(info->jumpstack);
700700 else
701701 kfree(info->jumpstack);
702− if (sizeof(unsigned int) * nr_cpu_ids > PAGE_SIZE)
703− vfree(info->stackptr);
704− else
705− kfree(info->stackptr);
702+
703+ free_percpu(info->stackptr);
706704
707705 kfree(info);
708706 }
@@ -753,14 +751,9 @@ static int xt_jumpstack_alloc(struct xt_table_info *i) · 44 unmodified lines
753751 unsigned int size;
754752 int cpu;
755753
756− size = sizeof(unsigned int) * nr_cpu_ids;
757− if (size > PAGE_SIZE)
758− i->stackptr = vmalloc(size);
759− else
760− i->stackptr = kmalloc(size, GFP_KERNEL);
754+ i->stackptr = alloc_percpu(unsigned int);
761755 if (i->stackptr == NULL)
762756 return -ENOMEM;
763− memset(i->stackptr, 0, size);
764757
765758 size = sizeof(void **) * nr_cpu_ids;
766759 if (size > PAGE_SIZE)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t