kern/134231: performance issue

Michel Henaut michel.henaut at
Tue May 5 13:20:03 UTC 2009

>Number:         134231
>Category:       kern
>Synopsis:       performance issue
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 05 13:20:02 UTC 2009
>Originator:     Michel Henaut
>Release:        5.5,6.2,6.3,6.4,7.0,7.1,7.2
everyware ltd
FreeBSD freebsd72-64.local 7.2-RELEASE FreeBSD 7.2-RELEASE
We have an application (server statistics), which uses sysctl and kvm_read. We
discovered that the Cpu use of our collector increased by 80% between 6.2 and
7.2. A small test program calling 10'000 sysctl gives the following result:
real    0m2.098s
user    0m0.000s
sys     0m2.073s
real    0m4.352s
user    0m0.036s
sys     0m4.119s 
Do you plan another way to get a sysctl resource other than the full scan done
in the different sysctl_find_oid. (use of tree instead of linked list).

#include <stdio.h>
#include <sys/types.h>
#include <sys/sysctl.h>
int main()
   int mib[4], st, nprocs;
   size_t size;
   int temp_op;
   int op = KERN_PROC_ALL;
   int arg = 0;
   int i;
   mib[0] = CTL_KERN;
   mib[1] = KERN_PROC;
   mib[2] = op;
   mib[3] = arg;
   temp_op = op & ~KERN_PROC_INC_THREAD;
   for (i = 0; i < 10000; i++) {
   st = sysctl(mib, 3, NULL, &size, NULL, 0);
   if (st == -1) {
      fprintf(stderr, "sysctl error\n");



More information about the freebsd-bugs mailing list