From nobody Fri Aug 05 11:56:02 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 4LzkZV2YJVz4Xlhc; Fri, 5 Aug 2022 11:56:02 +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 4LzkZV27t3z45th; Fri, 5 Aug 2022 11:56:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659700562; 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=/7p/juTuZeKCLTImJqmMjo0zlc2c7lrS+k7p5qq7XQw=; b=JlF8GJTt18ZvcdFZK1epzX//FUVils/TK1AzfhhmXZM7ypjM+8KUXLLQaeQ9GTQoXJiDfS 5F1k5fNuNNWY1Bwtaj6k0anu2Kf0D3uD4Oh5FXLNSpGj3GVmxa50yYZEHLcGXlZUjyZsuo I/fPSWqq9tMzdpeA3/cANMdV0pFNkgfjbE41y+PmLbmAgvtDk2i5q5eutfGgh1p35u7mWc 3q145+nCnFBlmL5vncpyzE1pkuTCFJ2t1zmKBXftcDWhFk+Xv5KURM+ScjSD9/l7TWdgmF R3ESHvnvObKhjSQjwaS6KylNyP9ynn/3qFZaXafcF5tQPEcOoLeNLVPwxWn4AA== 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 4LzkZV1FzQzsv9; Fri, 5 Aug 2022 11:56:02 +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 275Bu2JJ047761; Fri, 5 Aug 2022 11:56:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 275Bu2ea047760; Fri, 5 Aug 2022 11:56:02 GMT (envelope-from git) Date: Fri, 5 Aug 2022 11:56:02 GMT Message-Id: <202208051156.275Bu2ea047760@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: 6c6e7cbe47b0 - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: 6c6e7cbe47b0d7200947ebf0d57570fa6f771ec2 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659700562; 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=/7p/juTuZeKCLTImJqmMjo0zlc2c7lrS+k7p5qq7XQw=; b=UILcbiWmpPu/4wCPWR4Wlcag3XvL0BG6RebP6MP1E99kbUhm7ZFqSMauk5nANlFgr0unyk XvO3WlpPg5LbW8S9fC6DpXmP3iK3i8aWvHqHKENIMMVMzu+a/KWz1Lqkq4cwcPdavbGKgB TeDmSsCUevn+HGOoOwL3lef+ak8ej2IdDKJxRkkc9kGPVQA7RlfWmhMFCd8qc12eF1iHtq lV1Rht2W8w+9Wm33hY2g9DL6EFcJVUtRf6Qa0uSeynrQM4JU98ht5rL5zBhZ+/1S12eezy gIiJdhCG3upjxe7nCsjyEfrwTUh8kxs8Dhq4/3iFlpIYj9coD3eg/98tYF8XSQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1659700562; a=rsa-sha256; cv=none; b=qUWHNSWo/xolB7bY/rUQ+nTuwTdYNQraQlapj6IA/sI92n+g9XQgxVowiFimcbE+1rtXrP oFFZHayaFgDe4bSd7P26Xb3FysiH7x7m8bw/51uXc6bKH8bhmcQmqk6y5MGVX/TGUJmGgA pkE1Nve/pUEj5F/TMaCs0cTDZnf4bWOGfmeS9tUXS/QYYf9gE22ubd3Am1UkXF7kGuJKxs ZnnDExtItYOBWYCFe+iSDYnzJpbH12rGOYXzdOKDR69uB4VPY92sjGSw1qL/rlFmSgLBEt MjHrYXFv2RekDIWHcZGLIehHhJd2NnozgDC63uTeVKv94fvL95tVByAJYePCQA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=6c6e7cbe47b0d7200947ebf0d57570fa6f771ec2 commit 6c6e7cbe47b0d7200947ebf0d57570fa6f771ec2 Author: David Sips AuthorDate: 2022-07-22 17:17:04 +0000 Commit: Kristof Provost CommitDate: 2022-08-05 11:54:25 +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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c index 79f2834e50ff..21082f2d5741 100644 --- a/sys/net/if_vlan.c +++ b/sys/net/if_vlan.c @@ -425,7 +425,7 @@ 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) {