From owner-svn-src-head@freebsd.org Sat Jan 11 23:00:58 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 447961F7ADC; Sat, 11 Jan 2020 23:00:58 +0000 (UTC) (envelope-from mjg@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47wFhB16pYz4bpx; Sat, 11 Jan 2020 23:00:58 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 21BF5A1D8; Sat, 11 Jan 2020 23:00:58 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 00BN0wYC090551; Sat, 11 Jan 2020 23:00:58 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 00BN0wQs090550; Sat, 11 Jan 2020 23:00:58 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <202001112300.00BN0wQs090550@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Sat, 11 Jan 2020 23:00:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r356645 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 356645 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Jan 2020 23:00:58 -0000 Author: mjg Date: Sat Jan 11 23:00:57 2020 New Revision: 356645 URL: https://svnweb.freebsd.org/changeset/base/356645 Log: vfs: only recalculate watermarks when limits are changing Previously they would get recalculated all the time, in particular in: getnewvnode -> vcheckspace -> vspace Modified: head/sys/kern/vfs_subr.c Modified: head/sys/kern/vfs_subr.c ============================================================================== --- head/sys/kern/vfs_subr.c Sat Jan 11 22:59:44 2020 (r356644) +++ head/sys/kern/vfs_subr.c Sat Jan 11 23:00:57 2020 (r356645) @@ -118,6 +118,7 @@ static void vnlru_return_batches(struct vfsops *mnt_op static void destroy_vpollinfo(struct vpollinfo *vi); static int v_inval_buf_range_locked(struct vnode *vp, struct bufobj *bo, daddr_t startlbn, daddr_t endlbn); +static void vnlru_recalc(void); /* * These fences are intended for cases where some synchronization is @@ -194,8 +195,6 @@ static TAILQ_HEAD(freelst, vnode) vnode_free_list; * whenever vnlru_proc() becomes active. */ static u_long wantfreevnodes; -SYSCTL_ULONG(_vfs, OID_AUTO, wantfreevnodes, CTLFLAG_RW, - &wantfreevnodes, 0, "Target for minimum number of \"free\" vnodes"); static u_long freevnodes; SYSCTL_ULONG(_vfs, OID_AUTO, freevnodes, CTLFLAG_RD, &freevnodes, 0, "Number of \"free\" vnodes"); @@ -317,27 +316,65 @@ static u_long vlowat; /* minimal extras before expans static u_long vstir; /* nonzero to stir non-free vnodes */ static volatile int vsmalltrigger = 8; /* pref to keep if > this many pages */ +/* + * Note that no attempt is made to sanitize these parameters. + */ static int -sysctl_update_desiredvnodes(SYSCTL_HANDLER_ARGS) +sysctl_maxvnodes(SYSCTL_HANDLER_ARGS) { - u_long old_desiredvnodes; + u_long val; int error; - old_desiredvnodes = desiredvnodes; - if ((error = sysctl_handle_long(oidp, arg1, arg2, req)) != 0) + val = desiredvnodes; + error = sysctl_handle_long(oidp, &val, 0, req); + if (error != 0 || req->newptr == NULL) return (error); - if (old_desiredvnodes != desiredvnodes) { - wantfreevnodes = desiredvnodes / 4; - /* XXX locking seems to be incomplete. */ - vfs_hash_changesize(desiredvnodes); - cache_changesize(desiredvnodes); - } + + if (val == desiredvnodes) + return (0); + mtx_lock(&vnode_free_list_mtx); + desiredvnodes = val; + wantfreevnodes = desiredvnodes / 4; + vnlru_recalc(); + mtx_unlock(&vnode_free_list_mtx); + /* + * XXX There is no protection against multiple threads changing + * desiredvnodes at the same time. Locking above only helps vnlru and + * getnewvnode. + */ + vfs_hash_changesize(desiredvnodes); + cache_changesize(desiredvnodes); return (0); } SYSCTL_PROC(_kern, KERN_MAXVNODES, maxvnodes, - CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RW, &desiredvnodes, 0, - sysctl_update_desiredvnodes, "UL", "Target for maximum number of vnodes"); + CTLTYPE_ULONG | CTLFLAG_MPSAFE | CTLFLAG_RW, NULL, 0, sysctl_maxvnodes, + "UL", "Target for maximum number of vnodes"); + +static int +sysctl_wantfreevnodes(SYSCTL_HANDLER_ARGS) +{ + u_long val; + int error; + + val = wantfreevnodes; + error = sysctl_handle_long(oidp, &val, 0, req); + if (error != 0 || req->newptr == NULL) + return (error); + + if (val == wantfreevnodes) + return (0); + mtx_lock(&vnode_free_list_mtx); + wantfreevnodes = val; + vnlru_recalc(); + mtx_unlock(&vnode_free_list_mtx); + return (0); +} + +SYSCTL_PROC(_vfs, OID_AUTO, wantfreevnodes, + CTLTYPE_ULONG | CTLFLAG_MPSAFE | CTLFLAG_RW, NULL, 0, sysctl_wantfreevnodes, + "UL", "Target for minimum number of \"free\" vnodes"); + SYSCTL_ULONG(_kern, OID_AUTO, minvnodes, CTLFLAG_RW, &wantfreevnodes, 0, "Old name for vfs.wantfreevnodes (legacy)"); static int vnlru_nowhere; @@ -591,6 +628,12 @@ vntblinit(void *dummy __unused) mtx_init(&mntid_mtx, "mntid", NULL, MTX_DEF); TAILQ_INIT(&vnode_free_list); mtx_init(&vnode_free_list_mtx, "vnode_free_list", NULL, MTX_DEF); + /* + * The lock is taken to appease WITNESS. + */ + mtx_lock(&vnode_free_list_mtx); + vnlru_recalc(); + mtx_unlock(&vnode_free_list_mtx); vnode_zone = uma_zcreate("VNODE", sizeof (struct vnode), NULL, NULL, vnode_init, vnode_fini, UMA_ALIGN_PTR, 0); vnodepoll_zone = uma_zcreate("VNODEPOLL", sizeof (struct vpollinfo), @@ -1211,7 +1254,16 @@ vnlru_free(int count, struct vfsops *mnt_op) mtx_unlock(&vnode_free_list_mtx); } +static void +vnlru_recalc(void) +{ + mtx_assert(&vnode_free_list_mtx, MA_OWNED); + gapvnodes = imax(desiredvnodes - wantfreevnodes, 100); + vhiwat = gapvnodes / 11; /* 9% -- just under the 10% in vlrureclaim() */ + vlowat = vhiwat / 2; +} + /* XXX some names and initialization are bad for limits and watermarks. */ static int vspace(void) @@ -1219,9 +1271,6 @@ vspace(void) u_long rnumvnodes, rfreevnodes; int space; - gapvnodes = imax(desiredvnodes - wantfreevnodes, 100); - vhiwat = gapvnodes / 11; /* 9% -- just under the 10% in vlrureclaim() */ - vlowat = vhiwat / 2; rnumvnodes = atomic_load_long(&numvnodes); rfreevnodes = atomic_load_long(&freevnodes); if (rnumvnodes > desiredvnodes)