how can I get the meminfo of each kernel process?
Robert Watson
rwatson at FreeBSD.org
Mon May 30 05:01:16 PDT 2005
On Mon, 30 May 2005 littlegege at 263.net wrote:
> I want to get the meminfo of each kernel process,such as how much memory
> size is allocated to a process.How can i do? I will do this in kernel
> space,so which data structure can i used to achieve this.
Kernel processes are a bit of a misnomer -- in general, they actually
represent individual threads running in a single kernel address space. As
such, memory is typically not owned by the kernel process, it's owned by
the kernel as a whole. Normally, the approach taken is to track memory
owned by individual kernel subsystems, which can (in most cases) be done
using a combination of "vmstat -m" and "vmstat -z". Since individual
threads may enter many different subsystems, and the largest volumes of
memory are actually typically handed off between several threads (i.e.,
network packet buffers), this can provide better insight into memory use
in the kernel.
There are plans, in the future, to start using pure threads without
associated kernel processes in the kernel, which will reduce overhead as
well as make it more clear that kernel threads generally operate within a
single process (task) address space.
If you're interested in tracking memory allocation and use for specific
kernel threads, you might want to look at ktr(4), which is a general
kernel tracing primitive, and has hooks into the various kernel memory
allocators to track memory allocation and free events.
Robert N M Watson
More information about the freebsd-hackers
mailing list