Linux Stop Flushing of mmaped Pages To Disk

https:/‮/‬www.lautturi.com
Linux Stop Flushing of mmaped Pages To Disk

On a Linux system, the kernel's virtual memory management system is responsible for managing the memory of the system, including the memory used by processes, files, and other data. One of the tasks of the virtual memory management system is to write the contents of memory pages to disk when they are not needed in order to free up space in memory for other uses. This process is known as "paging" or "swapping".

By default, Linux will flush the contents of memory pages to disk as needed in order to manage the system's memory. However, you may want to disable this behavior for certain processes or files if you want to prevent the kernel from writing their contents to disk.

To stop the flushing of memory-mapped pages to disk, you can use the madvise command with the MADV_DONTFORK option. This will mark the pages as "dontneed", which tells the kernel not to write them to disk when the system is paging or swapping.

Here is an example of how you can use the madvise command to stop the flushing of memory-mapped pages to disk:

madvise -MADV_DONTFORK file

This command will mark the memory-mapped pages of the file file as "dontneed", which will prevent the kernel from writing them to disk when the system is paging or swapping.

Note that this behavior is not persistent and will only apply to the current session. If you want to make the change permanent, you will need to modify the system's paging and swapping settings. You can do this by modifying the kernel's vm.swappiness and vm.dirty_ratio parameters, which control how aggressively the kernel will page or swap memory pages to disk.

It is also worth noting that disabling the flushing of memory-mapped pages to disk can have negative consequences on the system's performance and stability. It is generally not recommended to disable paging or swapping unless you have a specific reason to do so.

Created Time:2017-10-30 10:17:39  Author:lautturi