如何禁用我的一个用户空间程序中的“请求分页”?

时间:2022-05-19 07:22:20

For an dedicated test I have to disable "demand paging" for exactly one of my userspace programs

对于专门的测试,我必须为我的一个用户空间程序禁用“请求分页”

http://en.wikipedia.org/wiki/Demand_paging

Any idea how I could do this ? (embedded linux appliance; 2.6 kernel)

你知道我该怎么做吗?(嵌入式linux设备;2.6内核)

1 个解决方案

#1


3  

If you have the ability to modify the application, you could use the mlock() / mlockall() system calls to ensure that your memory doesn't get paged out:

如果您有能力修改应用程序,您可以使用mlock() / mlockall()系统调用来确保您的内存不会被分页:

#include <sys/mman.h>

mlockall(MCL_FUTURE);

This will prevent all memory currently allocated, and any future memory that is allocated to this process from being swapped out. You can use the mlock() system call to get finer control over which parts of memory are locked.

这将防止当前分配的所有内存和分配给此进程的任何未来内存被交换出去。您可以使用mlock()系统调用来更好地控制哪些内存部分被锁定。

#1


3  

If you have the ability to modify the application, you could use the mlock() / mlockall() system calls to ensure that your memory doesn't get paged out:

如果您有能力修改应用程序,您可以使用mlock() / mlockall()系统调用来确保您的内存不会被分页:

#include <sys/mman.h>

mlockall(MCL_FUTURE);

This will prevent all memory currently allocated, and any future memory that is allocated to this process from being swapped out. You can use the mlock() system call to get finer control over which parts of memory are locked.

这将防止当前分配的所有内存和分配给此进程的任何未来内存被交换出去。您可以使用mlock()系统调用来更好地控制哪些内存部分被锁定。