diff options
-rw-r--r-- | sys/kern/kern_fork.c | 15 | ||||
-rw-r--r-- | sys/sys/vmmeter.h | 11 | ||||
-rw-r--r-- | sys/vm/vm_meter.c | 16 | ||||
-rw-r--r-- | usr.bin/vmstat/vmstat.c | 8 |
4 files changed, 50 insertions, 0 deletions
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index 9dc8ec3..e8f8a60 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -65,6 +65,7 @@ #include <vm/vm_extern.h> #include <vm/vm_zone.h> +#include <sys/vmmeter.h> #include <sys/user.h> static MALLOC_DEFINE(M_ATFORK, "atfork", "atfork callback"); @@ -517,6 +518,20 @@ again: */ vm_fork(p1, p2, flags); + if (flags == (RFFDG | RFPROC)) { + cnt.v_forks++; + cnt.v_forkpages += p2->p_vmspace->vm_dsize + p2->p_vmspace->vm_ssize; + } else if (flags == (RFFDG | RFPROC | RFPPWAIT | RFMEM)) { + cnt.v_vforks++; + cnt.v_vforkpages += p2->p_vmspace->vm_dsize + p2->p_vmspace->vm_ssize; + } else if (p1 == &proc0) { + cnt.v_kthreads++; + cnt.v_kthreadpages += p2->p_vmspace->vm_dsize + p2->p_vmspace->vm_ssize; + } else { + cnt.v_rforks++; + cnt.v_rforkpages += p2->p_vmspace->vm_dsize + p2->p_vmspace->vm_ssize; + } + /* * Both processes are set up, now check if any loadable modules want * to adjust anything. diff --git a/sys/sys/vmmeter.h b/sys/sys/vmmeter.h index 0ca8432..f6e17ff 100644 --- a/sys/sys/vmmeter.h +++ b/sys/sys/vmmeter.h @@ -92,6 +92,17 @@ struct vmmeter { u_int v_pageout_free_min; /* min number pages reserved for kernel */ u_int v_interrupt_free_min; /* reserved number of pages for int code */ u_int v_free_severe; /* severe depletion of pages below this pt */ + /* + * Fork/vfork/rfork activity. + */ + u_int v_forks; /* number of fork() calls */ + u_int v_vforks; /* number of vfork() calls */ + u_int v_rforks; /* number of rfork() calls */ + u_int v_kthreads; /* number of fork() calls by kernel */ + u_int v_forkpages; /* number of VM pages affected by fork() */ + u_int v_vforkpages; /* number of VM pages affected by vfork() */ + u_int v_rforkpages; /* number of VM pages affected by rfork() */ + u_int v_kthreadpages; /* number of VM pages affected by fork() by kernel */ }; #ifdef _KERNEL diff --git a/sys/vm/vm_meter.c b/sys/vm/vm_meter.c index 3e573d7..2fa0754 100644 --- a/sys/vm/vm_meter.c +++ b/sys/vm/vm_meter.c @@ -323,6 +323,22 @@ SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_interrupt_free_min, CTLFLAG_RD, &cnt.v_interrupt_free_min, 0, ""); SYSCTL_INT(_vm_stats_misc, OID_AUTO, zero_page_count, CTLFLAG_RD, &vm_page_zero_count, 0, ""); +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, + v_forks, CTLFLAG_RD, &cnt.v_forks, 0, "Number of fork() calls"); +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, + v_vforks, CTLFLAG_RD, &cnt.v_vforks, 0, "Number of vfork() calls"); +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, + v_rforks, CTLFLAG_RD, &cnt.v_rforks, 0, "Number of rfork() calls"); +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, + v_kthreads, CTLFLAG_RD, &cnt.v_kthreads, 0, "Number of fork() calls by kernel"); +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, + v_forkpages, CTLFLAG_RD, &cnt.v_forkpages, 0, "VM pages affected by fork()"); +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, + v_vforkpages, CTLFLAG_RD, &cnt.v_vforkpages, 0, "VM pages affected by vfork()"); +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, + v_rforkpages, CTLFLAG_RD, &cnt.v_rforkpages, 0, "VM pages affected by rfork()"); +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, + v_kthreadpages, CTLFLAG_RD, &cnt.v_kthreadpages, 0, "VM pages affected by fork() by kernel"); #if 0 SYSCTL_INT(_vm_stats_misc, OID_AUTO, page_mask, CTLFLAG_RD, &page_mask, 0, ""); diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c index a5c17f8..1b2d159 100644 --- a/usr.bin/vmstat/vmstat.c +++ b/usr.bin/vmstat/vmstat.c @@ -600,6 +600,10 @@ dosum() (void)printf("%9u software interrupts\n", sum.v_soft); (void)printf("%9u traps\n", sum.v_trap); (void)printf("%9u system calls\n", sum.v_syscall); + (void)printf("%9u kernel threads created\n", sum.v_kthreads); + (void)printf("%9u fork() calls\n", sum.v_forks); + (void)printf("%9u vfork() calls\n", sum.v_vforks); + (void)printf("%9u rfork() calls\n", sum.v_rforks); (void)printf("%9u swap pager pageins\n", sum.v_swapin); (void)printf("%9u swap pager pages paged in\n", sum.v_swappgsin); (void)printf("%9u swap pager pageouts\n", sum.v_swapout); @@ -617,6 +621,10 @@ dosum() (void)printf("%9u zero fill pages prezeroed\n", sum.v_ozfod); (void)printf("%9u intransit blocking page faults\n", sum.v_intrans); (void)printf("%9u total VM faults taken\n", sum.v_vm_faults); + (void)printf("%9u pages affected by kernel thread creation\n", sum.v_kthreadpages); + (void)printf("%9u pages affected by fork()\n", sum.v_forkpages); + (void)printf("%9u pages affected by vfork()\n", sum.v_vforkpages); + (void)printf("%9u pages affected by rfork()\n", sum.v_rforkpages); (void)printf("%9u pages freed\n", sum.v_tfree); (void)printf("%9u pages freed by daemon\n", sum.v_dfree); (void)printf("%9u pages freed by exiting processes\n", sum.v_pfree); |