[uClinux-dev] enable /proc/PID/smap

Phil Wilshire pwilshire at cox.net
Thu Feb 5 00:31:38 EST 2009

Phil Wilshire wrote:
> Robert Wessels wrote:
>> Hi,
>> I have been subscribed to this list for a while now and found a lot of 
>> answers to my questions in the archives. Thank you for that!
>> One I could not find, and hope someone can help me answer, is:
>> How do I enable /proc/PID/smap in the uClinux kernel.
>> I would like to have so that I can keep a tap on what the current 
>> stack size allocation is of a certain process.
>> Hopefully I will be able to contribute to this list ones I get more 
>> familiar with uClinux.
>> Thanks,
>> Robert Wessels
> Hi Robert,
> The code for smap is in linux/fs/proc/task_mmu.c
> The use of this file  is disabled in linux/fs/proc/Makefile
> where linux/fs/proc/task_nommu.c is used.
> The proc/PID/smap option does not seem to be enabled in that file.
> YOu may be able to copy some of the code  linux/fs/proc/task_mmu.c but 
> will have to find a different way to discover the stack size.
> However, since the stack is fixed in noMMU uClinux, you can simply
> look at the  executables  and see what the stack allocation is for those 
> files.
> The "flthdr" tool will tell you this information if you are using a
> flat file based system.
> Hope this helps
>   Phil Wilshire

Extra information.
Look in linux/fs/proc/base.c for the definition

REG("smaps", S_IRUGO, smaps);

This is only defined for the CONFIG_MMU case.
If you manage to put some form of smaps into task_nommu.c you will also
have to remove the CONFIG_MMU restraint on the REG statement.

I got interested to find out how these proc entries "magically" appear.

Once you define the REG statement all you need to do is include a file 
with the definition of "proc_smaps_operations" and its other helper 
( See linux/fs/proc/internal.h for the prototype )

The  "proc_smaps_operations" structure will lead to a definition of
a "seq_file" operation to produce the actual proc output.

This is not for the faint hearted at all, but, if you follow the code 
through, the actual data is produced by the code fragment
"show_smap" in  the file linux/fs/proc/task_mmu.c
This function is, in turn, activated by the "smap_open" function in the 
  same file.
There are some other functions "m_start" "m_next" and "m_stop"  that 
navigate through the process table.
All that "show_smap" needs to do is produce the output strings
using "seq_printf" etc form the "vma" presented by the "m_next" function.
If you look at it long enough you will start to see how the logic works.


More information about the uClinux-dev mailing list