From nobody Tue May 20 09:08:37 2025 X-Original-To: dev-commits-src-all@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 4b1pd14vDxz5w54g; Tue, 20 May 2025 09:08:37 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4b1pd12vjmz43XN; Tue, 20 May 2025 09:08:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1747732117; 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=mq3rXbjkA/g788ToV+bG4/Cb0ww7gWnzNhHjP/J4twU=; b=SQXqPbtNs005W/onyRgu55VmfCZVEwTQcEQ8GzqjceLpimFIs5GFDuRRQLJ/aepF6VU3Hi FJZMEo0dT2ml0PkuVZpwWxiXKNzJsw8B50WFZ60p+lnC9t4MHuw5NuD2SatZaI/LHFLhya f35YxFnU6TQg9GQKDbfChqVEKNO6cRdhKOy7O+uaCyJbw82CDn4vlAyBIe0udmSCsvqoyD FWS+3qvarkSHi1fZi2gIu7Uqki5CvFOHvbdB0ZvsN8E2rrE/yIQ3wz0gmn4JQ2zQZnUxga LqvoFUj0YfnV1OC38FJDvHhRTVf3nARwOnPDxAk1PKErYsaUYWzvzJoTB29cMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1747732117; 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=mq3rXbjkA/g788ToV+bG4/Cb0ww7gWnzNhHjP/J4twU=; b=tVV/rXtYK8/twIWfO+EVj7kLTp8RHRrpQBkdKIpkC1/8AgvRVctOSqNjoDQ8Y2fHjqYphK x45HHYTmeEsYI8jQuDtYufn28iI7N43FCu2w1a87/lnzmZAfMkdmouLyIHeaCFcLF79THl Z/nRg6aro48KsAernhpFfKlPNFaHmH7yfY4+ES28UIdhZUzwuKHsD33BzcgHSswYPw2+Ay 7MBu/YD5pal+lHOe8o0YBxWvmfCZdxVd5lN4aeKuEZtrwYbRc9439HS2cu5s6TQCR7r7n+ ur7c5G1bFwdOUvBPFXnF3NK+Tlbbox58M+MxcE49mvZk3QtQtGOspOjcO3O49Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1747732117; a=rsa-sha256; cv=none; b=lbUo4hFzHbdCAqEMqZs86y31+Wdl5AFwtp58F5ICaGrDgLDE8qU3NTVnhZWkxuWS78xU+1 UWeRpt349y0MPlYGinrWY546P9RQ8NnVV0mF914a2tZBJc8UquwEfClibPriNJ53vwa7Ow W1DN8wk+cguUKjRK/u65go0gZQExccEqHe/SfDsfjtJDpDI0++mUCHQ3LG4n6aIPu9obp3 UE6TX6C6Y9Z2qFE0BGJwRLMePFsApmjGdSvx4dw5C1FBv651hD7HV9b+FAgou6mv8iBpwv 9ctx+mmTm6dc9UswiS/c7G+UqH6re+atue2s803u/A36R9Wl1d0XwK0xu93yeg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4b1pd12RcyzkZ7; Tue, 20 May 2025 09:08:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 54K98bkr000780; Tue, 20 May 2025 09:08:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 54K98btR000777; Tue, 20 May 2025 09:08:37 GMT (envelope-from git) Date: Tue, 20 May 2025 09:08:37 GMT Message-Id: <202505200908.54K98btR000777@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: ce6b7a5919da - stable/14 - vfs: vn_alloc(): Stop always calling vn_alloc_hard() and direct reclaiming List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: ce6b7a5919da518715d6163baa42035d6d2c1bd0 Auto-Submitted: auto-generated The branch stable/14 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=ce6b7a5919da518715d6163baa42035d6d2c1bd0 commit ce6b7a5919da518715d6163baa42035d6d2c1bd0 Author: Olivier Certner AuthorDate: 2025-05-13 13:47:42 +0000 Commit: Olivier Certner CommitDate: 2025-05-20 09:05:27 +0000 vfs: vn_alloc(): Stop always calling vn_alloc_hard() and direct reclaiming Commit ab05a1cf321aca0f intended to revert commit 8733bc277a383cf5 ("vfs: don't provoke recycling non-free vnodes without a good reason"), but due to intervening changes in commit 054f45e026d898bd ("vfs: further speed up continuous free vnode recycle"), it also had to revert part of it. In particular, while removing the whole 'if (vn_alloc_cyclecount != 0)' block, it inadvertantly removed the code block resetting 'vn_alloc_cyclecount' to 0 and skipping direct vnode reclamation (done further below through vnlru_free_locked_direct()), which had been outside the 'if' before the intervening commit. Removing this block instead of reinstating it in practice causes 'vn_alloc_cyclecount' to (almost) never be 0, making vn_alloc() always call vn_alloc_hard(), which takes the 'vnode_list_mtx' mutex. In other words, this disables the fast path. [The reverted commit, which introduced the 'if (vn_alloc_cyclecount != 0)' guarding this block, actually never executed it because it also had the bug that 'vn_alloc_cyclecount' would always stay at 0, hiding its usefulness.] Additionally, not skipping direct vnode reclamation even when there are less vnodes than 'kern.maxvnodes' not only causes unnecessary contention but also plain livelocks as vnlru_free_locked_direct() does not itself check whether there are actually "free" (not referenced) vnodes to be deallocated, and will blindly browse all the vnode list until it finds one (which it may not, or only a few ones at the end). As the fast path was disabled, all threads in the system would soon be competing for the vnode list lock, outpacing the vnlru process that could never actually recycle vnodes in a more agressive manner (i.e., even if they have a non-zero hold count). And we could more easily get into this situation, as each vnode allocation was reducing the count of "free" vnodes, even if entirely new vnodes could be allocated instead. This part was mitigated by the vnlru process (before the tipping point described above), which explains why the mechanism would not always livelock. Not skipping direct vnode reclamation was arguably a bug introduced by the intervening commit (054f45e026d898bd), but was mitigated by vn_alloc_hard() not being called in the fast path. The revert commit, by disabling the fast path, made it significantly annoying (to the point of getting a few livelocks a week in some of my workloads). Restore the reset of 'vn_alloc_cyclecount' to 0 and skip direct reclamation when the current number of vnodes is below the 'kern.maxvnodes' limit, indicating we can start allocating a new 'struct vnode' right away. While here, fix the comparison with the limit when 'bumped' is true. Reviewed by: kib (older version), avg Tested by: avg, olce Fixes: ab05a1cf321aca0f (revert of "vfs: don't provoke recycling non-free vnodes without a good reason") Fixes: 054f45e026d898bd ("vfs: further speed up continuous free vnode recycle") MFC after: 5 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D50338 (cherry picked from commit d90c9c24e2c3701949c47061b5ad198eedeebfb9) --- sys/kern/vfs_subr.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 009d305b8c1f..a640bede85b9 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -1964,11 +1964,24 @@ vn_alloc_hard(struct mount *mp, u_long rnumvnodes, bool bumped) mtx_lock(&vnode_list_mtx); + /* + * Reload 'numvnodes', as since we acquired the lock, it may have + * changed significantly if we waited, and 'rnumvnodes' above was only + * actually passed if 'bumped' is true (else it is 0). + */ + rnumvnodes = atomic_load_long(&numvnodes); + if (rnumvnodes + !bumped < desiredvnodes) { + vn_alloc_cyclecount = 0; + mtx_unlock(&vnode_list_mtx); + goto alloc; + } + rfreevnodes = vnlru_read_freevnodes(); if (vn_alloc_cyclecount++ >= rfreevnodes) { vn_alloc_cyclecount = 0; vstir = true; } + /* * Grow the vnode cache if it will not be above its target max * after growing. Otherwise, if the free list is nonempty, try