> > I use (as root) "cat maps | sort -r" in lecture quite
> > often. (The "sort -r" puts the addresses in high-to-low sequence which
> > I prefer when drawing memory diagrams.)
> Yes, I know about /proc/<pid>/maps and I will use it for my talk,
> too. But that does not give me the physical addresses of the pages.
They might not even have any physical address.
> > The "maps" are particularly informative with multi-threaded
> > applications as you will see each thread's stack allocation and,
> > depending on the version of Linux you have, you may also see "guard
> > pages" between the thread stacks.
The guard pages does not depend on the Linux version,
it depends on the threading library.
> I have just tried it. Interesting. But why have different threads
> their stack mapped at different addresses?
The threads share the same address space. So the only
way to have one stack for each thread is to place them
at different addresses. The threads can access each
others stacks by using the right addresses.
Quote:> I would assume the stack of each thread to start at 0xc0000000.
No. Only the initial thread will have the stack
starting at 0xc0000000. As soon as you start making
differences between the memory layout of the threads
they are no longer threads but processess.
> Do the threads of one process also share page directories and page
> tables or only pages frames?
They share it all.
Quote:> In the former case no thread could have
> private memory and it's clear that the stacks have to be at different
That is exactly the case.
Quote:> But I have thought that each thread has its own page dirs
> and page tables and only most of their page frames shared.
In that case it is not threads but processes using
shared memory. You can do that if you want to by
using SysV shared memory or the like. But you will
not get as good performance as with threads.
> But my questions remains, how can I get the physical address for a
> virtual address of a given process?
First we look at struct the task_struct:
and find the field named mm
This is a struct mm_struct
which has a mmap field of the type struct vm_area_struct
these are in a chained list.
But I don't see how to get from the vm_area_struct to
the actual pages, so I could be on the wrong track
Kasper Dupont -- der bruger for meget tid p? usenet.