我如何告诉Linux保留页面而不驱逐它? [英] How can I tell Linux to keep a page and not evict it?
问题描述
可能重复:
我可以告诉Linux不要换出特定进程的内存?
Possible Duplicate:
Can I tell Linux not to swap out a particular processes' memory?
我想在 Linux 中分配一块内存,并确保它不会出现#GP或#PF错误.关于#GP,作为程序员,我有责任确保不超出任何范围.但是,#PF是操作系统的责任,因为它可以选择是否逐出页面.
I want to allocate a chunk of memory in Linux and be sure that it will get no #GP or #PF faults. Regarding #GP, it's my responsibility as a programmer to ensure that I do not exceed any bounds. However, #PF are the the responsibility of the OS, since it can choose whether or not to evict a page.
我想像一下,如果我经常使用同一页面,那么该操作系统将足够聪明以至于无法逐出该页面.但是,如果我想分配一个大的内存块,那么我将花一些时间才能到达某些页面,并且我不希望OS在此同时退出它.
I imagine that if I use the same page frequently, the OS will be smart enough not to evict it. However, if I want to allocate a large block of memory, then it'll take me a while to reach some of the pages, and I don't want the OS to evict it in the meanwhile.
有什么方法可以告诉 Linux 使页面保持当前状态,从而永远不会出现页面错误?
Is there any way to tell Linux to keep a page present so that I never get a page fault?
Note: This is similar to to the question How can I tell Windows to keep a page and not evict it? except that this one is about Linux
推荐答案
I think you are looking for mlock
.
这篇关于我如何告诉Linux保留页面而不驱逐它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!