Skip to content

Commit

Permalink
netfilter: xtables: stackptr should be percpu
Browse files Browse the repository at this point in the history
commit f3c5c1b (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()

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Acked-By: Jan Engelhardt <jengelh@medozas.de>
Signed-off-by: Patrick McHardy <kaber@trash.net>
  • Loading branch information
Eric Dumazet authored and Patrick McHardy committed May 31, 2010
1 parent c936e8b commit 7489aec
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion include/linux/netfilter/x_tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ struct xt_table_info {
* @stacksize jumps (number of user chains) can possibly be made.
*/
unsigned int stacksize;
unsigned int *stackptr;
unsigned int __percpu *stackptr;
void ***jumpstack;
/* ipt_entry tables: one per CPU */
/* Note : this field MUST be the last one, see XT_TABLE_INFO_SZ */
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/netfilter/ip_tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ ipt_do_table(struct sk_buff *skb,
cpu = smp_processor_id();
table_base = private->entries[cpu];
jumpstack = (struct ipt_entry **)private->jumpstack[cpu];
stackptr = &private->stackptr[cpu];
stackptr = per_cpu_ptr(private->stackptr, cpu);
origptr = *stackptr;

e = get_entry(table_base, private->hook_entry[hook]);
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/netfilter/ip6_tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ ip6t_do_table(struct sk_buff *skb,
cpu = smp_processor_id();
table_base = private->entries[cpu];
jumpstack = (struct ip6t_entry **)private->jumpstack[cpu];
stackptr = &private->stackptr[cpu];
stackptr = per_cpu_ptr(private->stackptr, cpu);
origptr = *stackptr;

e = get_entry(table_base, private->hook_entry[hook]);
Expand Down
13 changes: 3 additions & 10 deletions net/netfilter/x_tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,8 @@ void xt_free_table_info(struct xt_table_info *info)
vfree(info->jumpstack);
else
kfree(info->jumpstack);
if (sizeof(unsigned int) * nr_cpu_ids > PAGE_SIZE)
vfree(info->stackptr);
else
kfree(info->stackptr);

free_percpu(info->stackptr);

kfree(info);
}
Expand Down Expand Up @@ -753,14 +751,9 @@ static int xt_jumpstack_alloc(struct xt_table_info *i)
unsigned int size;
int cpu;

size = sizeof(unsigned int) * nr_cpu_ids;
if (size > PAGE_SIZE)
i->stackptr = vmalloc(size);
else
i->stackptr = kmalloc(size, GFP_KERNEL);
i->stackptr = alloc_percpu(unsigned int);
if (i->stackptr == NULL)
return -ENOMEM;
memset(i->stackptr, 0, size);

size = sizeof(void **) * nr_cpu_ids;
if (size > PAGE_SIZE)
Expand Down

0 comments on commit 7489aec

Please sign in to comment.