calculating resident size (in K)

From: Matthew Story <matthewstory_at_gmail.com>
Date: Fri, 24 Feb 2012 14:10:23 -0500
I'm working on kern/163033, and so far have written a sysctl for
controlling logging of additional process information on SIGKILL (or
SIGEXIT if logsigexit=1) from the kernel level, this logs proc size in K,
number of threads, process state and CPU utilization of the process, in
addition to the currently available information.

For resident memory, things are a touch trickier, I looked at top for
inspiration (possibly not the best place for inspiration ...), and from a
kinfo_proc I can calculate via rssize (sum of threads pages utilization,
and then use pagesize from there).  It's also possible, albeit with some
code repetition, to handle this from a proc (not kinfo_proc).  But there
are a few questions, the first of which is that the kern_proc.c code that
populates a kinfo_proc struct's rssize value, has a nice XXX next to it ...

        kp->ki_rssize = vmspace_resident_count(vm); /*XXX*/
        FOREACH_THREAD_IN_PROC(p, td0) {
            if (!TD_IS_SWAPPED(td0))
                kp->ki_rssize += td0->td_kstack_pages;
        }

... so I'm wondering if there are plans on changing the way this is
calculated, and what assumptions are safe in so far as calculating resident
memory (if things are likely to change).

The second question is that were resident memory logging enabled by this
sysctl (not sure that populating a kinfo_proc and calculating res memory is
necessarily an intelligent idea prior to a SIGKILL ... and the other
diagnostics give you enough information to debug intelligently, but for the
sake of argument ...), there would be at least 2 implementations which
calculate resident memory in K from pages (this one and top, there are
doubtlessly others).  Would it be useful to provide a function at the sys
level to return the calculated resident size in K from a kinfo_proc (or
just a regular old proc)?

-- 
regards,
matt
Received on Fri Feb 24 2012 - 18:34:47 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:24 UTC