I am working on a system where we lock files in memory using mmap and MAP_LOCKED and MAP_POPULATE for performance. If we do this with a file that is in tmpfs, will it use the existing tmpfs memory area or will it make a copy for the mmap?
Asked
Active
Viewed 3,408 times
8
-
3I will suggest that this should be relatively easy to test. Check memory usage, lock a large file (a GB or two) and check memory usage again. – Centimane Mar 01 '17 at 18:54
-
Thanks for the suggestion. With the cache it's a bit hard to see what is going on but FYI I didn't see any increase in usage after calling mmap(). – ElefEnt Mar 01 '17 at 20:43
-
Using `free` the second line should show `-/+ buffers/cache:` which lists memory usage without including cache – Centimane Mar 01 '17 at 21:05
1 Answers
4
Tmpfs is a file system which keeps all files in virtual memory.
mmap copies file data to the disk cache when it needs the data to be in memory. With tmpfs, all the data is already in the disk cache (or swapped out). So mmapped data won't be copied: it's already in the place where it would be copied to.
Gilles 'SO- stop being evil'
- 807,993
- 194
- 1,674
- 2,175
-
Thanks, what about MAP_LOCKED, would it have any effect on a tmpfs file? – ElefEnt Mar 07 '17 at 00:56
-