tags:

views:

38

answers:

2

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  A: 

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.

torak
+1  A: 

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.

waffleman