From nobody Fri Jul 22 23:19:14 2022 X-Original-To: dev-commits-src-main@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 4LqQPH0Mrmz4XC3J; Fri, 22 Jul 2022 23:19:15 +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 4LqQPG704Pz3wvS; Fri, 22 Jul 2022 23:19:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1658531955; 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=jdLOQNxMMnVEPJDnbcMLz5H12mkPxhTLWSvmoM3UTJk=; b=YNdOFLxT/czx2mdvHlzwkCp/iDvkUpbsifa2eeGCSFcUhlnRnAEBodSbP6b4D2yeIUcBTX lMX8DaDl+Cd+GWJZhhcL7h0P6IC9ETiIP+tS9WG53m2ja+wMUMENKGxweOfAGjv8/i5TJ5 N/IILIioIZKW7BOWy8DUlybg15fRGdR4Mig3CjJhjoIRsnPvhP/GWmXAtKvrvcU+jcrqHp eX5v4JoW6AD+SMtYo4JLwPvQYTkbZQiDJWWn9yxpno8XgIazWeXav7TyL6TEgJDf+r7MKs OlSO0ugf9LJp4cFDPmV3sxCiAipiShC9eiIGZfoAGgtPRU3uVFLqVACEmTC4dQ== 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 4LqQPG5pTjzJQk; Fri, 22 Jul 2022 23:19:14 +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 26MNJEgj032684; Fri, 22 Jul 2022 23:19:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 26MNJEVY032683; Fri, 22 Jul 2022 23:19:14 GMT (envelope-from git) Date: Fri, 22 Jul 2022 23:19:14 GMT Message-Id: <202207222319.26MNJEVY032683@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 151abc80cde7 - main - if_vlan: avoid hash table thrashing when adding and removing entries List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 151abc80cde778bc18b91c334d07fbd52bbb38fb Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1658531955; 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=jdLOQNxMMnVEPJDnbcMLz5H12mkPxhTLWSvmoM3UTJk=; b=f6bKap8Ud+hIVYKZ/byS0rnXcQi4H9+Jx3ekpLO55XZxEF1yLhbvJ8Vfdavgi50ef8bZYW KFKEDdR1v4Afdyqn0U2JKvyQZ3bZlZDLQ2rI2aGM53ZpdCJkBA94QsGBJz/xI9P5sC7h8w 7QFAXwQU3Ddq9P5SWePL++7Z6EvoNt7H+tntyIzuKd66v6aCY1BOG47BES+j+nFi/vQhQ3 UDNvWjFZDf4X/nkRSbb1hNePPXW7SrtiaWaxf+gf0GxuXdqZ47qXF0pePPcm2YluLXlebO TLlq10XX9DLDJVqR+wR/b7zCVmqKSp9J8C/D4TwZaJMhKzkgJm8u68aK2Y5f/Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1658531955; a=rsa-sha256; cv=none; b=tOP7JZDJPHa4F0SZswK4eq6r94ifOtumc6zLr5hMlJzSxo0qn47hdx5ToRBoH59MyFC7kU /vQ8GN3oE3C/temH1yyD2/LCUowyevGEjbQoVsXz3f95QcdRBX0sNqDb3m+tiW+EC2sriT Avxr/xRyCUB1k5sUsREfWZ92f5Xe5hHy2YaecZxPFWu7PiOAJml8udTJCAmd2TlEj/9+TQ y9hXlXkdlpWCC81CjDygMlEq/d0EcBQPpTEHkIOzKXRBkVfzUMDlHpHa0EbsfZuHHUboFe TrfPamXyC5RUxm3tOCGJoPVd6qiZY/bWZFwOFojPD7d6+dYcJBxcQf53DwZpwA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=151abc80cde778bc18b91c334d07fbd52bbb38fb commit 151abc80cde778bc18b91c334d07fbd52bbb38fb Author: Kristof Provost AuthorDate: 2022-07-22 17:17:04 +0000 Commit: Kristof Provost CommitDate: 2022-07-22 17:18:41 +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. --- 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 03a06f09c541..58df9b21fc20 100644 --- a/sys/net/if_vlan.c +++ b/sys/net/if_vlan.c @@ -464,7 +464,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) {