In Linux, is it possible to mmap() a file in such a way that it will never be swapped out to a disk in favor of files which, using the normal read(), have been placed into the page/buffer cache?
-
If not using mmap(), it seems like there should be a way to give certain files "priority", so that the only time they're swapped out is for page faults trying to bring in, e.g., executing code, or memory that was malloc()'d by some process. One can think of situations where this could be useful. Consider search engines, which should keep their index files in cache. EDIT: Specifically, the mmap()'d file should still be pageable, just not in favor of other files. In the example, the search index files could be enormous, so using mlock() is out of the question unfortunately.
-
Answer:
There is an mlock(2) call for this specific purpose: to lock region of memory into physical memory. See [1] Second, to lock something into memory, it has to be a virtual memory region. It must be allocated by mmap, malloc or similar calls, but not read(2). Read(2) requires a pre-allocated memory region to be passed in, which is either malloc-ed / mmap-ed, or automatically allocated on the stack. [1] http://man7.org/linux/man-pages/man2/mlock.2.html
Ryan Gao at Quora Visit the source
Other answers
madvise with MADV_WILLNEED may give the area a priority over other system cache pages, but I'm not sure how it is implemented in Linux.
Alexander Lukyanov
Related Q & A:
- Is it possible to use a phone camera as a webcam?Best solution by Yahoo! Answers
- Is it possible to use a game controller as a mouse?Best solution by Yahoo! Answers
- How can a person even get a credit card when they never had any credit before?Best solution by credit.com
- Is it possible to do a live broadcast with a regular camera?Best solution by support.google.com
- Is it possible to have a chemical change without a physical change?Best solution by mcwdn.org
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.