From nobody Fri Oct 13 23:53:55 2023 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 4S6jyW71tPz4wyGL; Fri, 13 Oct 2023 23:53:55 +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 4S6jyW4fhsz3KDd; Fri, 13 Oct 2023 23:53:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697241235; 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=JgTj/lsb+cr2Vxbu0VeFv0xF93Ta4gbRZqKPLZgpL00=; b=ZS/bDAeh1Jwza885DBYwaI2KyJ+ZykMlZdmZDzwO50mlRBvM+Wu8cnVB7nhsO+SMb/rqfa vkKiyMN1sbplmOxBn1F2vtP20fNN2/OW7SVFYfO7JZcjp+9Xua5EG286Mw3YJKMG3C0YSd nxk0URwgSCVUTKQYQ4Rrx0pxetoneAdd6PUf+smDFmB7JaRYfB0xjlHPuEBwO/znBZAwIv jfhQScPPqWWEnTCljQ1R4ng9dIghfmadiKkXFk6Py5hEEvX6pmPaWO2GzMwmyLEuDRW3MN IfawtbfAQ061aNd1YHKWVab8qjUn2ZnGMO4K1jGzQdShBeL3+u1Im2AA7jar2Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697241235; a=rsa-sha256; cv=none; b=v+ZKfUAqHy+JU552uU7QaMKPUs0FbkPHPgAjwi1xrrmBHRoxLkf5GJFBrrV/borldA1NCV ooHgWUwB1pxU0NjPlCtdc1d/f8blA5FzOx9nHU/D7v0bn4rFcY6mKxH+4zf/4ODbHddahv y2Q2zoKXaW2L0FuTgmj+nCp11ZGui29uRiNeyJtDh8E0KSToVB59QaRBgoz0loaSs2Vkz0 qijDJZMxkutBm8mAeeLVPxf3SHUnwqx2o7tohwSyZylRy6qHkZUgnLCrCZoVfCpuGsHZNk Ku3XTUjdzqKxirmJUng3l0PXfl+nQQ3oBHJqWM70hGqbTt1CCxWlFW1zQbTqxQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697241235; 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=JgTj/lsb+cr2Vxbu0VeFv0xF93Ta4gbRZqKPLZgpL00=; b=v+uaGhjhmR4IPpwOeuLilbOlLj3+OUlk/p0BaRX0nGP0U82JtFyGIERPQmDaTtaxtFJOfr 9BYgS4BduX1LxpQoFBsK6IKPsrbDd6fzXzBQxNYExD4/SGIt3yQROUUp/sL+pE5m5+j7Dt 6eO7Z4ykeErRrCxoIsLWzuD0msL6iA7LeqUu5o+VrMuhsEpQQnfFdBo0ZmlAQZGdV3E4/s 2I9zMEc9xCzQUf2V0SeDLAwlC7G8uHgI9ZViKGnQTEtPlcX7ZcELC4XcEVhGhc6bPni2lT DOIsZWRTij9271+NOcJ0fpPFF8dohPwAiwBSNEBHU0mPd2lQMuZAgQsTi9xLeA== 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 4S6jyW3jkzz17nd; Fri, 13 Oct 2023 23:53:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39DNrtH5032277; Fri, 13 Oct 2023 23:53:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39DNrtJU032274; Fri, 13 Oct 2023 23:53:55 GMT (envelope-from git) Date: Fri, 13 Oct 2023 23:53:55 GMT Message-Id: <202310132353.39DNrtJU032274@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 12e81504ef7a - stable/13 - vfs: prefix regular vnlru with a special case for free vnodes 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 12e81504ef7aa1802c8ede384f07ae65fec48bdc Auto-Submitted: auto-generated The branch stable/13 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=12e81504ef7aa1802c8ede384f07ae65fec48bdc commit 12e81504ef7aa1802c8ede384f07ae65fec48bdc Author: Mateusz Guzik AuthorDate: 2023-09-14 19:08:40 +0000 Commit: Mateusz Guzik CommitDate: 2023-10-13 23:48:13 +0000 vfs: prefix regular vnlru with a special case for free vnodes Works around severe performance problems in certain corner cases, see the commentary added. Modifying vnlru logic has proven rather error prone in the past and a release is near, thus take the easy way out and fix it without having to dig into the current machinery. (cherry picked from commit 90a008e94bb205e5b8f3c41d57e155b59a6be95d) --- sys/kern/vfs_subr.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 113 insertions(+), 4 deletions(-) diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 5ddbff77a221..e4b9ff8e1ba6 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -1417,6 +1417,14 @@ vnlru_free_locked(int count) return (ret); } +static int +vnlru_free(int count) +{ + + mtx_lock(&vnode_list_mtx); + return (vnlru_free_locked(count)); +} + void vnlru_free_vfsops(int count, struct vfsops *mnt_op, struct vnode *mvp) { @@ -1611,6 +1619,106 @@ vnlru_kick_cond(void) mtx_unlock(&vnode_list_mtx); } +static void +vnlru_proc_sleep(void) +{ + + if (vnlruproc_sig) { + vnlruproc_sig = 0; + wakeup(&vnlruproc_sig); + } + msleep(vnlruproc, &vnode_list_mtx, PVFS|PDROP, "vlruwt", hz); +} + +/* + * A lighter version of the machinery below. + * + * Tries to reach goals only by recycling free vnodes and does not invoke + * uma_reclaim(UMA_RECLAIM_DRAIN). + * + * This works around pathological behavior in vnlru in presence of tons of free + * vnodes, but without having to rewrite the machinery at this time. Said + * behavior boils down to continuously trying to reclaim all kinds of vnodes + * (cycling through all levels of "force") when the count is transiently above + * limit. This happens a lot when all vnodes are used up and vn_alloc + * speculatively increments the counter. + * + * Sample testcase: vnode limit 8388608, 20 separate directory trees each with + * 1 million files in total and 20 find(1) processes stating them in parallel + * (one per each tree). + * + * On a kernel with only stock machinery this needs anywhere between 60 and 120 + * seconds to execute (time varies *wildly* between runs). With the workaround + * it consistently stays around 20 seconds. + * + * That is to say the entire thing needs a fundamental redesign (most notably + * to accommodate faster recycling), the above only tries to get it ouf the way. + * + * Return values are: + * -1 -- fallback to regular vnlru loop + * 0 -- do nothing, go to sleep + * >0 -- recycle this many vnodes + */ +static long +vnlru_proc_light_pick(void) +{ + u_long rnumvnodes, rfreevnodes; + + if (vstir || vnlruproc_sig == 1) + return (-1); + + rnumvnodes = atomic_load_long(&numvnodes); + rfreevnodes = vnlru_read_freevnodes(); + + /* + * vnode limit might have changed and now we may be at a significant + * excess. Bail if we can't sort it out with free vnodes. + */ + if (rnumvnodes > desiredvnodes) { + if (rnumvnodes - rfreevnodes >= desiredvnodes || + rfreevnodes <= wantfreevnodes) { + return (-1); + } + + return (rnumvnodes - desiredvnodes); + } + + /* + * Don't try to reach wantfreevnodes target if there are too few vnodes + * to begin with. + */ + if (rnumvnodes < wantfreevnodes) { + return (0); + } + + if (rfreevnodes < wantfreevnodes) { + return (-1); + } + + return (0); +} + +static bool +vnlru_proc_light(void) +{ + long freecount; + + mtx_assert(&vnode_list_mtx, MA_NOTOWNED); + + freecount = vnlru_proc_light_pick(); + if (freecount == -1) + return (false); + + if (freecount != 0) { + vnlru_free(freecount); + } + + mtx_lock(&vnode_list_mtx); + vnlru_proc_sleep(); + mtx_assert(&vnode_list_mtx, MA_NOTOWNED); + return (true); +} + static void vnlru_proc(void) { @@ -1626,6 +1734,10 @@ vnlru_proc(void) want_reread = false; for (;;) { kproc_suspend_check(vnlruproc); + + if (force == 0 && vnlru_proc_light()) + continue; + mtx_lock(&vnode_list_mtx); rnumvnodes = atomic_load_long(&numvnodes); @@ -1656,10 +1768,7 @@ vnlru_proc(void) vstir = false; } if (force == 0 && !vnlru_under(rnumvnodes, vlowat)) { - vnlruproc_sig = 0; - wakeup(&vnlruproc_sig); - msleep(vnlruproc, &vnode_list_mtx, - PVFS|PDROP, "vlruwt", hz); + vnlru_proc_sleep(); continue; } rfreevnodes = vnlru_read_freevnodes();