How to prevent paging for one program / process?

前端 未结 3 1774
心在旅途
心在旅途 2020-12-31 05:10

I have a program that requires much memory, like 2/3 of all the physical ram. After some runtime my operating system begins to swap the program to hdd. But I need the progra

相关标签:
3条回答
  • 2020-12-31 05:32

    Use mmap() instead of malloc, and use the "MAP_LOCKED" flag. (works on linux > 2.5.37)

    0 讨论(0)
  • 2020-12-31 05:39

    At the start of the program, call:

    mlockall(MCL_CURRENT | MCL_FUTURE);
    

    (If you do not have the source to the program, you'll have to debauch the process with ptrace to do this).

    Be aware that this will increase the chances of memory allocations made by the process failing.

    0 讨论(0)
  • 2020-12-31 05:58

    Well, there's mlock for locking memory (telling the kernel it may not be swapped out), but that's meant for relatively small amounts of memory, and would require modification of the program.

    The other option might be to adjust Linux's "swappiness", i.e. its tendency to swap out pages. See here for an interesting discussion. That is not possible per process, however.

    I'm not aware of any per-process solution for your problem.

    0 讨论(0)
提交回复
热议问题