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

ravali pullela rpravali069 at gmail.com
Fri Aug 29 15:51:12 EDT 2014


Hi,

I tried to do the following. Calculate rss using virtual address to
physical page mappings. But *the value calculated using this method is
greater than the value reported by get_mm_rss*, the api which reports the
process rss in /proc/pis/status.

The way I tried to calculate rss is to count pages whose virtual to
physical mappings are valid and for which page is present. I am doing this
on the entire va space so that I can check every page if it is present and
increment a counter.

The problem is that when i looked inside get_mm_rss function, it returns
                get_mm_counter(mm, MM_FILEPAGES) +
                get_mm_counter(mm, MM_ANONPAGES);

I thought that anonymous and file pages cover all vm areas like stack,
heap, code, data etc., but it does not look like. So, what is it that I am
missing.

Note: The value calculated by my module is approximately same as the sum of
rss reported by /proc/pid/smaps for all vmas.

Thanks


On Mon, Aug 25, 2014 at 11:07 PM, ravali pullela <rpravali069 at gmail.com>
wrote:

> Thank you so much Valdis and Aruna. Probably, the problem was I tried to
> search more on internet rather than kernel source and after 3 hours(I know
> it is long), I understood that I am nowhere going in the right direction.
>
> I have the mm_struct * with me. grepping is more useful.
>
> Thanks again to all the people who are supporting kernel newbies :)
>
>
> On Mon, Aug 25, 2014 at 10:12 PM, Aruna Hewapathirane <
> aruna.hewapathirane at gmail.com> wrote:
>
>> >> 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
>>>
>>
>> Have a look here: https://gist.github.com/Aruna-Hewapathirane
>> /f41e7291e15bae6062a1 does exactly what your trying to do.
>>
>> >> Can anyone please point me to either resources or guide me to
>>> accomplish the task of reading information from
>>>
>> >>/proc/files...
>>>
>>
>> I would suggest you go through the source code for PS : http://procps.
>> sourceforge.net/ and carefully study how things are done.
>>
>> This will also help: https://www.kernel.org/doc/Documentation/filesystems
>> /proc.txt
>>
>> That being said I have to agree fully with Valdis the best way is always
>> to grep through the kernel that way you get to see code that is being used
>> and how things are done.
>>
>> With all due respect to all the more experienced and knowledgeable folks
>> on the list I had great difficulty when I first started out accessing
>> information and I have no wish to see anyone who is fascinated by the
>> kernel and wants to mess with the internals be it for fun as a hobby to
>> learn or for serious patching and contributing to the kernel walk away
>> frustrated like I did so many times. ( I always walked right back though...
>> :)
>>
>> Yes Valdis you can give me a hard time on IRC when I next show up :)
>>
>> Aruna ( Ravali, please heed Valdis's advice that is the best way. I just
>> pointed you in the right direction with a bit more code to play with but
>> try to do your own digging first through the kernel and good luck ! )
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140830/20ef9d13/attachment.html 


More information about the Kernelnewbies mailing list