Commit 08433eff authored by YOSHIFUJI Hideaki / 吉藤英明's avatar YOSHIFUJI Hideaki / 吉藤英明 Committed by David S. Miller

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: default avatarYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent cdda8891
...@@ -184,7 +184,7 @@ struct neigh_table { ...@@ -184,7 +184,7 @@ struct neigh_table {
static inline void *neighbour_priv(const struct neighbour *n) static inline void *neighbour_priv(const struct neighbour *n)
{ {
return (char *)n + ALIGN(sizeof(*n) + n->tbl->key_len, NEIGH_PRIV_ALIGN); return (char *)n + n->tbl->entry_size;
} }
/* flags for neigh_update() */ /* flags for neigh_update() */
......
...@@ -290,15 +290,7 @@ static struct neighbour *neigh_alloc(struct neigh_table *tbl, struct net_device ...@@ -290,15 +290,7 @@ static struct neighbour *neigh_alloc(struct neigh_table *tbl, struct net_device
goto out_entries; goto out_entries;
} }
if (tbl->entry_size) n = kzalloc(tbl->entry_size + dev->neigh_priv_len, GFP_ATOMIC);
n = kzalloc(tbl->entry_size, GFP_ATOMIC);
else {
int sz = sizeof(*n) + tbl->key_len;
sz = ALIGN(sz, NEIGH_PRIV_ALIGN);
sz += dev->neigh_priv_len;
n = kzalloc(sz, GFP_ATOMIC);
}
if (!n) if (!n)
goto out_entries; goto out_entries;
...@@ -1546,6 +1538,12 @@ static void neigh_table_init_no_netlink(struct neigh_table *tbl) ...@@ -1546,6 +1538,12 @@ static void neigh_table_init_no_netlink(struct neigh_table *tbl)
if (!tbl->nht || !tbl->phash_buckets) if (!tbl->nht || !tbl->phash_buckets)
panic("cannot allocate neighbour cache hashes"); panic("cannot allocate neighbour cache hashes");
if (!tbl->entry_size)
tbl->entry_size = ALIGN(offsetof(struct neighbour, primary_key) +
tbl->key_len, NEIGH_PRIV_ALIGN);
else
WARN_ON(tbl->entry_size % NEIGH_PRIV_ALIGN);
rwlock_init(&tbl->lock); rwlock_init(&tbl->lock);
INIT_DEFERRABLE_WORK(&tbl->gc_work, neigh_periodic_work); INIT_DEFERRABLE_WORK(&tbl->gc_work, neigh_periodic_work);
schedule_delayed_work(&tbl->gc_work, tbl->parms.reachable_time); schedule_delayed_work(&tbl->gc_work, tbl->parms.reachable_time);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment