Rohit Banga
Rohit Banga

Reputation: 18918

Why does the memory mapped region grow down in Linux

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?

Upvotes: 0

Views: 1892

Answers (1)

Per Knytt
Per Knytt

Reputation: 2011

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.

Upvotes: 1

Related Questions