Hello xen-users!
We've been having issues with mmap on several (all we tested to date) of our
linux guest instances. The short C program that yields correct results on
normal kernels but fails to actually read the file into memory when run under
a domU kernel (tested with 2.6.16.33, 2.6.18, 2.6.21.7) is this:
#define _FILE_OFFSET_BITS 64
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
int main() {
int *where;
int fd;
struct stat st_buf;
fd = open("piggy", O_RDONLY);
fstat(fd, &st_buf);
where = mmap(NULL, st_buf.st_size, PROT_READ, MAP_SHARED | MAP_POPULATE,
fd, 0);
printf("Finished\n");
while(1) {
sleep(10);
}
munmap(where, st_buf.st_size);
close(fd);
return 0;
}
If you gcc -o mmap mmap.c, then create a piggy file of some gigabytes (but
less than you have available memory, of course) and then run mmap, the file
will be read from disk into memory and top will show a RES size of piggy file
size plus some extra kbytes.
If you do the same from within a domU instance, the mmap call will return a
valid pointer immediately, the VIRT will properly inflate but the RES will
not and the file will not be read into memory.
While it's possible we're doing something horribly wrong (and if anyone sees
an obvious error we don't, please point it out), I would like to know if
anyone else has had trouble with mmap within domU kernels before and if so,
if and how you have gotten it to work?
Thank you all for your time in advance,
--
Jure Koren
Zemanta Ltd, London, Ljubljana
www.zemanta.com
_______________________________________________
Xen-users mailing list
Xen-users@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-users
|