From 6947b628664f2cb071da0737b610e73ce330f5bf Mon Sep 17 00:00:00 2001 From: simonb Date: Sun, 25 Jul 2021 06:06:40 +0000 Subject: [PATCH] If we're only doing a count-only kern.buf sysctl, just return the number of active members in the pool cache (plus some slop) instead of looking in all the free buffer list. Should reduce CPU usage for "systat vm" to << 1% especially for machines with a larger number of buffers. --- sys/kern/vfs_bio.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index 327e999176c0..6b31d884d35a 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_bio.c,v 1.300 2021/07/24 13:28:14 simonb Exp $ */ +/* $NetBSD: vfs_bio.c,v 1.301 2021/07/25 06:06:40 simonb Exp $ */ /*- * Copyright (c) 2007, 2008, 2009, 2019, 2020 The NetBSD Foundation, Inc. @@ -123,7 +123,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.300 2021/07/24 13:28:14 simonb Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.301 2021/07/25 06:06:40 simonb Exp $"); #ifdef _KERNEL_OPT #include "opt_bufcache.h" @@ -1804,6 +1804,14 @@ sysctl_dobuf(SYSCTLFN_ARGS) elem_size < 1 || elem_count < 0) return (EINVAL); + if (oldp == NULL) { + /* count only, don't run through the buffer queues */ + needed = pool_cache_nget(buf_cache) - pool_cache_nput(buf_cache); + *oldlenp = (needed + KERN_BUFSLOP) * elem_size; + + return 0; + } + error = 0; needed = 0; sysctl_unlock(); @@ -1848,8 +1856,6 @@ sysctl_dobuf(SYSCTLFN_ARGS) sysctl_relock(); *oldlenp = needed; - if (oldp == NULL) - *oldlenp += KERN_BUFSLOP * elem_size; return (error); }