NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/45539: add support for getrusage(2) memory size statistics



>Number:         45539
>Category:       kern
>Synopsis:       add support for getrusage(2) memory size statistics
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Oct 29 01:55:00 +0000 2011
>Originator:     Greg A. Woods
>Release:        NetBSD -current 2011/10/28
>Organization:
Planix, Inc.; Kelowna, BC; Canada
>Environment:
System: NetBSD
Architecture: all
Machine: all
>Description:

        some time between 4.3BSD and 4.4BSD the code to track process
        memory size statistics was removed and never re-written, so it
        has been missing in NetBSD since the beginning

>How-To-Repeat:

        run "/usr/bin/time -l some-big-long-running-process" and note
        that the memory size stats are always zero

>Fix:

        (untested in -current, but tested in netbsd-5)

--- kern_clock.c        28 Sep 2011 16:06:27 -0700      1.128
+++ kern_clock.c        28 Oct 2011 18:43:48 -0700      
@@ -427,6 +427,36 @@
                        spc->spc_cp_time[CP_IDLE]++;
                }
        }
+       /*
+        * If the CPU is currently scheduled to a non-idle process, then charge
+        * that process with the appropriate VM resource utilization for a tick.
+        *
+        * Assume that the current process has been running the entire last
+        * tick, and account for VM use regardless of whether in user mode or
+        * system mode (XXX or interrupt mode?).
+        *
+        * rusage VM stats are expressed in kilobytes * ticks-of-execution.
+        */
+       /* based on code from 4.3BSD kern_clock.c and from FreeBSD */
+
+# define pg2kb(n)      (((n) * PAGE_SIZE) / 1024)
+
+       if (p != NULL) {
+               struct vmspace *vm = p->p_vmspace;
+               long rss;
+
+               /*
+                * XXX is p_stmutex currently enough to protect updates to
+                * p_stats too?
+                */
+               p->p_stats->p_ru.ru_idrss += pg2kb(vm->vm_dsize); /* unshared 
data */
+               p->p_stats->p_ru.ru_isrss += pg2kb(vm->vm_ssize); /* unshared 
stack */
+               p->p_stats->p_ru.ru_ixrss += pg2kb(vm->vm_tsize); /* "shared" 
text? */
+
+               rss = pg2kb(vm_resident_count(vm));
+               if (rss > p->p_stats->p_ru.ru_maxrss)
+                       p->p_stats->p_ru.ru_maxrss = rss;
+       }
        spc->spc_pscnt = psdiv;
 
        if (p != NULL) {



Home | Main Index | Thread Index | Old Index