How to get the information from /proc/files from within a kernel module?

Valdis.Kletnieks at vt.edu Valdis.Kletnieks at vt.edu
Mon Aug 25 11:45:57 EDT 2014


On Mon, 25 Aug 2014 19:57:39 +0530, ravali pullela said:

> I want process related information like rss.(we can get this by doing cat
> /proc/<pid>status) Is there a way to get this from within a kernel module?
> I checked out the sources on /proc filesystem. They all show how to create,
> read, write a new proc file. But I want to read from an existing proc file
> specifically /proc/<pid>/status

Don't bother reading the file. It's a *lot* faster and less buggy to just go
get the same data yourself.

> I could not find rss info of a process from its task struct in kernel
> version 3.10.
>
> I tried to look inside kernel to know how and where are these values (rss
> and all) are calculated by kernel. But I could not track it.

You apparently didn't look very hard:

[/usr/src/linux-next] grep RSS fs/proc/*.c
fs/proc/array.c:                rsslim = ACCESS_ONCE(sig->rlim[RLIMIT_RSS].rlim_
cur);
fs/proc/base.c: [RLIMIT_RSS] = {"Max resident set", "bytes"},
fs/proc/task_mmu.c:             "VmRSS:\t%8lu kB\n"
fs/proc/task_mmu.c: * Proportional Set Size(PSS): my share of RSS.

And 30 seconds of checking shows the first two to be rlimits not actual values,
so you're interested in the third.  Look at the source of fs/proc/task_mmu.c
at function task_mem().  Getting a valid pointer to a 'struct mm_struct *'
is left as an exercise for the student. :)

The bigger question is, of course, what you intend to try to *do* with
that info from inside a kernel module. Practical experience with several
years of kernel newbies shows that 90% of the time, the idea is misguided
and there's a better way to achieve the actual goal...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 848 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140825/89b77ac4/attachment.bin 


More information about the Kernelnewbies mailing list