From 4d34e019c4df776fe9c114e3945a413e30ed48a5 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Wed, 23 May 2012 18:10:54 +0000 Subject: [PATCH] Calculate the count of per-process cow faults. Export the count to userspace using the obscure spare int field in struct kinfo_proc. Submitted by: Andrey Zonov MFC after: 1 week --- sys/kern/kern_proc.c | 4 ++++ sys/sys/proc.h | 1 + sys/sys/user.h | 2 +- sys/vm/vm_fault.c | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index cf7657668f00..3988a9390f11 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -878,6 +878,9 @@ fill_kinfo_proc_only(struct proc *p, struct kinfo_proc *kp) kp->ki_childtime = kp->ki_childstime; timevaladd(&kp->ki_childtime, &kp->ki_childutime); + FOREACH_THREAD_IN_PROC(p, td0) + kp->ki_cow += td0->td_cow; + tp = NULL; if (p->p_pgrp) { kp->ki_pgid = p->p_pgrp->pg_id; @@ -990,6 +993,7 @@ fill_kinfo_thread(struct thread *td, struct kinfo_proc *kp, int preferthread) kp->ki_runtime = cputick2usec(td->td_rux.rux_runtime); kp->ki_pctcpu = sched_pctcpu(td); kp->ki_estcpu = td->td_estcpu; + kp->ki_cow = td->td_cow; } /* We can't get this anymore but ps etc never used it anyway. */ diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 0873927b0c6c..3f24ae936f8c 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -247,6 +247,7 @@ struct thread { int td_slptick; /* (t) Time at sleep. */ int td_blktick; /* (t) Time spent blocked. */ int td_swvoltick; /* (t) Time at last SW_VOL switch. */ + u_int td_cow; /* (*) Number of copy-on-write faults */ struct rusage td_ru; /* (t) rusage information. */ struct rusage_ext td_rux; /* (t) Internal rusage information. */ uint64_t td_incruntime; /* (t) Cpu ticks to transfer to proc. */ diff --git a/sys/sys/user.h b/sys/sys/user.h index 2c37e9972cd1..42733a6ee2ab 100644 --- a/sys/sys/user.h +++ b/sys/sys/user.h @@ -159,7 +159,7 @@ struct kinfo_proc { u_int ki_estcpu; /* Time averaged value of ki_cpticks */ u_int ki_slptime; /* Time since last blocked */ u_int ki_swtime; /* Time swapped in or out */ - int ki_spareint1; /* unused (just here for alignment) */ + u_int ki_cow; /* number of copy-on-write faults */ u_int64_t ki_runtime; /* Real time in microsec */ struct timeval ki_start; /* starting time */ struct timeval ki_childtime; /* time used by process children */ diff --git a/sys/vm/vm_fault.c b/sys/vm/vm_fault.c index fde5d4a75447..e3a29f003984 100644 --- a/sys/vm/vm_fault.c +++ b/sys/vm/vm_fault.c @@ -805,6 +805,7 @@ RetryFault:; if (!is_first_object_locked) VM_OBJECT_LOCK(fs.object); PCPU_INC(cnt.v_cow_faults); + curthread->td_cow++; } else { prot &= ~VM_PROT_WRITE; }