How to make every page of a process in the page table present?

眉间皱痕 提交于 2019-12-11 00:25:31

问题


i compiled a static program using gcc on linux and run it under kvm. I checked every page table entry of this process in guest memory and found that some pages have been mapped and some ones are not. Is this the feature of on-demand paging? My question is whether there is a solution to make all the pte present and mapped in the page table? E.g. i fork a new process and load a new elf binary, how to make every page mapped in the page table of this new process. Thanks


回答1:


Try out the following system call:

#include <sys/mman.h>

int mlockall(int flags);

Set the flags parameter with MCL_FUTURE and it will lock all current and future pages into memory. You can find more info about it here or just type "man mlockall" and you will get a bunch of information.




回答2:


The linux API for this is mlock().

However, if you're trying to do this in a linux VM running on top of KVM I don't think there's a way for usermode code to make this work. It is possible that a paravirtualized linux kernel might have access to some KVM APIs that it could uses for this sort of thing, but kind of doubt it would do so.



来源:https://stackoverflow.com/questions/3355790/how-to-make-every-page-of-a-process-in-the-page-table-present

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!