Re: mremap() proposal (was Re: malloc and joe)

Linus Torvalds (torvalds@cs.helsinki.fi)
Sun, 24 Mar 1996 19:59:38 +0200 (EET)


On Sun, 24 Mar 1996, Snow Cat wrote:
>
> If the mapping grows, what is the content of new pages? Is it always
> MAP_ANON or new sections of the same file that was used for mapping?

Conceptually, mremap() really only extends/shrinks the memory mapping, so
the new pages will be an extension of whatever the old mmap was. In most
cases (at least for the malloc case) this will be a anonymous mapping,
but it's by no means an error to extend any mapping you have created.

Extending a file mapping could potentially be useful if you want to track
a file when it grows, for example. You'd just do something like

addr = mmap(... st.st_size ...)

for the initial mapping, and then when the process notices that the file
has grown (or shrunk), it does a

mremap(addr, old_size, st.st_size)

to be able to read the new pages. A very logical interface, in fact.

Linus