For random read/write access to a mmap()
ed file, MADV_SEQUENTIAL
is probably not very useful (and may in fact cause undesired behavior). MADV_RANDOM
or MADV_DONTNEED
would be better options in this case. However, be aware that the kernel is free to ignore any madvise()
- although in my understanding, Linux currently does not, as it tends to treat madvise()
more as a command than an advisory...
Another option would be to mmap()
only selected sections of the file as needed, and munmap()
them as you're done with them, perhaps maintaining a pool of some small number of currently active mappings (i.e. mapping more than one region at once if needed, but still keeping it limited).