Skip to content

Commit 8dbde28

Browse files
Eric Dumazetdavem330
authored andcommitted
[NET]: NET_CLS_ROUTE : convert ip_rt_acct to per_cpu variables
ip_rt_acct needs 4096 bytes per cpu to perform some accounting. It is actually allocated as a single huge array [4096*NR_CPUS] (rounded up to a power of two) Converting it to a per cpu variable is wanted to : - Save space on machines were num_possible_cpus() < NR_CPUS - Better NUMA placement (each cpu gets memory on its node) Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 68f8353 commit 8dbde28

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

net/ipv4/ip_input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ static int ip_rcv_finish(struct sk_buff *skb)
347347

348348
#ifdef CONFIG_NET_CLS_ROUTE
349349
if (unlikely(skb->dst->tclassid)) {
350-
struct ip_rt_acct *st = ip_rt_acct + 256*smp_processor_id();
350+
struct ip_rt_acct *st = per_cpu_ptr(ip_rt_acct, smp_processor_id());
351351
u32 idx = skb->dst->tclassid;
352352
st[idx&0xFF].o_packets++;
353353
st[idx&0xFF].o_bytes+=skb->len;

net/ipv4/route.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,12 +2858,10 @@ ctl_table ipv4_route_table[] = {
28582858
#endif
28592859

28602860
#ifdef CONFIG_NET_CLS_ROUTE
2861-
struct ip_rt_acct *ip_rt_acct;
2862-
2863-
/* This code sucks. But you should have seen it before! --RR */
2861+
struct ip_rt_acct *ip_rt_acct __read_mostly;
28642862

28652863
/* IP route accounting ptr for this logical cpu number. */
2866-
#define IP_RT_ACCT_CPU(i) (ip_rt_acct + i * 256)
2864+
#define IP_RT_ACCT_CPU(cpu) (per_cpu_ptr(ip_rt_acct, cpu))
28672865

28682866
#ifdef CONFIG_PROC_FS
28692867
static int ip_rt_acct_read(char *buffer, char **start, off_t offset,
@@ -2923,16 +2921,9 @@ int __init ip_rt_init(void)
29232921
(jiffies ^ (jiffies >> 7)));
29242922

29252923
#ifdef CONFIG_NET_CLS_ROUTE
2926-
{
2927-
int order;
2928-
for (order = 0;
2929-
(PAGE_SIZE << order) < 256 * sizeof(struct ip_rt_acct) * NR_CPUS; order++)
2930-
/* NOTHING */;
2931-
ip_rt_acct = (struct ip_rt_acct *)__get_free_pages(GFP_KERNEL, order);
2924+
ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct));
29322925
if (!ip_rt_acct)
29332926
panic("IP: failed to allocate ip_rt_acct\n");
2934-
memset(ip_rt_acct, 0, PAGE_SIZE << order);
2935-
}
29362927
#endif
29372928

29382929
ipv4_dst_ops.kmem_cachep =

0 commit comments

Comments
 (0)