Quote:
Originally Posted by
iamjag
Thanks Corona for your opinion.
I have been reading about mmap and I have understood
that you need a process running to keep the file in-memory.
Do not try to outsmart the operating system. Whether
anything is in-memory is up to it -- things will get paged out at need. This includes shm segments too, so having it "purely in ram" is an illusion. Things which are
frequently used will stay in memory.
Besides, with mmap, you get a file. With shm, you don't -- reboot and it's gone forever.
mmap may be actually more efficient since it doesn't need to back it with swap, only with file.
Quote:
I like the idea of a process which makes the memory available for the first time and does not need to be running later. Also, this operation could be delegated to the own library at the first time it is called. Is this posible using mmap?
Do not try to outsmart the operating system. Whether
anything is in-memory, be it code or data, is up to it. There are reasons for this. Just dumping everything into memory isn't always for the best.
On some systems you can tell mmap to preload the data, or you can mlock() the segment you want to keep in, but this is generally not necessary -- especially when the amount of data isn't huge. Frequeqntly-used data
will stay in memory.
If the amount of data
is huge, you
don't want it all in memory, only the frequently used bits which will actually fit, for efficiency reasons. Large database systems often rely on mmap and the system deciding intelligently which things belong in memory.