aboutsummaryrefslogtreecommitdiffstats
path: root/net/core
diff options
context:
space:
mode:
authorYOSHIFUJI Hideaki / 吉藤英明 <yoshfuji@linux-ipv6.org>2013-01-23 19:44:23 -0500
committerDavid S. Miller <davem@davemloft.net>2013-01-28 23:17:51 -0500
commit08433eff2d041b263c68306f6a6ccb4e1f75e196 (patch)
treea983dd9edfdb434076751c50f3952c744f64e17f /net/core
parentcdda88912d62f9603d27433338a18be83ef23ac1 (diff)
net neigh: Optimize neighbor entry size calculation.
When allocating memory for neighbour cache entry, if tbl->entry_size is not set, we always calculate sizeof(struct neighbour) + tbl->key_len, which is common in the same table. With this change, set tbl->entry_size during the table initialization phase, if it was not set, and use it in neigh_alloc() and neighbour_priv(). This change also allow us to have both of protocol private data and device priate data at tha same time. Note that the only user of prototcol private is DECnet and the only user of device private is ATM CLIP. Since those are exclusive, we have not been facing issues here. Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r--net/core/neighbour.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 7bd0eedb357f..3863b8f639c5 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -290,15 +290,7 @@ static struct neighbour *neigh_alloc(struct neigh_table *tbl, struct net_device
290 goto out_entries; 290 goto out_entries;
291 } 291 }
292 292
293 if (tbl->entry_size) 293 n = kzalloc(tbl->entry_size + dev->neigh_priv_len, GFP_ATOMIC);
294 n = kzalloc(tbl->entry_size, GFP_ATOMIC);
295 else {
296 int sz = sizeof(*n) + tbl->key_len;
297
298 sz = ALIGN(sz, NEIGH_PRIV_ALIGN);
299 sz += dev->neigh_priv_len;
300 n = kzalloc(sz, GFP_ATOMIC);
301 }
302 if (!n) 294 if (!n)
303 goto out_entries; 295 goto out_entries;
304 296
@@ -1546,6 +1538,12 @@ static void neigh_table_init_no_netlink(struct neigh_table *tbl)
1546 if (!tbl->nht || !tbl->phash_buckets) 1538 if (!tbl->nht || !tbl->phash_buckets)
1547 panic("cannot allocate neighbour cache hashes"); 1539 panic("cannot allocate neighbour cache hashes");
1548 1540
1541 if (!tbl->entry_size)
1542 tbl->entry_size = ALIGN(offsetof(struct neighbour, primary_key) +
1543 tbl->key_len, NEIGH_PRIV_ALIGN);
1544 else
1545 WARN_ON(tbl->entry_size % NEIGH_PRIV_ALIGN);
1546
1549 rwlock_init(&tbl->lock); 1547 rwlock_init(&tbl->lock);
1550 INIT_DEFERRABLE_WORK(&tbl->gc_work, neigh_periodic_work); 1548 INIT_DEFERRABLE_WORK(&tbl->gc_work, neigh_periodic_work);
1551 schedule_delayed_work(&tbl->gc_work, tbl->parms.reachable_time); 1549 schedule_delayed_work(&tbl->gc_work, tbl->parms.reachable_time);