aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sips <dsips@netapp.com>2022-07-22 17:17:04 +0000
committerKristof Provost <kp@FreeBSD.org>2022-08-05 11:54:32 +0000
commita5f19abeb7191cb3cd89f06ff0eb150b89d6b8bf (patch)
tree53df3b11735968b6d7a5395cab9bbbb68185135b
parent325c554e2ec9ffd4d5ce38793ea3a529a5d26069 (diff)
if_vlan: avoid hash table thrashing when adding and removing entries
vlan_remhash() uses incorrect value for b. When using the default value for VLAN_DEF_HWIDTH (4), the VLAN hash-list table expands from 16 chains to 32 chains as the 129th entry is added. trunk->hwidth becomes 5. Say a few more entries are added and there are now 135 entries. trunk-hwidth will still be 5. If an entry is removed, vlan_remhash() will calculate a value of 32 for b. refcnt will be decremented to 134. The if comparison at line 473 will return true and vlan_growhash() will be called. The VLAN hash-list table will be compressed from 32 chains wide to 16 chains wide. hwidth will become 4. This is an error, and it can be seen when a new VLAN is added. The table will again be expanded. If an entry is then removed, again the table is contracted. If the number of VLANS stays in the range of 128-512, each time an insert follows a remove, the table will expand. Each time a remove follows an insert, the table will be contracted. The fix is simple. The line 473 should test that the number of entries has decreased such that the table should be contracted using what would be the new value of hwidth. line 467 should be: b = 1 << (trunk->hwidth - 1); PR: 265382 Reviewed by: kp MFC after: 2 weeks Sponsored by: NetApp, Inc. (cherry picked from commit 151abc80cde778bc18b91c334d07fbd52bbb38fb)
-rw-r--r--sys/net/if_vlan.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c
index ae1e05e8bc93..491c1a4fa371 100644
--- a/sys/net/if_vlan.c
+++ b/sys/net/if_vlan.c
@@ -408,7 +408,8 @@ vlan_remhash(struct ifvlantrunk *trunk, struct ifvlan *ifv)
VLAN_XLOCK_ASSERT();
KASSERT(trunk->hwidth > 0, ("%s: hwidth not positive", __func__));
- b = 1 << trunk->hwidth;
+
+ b = 1 << (trunk->hwidth - 1);
i = HASH(ifv->ifv_vid, trunk->hmask);
CK_SLIST_FOREACH(ifv2, &trunk->hash[i], ifv_list)
if (ifv2 == ifv) {