Skip to content

Commit eb79358

Browse files
Nikolay Aleksandrovdavem330
authored andcommitted
net: bridge: use rhashtable for fdbs
Before this patch the bridge used a fixed 256 element hash table which was fine for small use cases (in my tests it starts to degrade above 1000 entries), but it wasn't enough for medium or large scale deployments. Modern setups have thousands of participants in a single bridge, even only enabling vlans and adding a few thousand vlan entries will cause a few thousand fdbs to be automatically inserted per participating port. So we need to scale the fdb table considerably to cope with modern workloads, and this patch converts it to use a rhashtable for its operations thus improving the bridge scalability. Tests show the following results (10 runs each), at up to 1000 entries rhashtable is ~3% slower, at 2000 rhashtable is 30% faster, at 3000 it is 2 times faster and at 30000 it is 50 times faster. Obviously this happens because of the properties of the two constructs and is expected, rhashtable keeps pretty much a constant time even with 10000000 entries (tested), while the fixed hash table struggles considerably even above 10000. As a side effect this also reduces the net_bridge struct size from 3248 bytes to 1344 bytes. Also note that the key struct is 8 bytes. Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e8952ba commit eb79358

5 files changed

Lines changed: 211 additions & 219 deletions

File tree

‎include/trace/events/bridge.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ TRACE_EVENT(fdb_delete,
8282
TP_fast_assign(
8383
__assign_str(br_dev, br->dev->name);
8484
__assign_str(dev, f->dst ? f->dst->dev->name : "null");
85-
memcpy(__entry->addr, f->addr.addr, ETH_ALEN);
86-
__entry->vid = f->vlan_id;
85+
memcpy(__entry->addr, f->key.addr.addr, ETH_ALEN);
86+
__entry->vid = f->key.vlan_id;
8787
),
8888

8989
TP_printk("br_dev %s dev %s addr %02x:%02x:%02x:%02x:%02x:%02x vid %u",

‎net/bridge/br_device.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,24 @@ static int br_dev_init(struct net_device *dev)
125125
if (!br->stats)
126126
return -ENOMEM;
127127

128+
err = br_fdb_hash_init(br);
129+
if (err) {
130+
free_percpu(br->stats);
131+
return err;
132+
}
133+
128134
err = br_vlan_init(br);
129135
if (err) {
130136
free_percpu(br->stats);
137+
br_fdb_hash_fini(br);
131138
return err;
132139
}
133140

134141
err = br_multicast_init_stats(br);
135142
if (err) {
136143
free_percpu(br->stats);
137144
br_vlan_flush(br);
145+
br_fdb_hash_fini(br);
138146
}
139147
br_set_lockdep_class(dev);
140148

@@ -148,6 +156,7 @@ static void br_dev_uninit(struct net_device *dev)
148156
br_multicast_dev_del(br);
149157
br_multicast_uninit_stats(br);
150158
br_vlan_flush(br);
159+
br_fdb_hash_fini(br);
151160
free_percpu(br->stats);
152161
}
153162

@@ -416,6 +425,7 @@ void br_dev_setup(struct net_device *dev)
416425
br->dev = dev;
417426
spin_lock_init(&br->lock);
418427
INIT_LIST_HEAD(&br->port_list);
428+
INIT_HLIST_HEAD(&br->fdb_list);
419429
spin_lock_init(&br->hash_lock);
420430

421431
br->bridge_id.prio[0] = 0x80;

0 commit comments

Comments
 (0)