8

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?

3
  • 3
    I 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
    Commented Mar 1, 2017 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
    Commented Mar 1, 2017 at 20:43
  • Using free the second line should show -/+ buffers/cache: which lists memory usage without including cache
    – Centimane
    Commented Mar 1, 2017 at 21:05

1 Answer 1

4

Tmpfs is a file system which keeps all files in virtual memory.

tmpfs lives completely in the page cache and on swap

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.

2
  • Thanks, what about MAP_LOCKED, would it have any effect on a tmpfs file?
    – ElefEnt
    Commented Mar 7, 2017 at 0:56
  • @ElefEnt I think so, but I'm not sure. Commented Mar 7, 2017 at 12:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .