On Fri, Nov 14, 2003 at 00:29:49 +0100, Daniele Bellucci wrote: > On Thu, Nov 13, 2003 at 10:55:57PM +0100, Jan Hudec wrote: > |On Thu, Nov 13, 2003 at 08:19:36 -0400, Allan.Bezerra@indt.org.br wrote: > |> Hi all, > |> > |> I was trying to get the stack, heap, data and code size separately allocated in physical memory but I did not manage to get them from /proc. > |> > |> I took a look the linux kernel source 2.6, but I did not discover any variables or structures about stack, heap, data and code size allocated in physical memory. > |> > |> I just found those information allocated in virtual memory. > |> > |> Please, could anybody help me? > | > |AFAIK there is no such information collected anywhere. AFACT it's > |actualy impossible. When process allocates memory, kernel only adds an > |entry into it's page table. The allocation is accounted for, but the > |allocated page does not exist anywhere -- it's only a promiss. > > . and this is the demand paging. What you say is not true at all. > If you look at sys_brk (mm/mmap.c) you will find the following > assignment: OOPS, sorry. It does not add a page table entry. It only adds or extens (mmap/setbrk) a vma. PTEs only describe pages in memory. > mm->brk = brk; > > (where brk is the start heap address) > > so .. one more time: please refer to the struct mm_struct > in include/sched.h > > (BE AWARE:this struct appears in struct task_struct, the process > descriptor) > > on every stack/heap grow/shrink the mm struct values of a given process > are correctly updated with no need to wait for a "demand page". > > > > |The page is actualy allocated in a page fault handler when the process > |tries to access it. > > yes, this is true .. but even if a page fault doesn't occours > the process descriptor (its mm struct) is updated correctly whenever > a new VMA is added. However, page fault handler does not add VMAs. Page fault handler adds PTEs. > > |It does not bother to look, whether it's a code, > |data, stack, etc. page. It only looks whether the page exists and from > |what file (or swap) it should be loaded. > Be AWARE: The stack is not mmapped. No, but it's pages. Every page is described by struct page. Each struct page belongs to struct address_space. That either belongs to an inode (filemap address_space), or is a special swap address_space. (I am not sure, if there is not actualy a special-case in the code to handle anonymous pages). ------------------------------------------------------------------------------- Jan 'Bulb' Hudec <bulb@ucw.cz> -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/