views:

243

answers:

1

Consider this because this region maps the files like dynamically loaded libraries, i feel it should ideally grow up. this can be implemented by starting the mmap region between RLIMIT_STACK and heap beginning. what problems would occur in this case.

if it grows down, then how is a new memory mapped region created. suppose we wish to map the code for abc.so in the virtual address space, then we would have to create sizeof(abc.so) space, in the downward direction and map file starting at the bottom of this region. is this how it works?

+1  A: 

Are you sure you're not confusing "up" in the diagram with "up" in the sense of increasing addresses? Note that the diagram has the low address in the top [Edit: No actually, it has the low address at the bottom, my bad].

The mapped area grows towards lower addresses. Why do you feel it should grow in the other direction? If the mapped files and the heap start in opposite directions of the address space and grow towards each other you maximize the address space utilization before the areas collide.

When you map a file you just map a contigous range of addresses to be backed by the file (from low to high addresses, which is what you would expect). When you access a page a page fault will occur and the file content is copied into the memory page frame.

Per Ekman
I'm pretty sure address 0 is at the bottom of that diagram..
Michael Foukarakis
right, and also the stack is growing in the downward direction, i.e. towards lower addresses.
iamrohitbanga
They eyes are the first thing you go blind in... Sorry.Anyway, it's pretty arbitrary which way the heap and themapped file regions grow since they are allocated in blocks.
Per Ekman
That sounds right. stack is expected to grow the least, esp. if the process doesn't raise its RLIMIT_STACK. So the stack is left a small amount of space, while the heap and the mmap region grow towards each other from as far away as possible. Thanks goodness for AMD64.
Peter Cordes