From nobody Fri Aug 5 11:55:57 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4LzkZP5fyjz4XlZf; Fri, 5 Aug 2022 11:55:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LzkZP58F1z45bP; Fri, 5 Aug 2022 11:55:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659700557; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FLrxVlIiubvaKTHVzZLodbqvcq7MbjbTLMK2xrXHlXA=; b=oBtfqcPreDc1FzDoYj3H7rs9dVkQTQh6s7Amo0I9Tu4uu0c3KCCzopaQyHMZEywtwj/01T BFmp1cjxNFWLHl5BqtzwoUjKCUuC3/+PpNvgv2om39Setqs+I5PgMHsm01sUxwX7wPXgFF mMGhhNJry9z+aG1Di4FQbPuLRBRNmb5Y87AFAORQAmEPY3bd4gONECf1jcYebD1TG47lBR X78AHOhOBqePywopYxMjxrGFW1ozuAwn74ce9akOTauhhrYo9VdmjkAwA2Y1PRxHYLbOyI 13rCXvfiy4+Z1Y4QeiI1kCdzGwBKf3cYu+hzQ2qOWrSp8DPUbYVoYeWhF4I9lw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4LzkZP48h7zsJ9; Fri, 5 Aug 2022 11:55:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 275Btv3A047635; Fri, 5 Aug 2022 11:55:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 275BtvwE047634; Fri, 5 Aug 2022 11:55:57 GMT (envelope-from git) Date: Fri, 5 Aug 2022 11:55:57 GMT Message-Id: <202208051155.275BtvwE047634@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: a5f19abeb719 - stable/12 - if_vlan: avoid hash table thrashing when adding and removing entries List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: a5f19abeb7191cb3cd89f06ff0eb150b89d6b8bf Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659700557; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FLrxVlIiubvaKTHVzZLodbqvcq7MbjbTLMK2xrXHlXA=; b=MTjplKXsD57VT8mkF9E7IEjUFjhzSubDUwrB+uYRaQkRRO+u1EZn1J66N/lMSKd4JiqrB+ eFv8QdX++fgmFx9PKtyfZrG/s0NMpyADbz3uJ7V67mvJzjFNDAjFl2JIzpppg5dcbaR29i jv5qN3uNzvZ0CZszJ2zvijscqIEb4lCjOnXB8ex+97XHlMVVDhKp9cN2EgyWQW+616lDXq 3+u+QvYomu8hFBqmw1XDQqk4QC5iNnqgUpPkp3AIT6ebfRiRdeoRGC5yW+cBwK/tUDgsgW pWeZ77aX9CEIcE0wfTiin5nQhilMkUJ+EnUQ1ZyXVBnpWjnBD3yBDLakBdPpmQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1659700557; a=rsa-sha256; cv=none; b=kx4OvARugULj4Q/ijAovnwDu0DuMxOv/AA5SgU1I2F5+mn12qDHxPbNfdDT1dhpyfYwgCZ E7kFwNt146z5GPUNELdInj8e+1Rrb8z6Pquw/Rf33en11Lcbm9bjbeorqimhaO6zyI8G+H qSrRYGe2lmMJWrBfjDrvzxkPjvl7givkw66/fP0lDpRnARluzKIxSfj/bsCuwY+JYXRR/g SlHZwoty2PANWI1QbUnQPCjHC4ml0cbOwgR9Qa0kPQEWPz8zvC/WxJ8zEC8/PKEZjIpidZ rcVKfk2+jl6tAMQqP0Qwh578cHodrrCKMfqf7dEB9qrPn46mhNC9fUyZu2GVWw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=a5f19abeb7191cb3cd89f06ff0eb150b89d6b8bf commit a5f19abeb7191cb3cd89f06ff0eb150b89d6b8bf Author: David Sips AuthorDate: 2022-07-22 17:17:04 +0000 Commit: Kristof Provost CommitDate: 2022-08-05 11:54:32 +0000 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) --- sys/net/if_vlan.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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) {