memory: move preallocation code out of exec.c

So that backends can use it.

Since we need the page size for efficiency, move code to compute it
out of translate-all.c and into util/oslib-win32.c.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
Paolo Bonzini 2014-05-14 17:43:21 +08:00 committed by Michael S. Tsirkin
parent e1c57ab86f
commit 38183310be
6 changed files with 97 additions and 50 deletions

View file

@ -350,3 +350,22 @@ gint g_poll_fixed(GPollFD *fds, guint nfds, gint timeout)
return num_completed;
}
size_t getpagesize(void)
{
SYSTEM_INFO system_info;
GetSystemInfo(&system_info);
return system_info.dwPageSize;
}
void os_mem_prealloc(int fd, char *area, size_t memory)
{
int i;
size_t pagesize = getpagesize();
memory = (memory + pagesize - 1) & -pagesize;
for (i = 0; i < memory / pagesize; i++) {
memset(area + pagesize * i, 0, 1);
}
}