I am trying to find any system functionality that would allow a process to allocate temporary memory, that is, memory that is considered discarded by the process and can be removed by the system when memory is required, but allowing it to benefit from available memory when possible. In other words, a process tells the system that it is ready to sacrifice a block of memory when the process is not using it. Releasing a block is also preferable for replacing it (more expensive or expensive, to replace it and then re-compile its contents).
Systems (like Linux) have things in the kernel like the F / S memory cache. I am looking for something like this, but accessible to user space.
I understand that there are ways to do this from a program, but it is really a great job for the kernel to handle this. To some extent, I ask the kernel:
- if you need to reduce my or another place of residence, first delete these temporary pages.
- If you are shooting these temporary pages, do not change them, just cancel them.
In particular, I'm interested in a solution that will work on Linux, but it would be interesting to know if there are any other O / S.
UPDATE
An example of how I expect this to work:
- display page (swap). There is no difference with what is available right now.
- tell the kernel that the page is "temporary" (due to the lack of a better name), which means that if this page leaves, I do not want it to be loaded.
- tell the kernel that I need a temporary back page. If the page was not displayed, since I designated it as “temporary”, I was told that this happened. If this does not happen, it starts behaving like a regular page.
Here are the problems associated with an existing MM:
To prevent pages from loading, I have to distribute them throughout. But then they can be pulled out at any time, without warning. Testing with mincore () does not guarantee that the page will still be at the time mincore () is complete. Using mlock () requires elevated privileges.
So, the closest I can do this is using mlock () and anonymous pages. Following the expectations that I set out earlier, it will be:
- display anonymous blocked page. (MAP_ANON | MAP_LOCKED | MAP_NORESERVE). Print a page using magic.
- to create the page "temporarily", unlock the page
- if necessary, block the page again. If there is magic, this is my data, otherwise it was lost, and I need to restore it.
However, I do not need the pages to be locked in RAM when I use them. In addition, MAP_NORESERVE is problematic if the memory is overloaded.
source share