From: Peter Dinda Date: Fri, 17 Apr 2015 15:11:53 +0000 (-0500) Subject: Expose vmalloc-like os interface to Palacios, and updates to use it X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=659151a0b655c619f3acbb98a45e9eeb8002a4b3;p=palacios.git Expose vmalloc-like os interface to Palacios, and updates to use it The purpose of finally exposing virtually contiguous / not necessarily physically contiguous allocations to Palacios is to get around a catch-22. We support arbitrarily small base region chunks at this point, down to a page size. We also support host kernels that do not provide large contiguous physical page allocations. The result is that we can end up needing to build a base region chunk array that is larger than the amount of memory we can either malloc or contiguously page alloc to support it. Yet the base region array itself does not need to be physically contiguous. Two places where this currently burns us is: large memory VM allocated over linux host that does not support hot remove; moderate memory VM using tiny chunk size, for example in cache partitioning --- diff --git a/linux_module/palacios-stubs.c b/linux_module/palacios-stubs.c index d5e27b3..54b2ad1 100644 --- a/linux_module/palacios-stubs.c +++ b/linux_module/palacios-stubs.c @@ -868,6 +868,8 @@ static struct v3_os_hooks palacios_os_hooks = { .print = palacios_print_scoped, .allocate_pages = palacios_allocate_pages, .free_pages = palacios_free_pages, + .vmalloc = palacios_valloc, + .vfree = palacios_vfree, .malloc = palacios_alloc, .free = palacios_free, .vaddr_to_paddr = palacios_vaddr_to_paddr, diff --git a/palacios/include/palacios/vmm.h b/palacios/include/palacios/vmm.h index 1f6228e..14bbb2b 100644 --- a/palacios/include/palacios/vmm.h +++ b/palacios/include/palacios/vmm.h @@ -147,6 +147,24 @@ int v3_get_vcore(struct guest_info *); } \ } while (0) +#define V3_VMalloc(size) ({ \ + extern struct v3_os_hooks * os_hooks; \ + void * var = 0; \ + if ((os_hooks) && (os_hooks)->vmalloc) { \ + var = (os_hooks)->vmalloc(size); \ + } \ + if (!var) PrintError(VM_NONE,VCORE_NONE,"VMALLOC FAILURE. Memory LEAK!!\n"); \ + var; \ + }) + +#define V3_VFree(addr) \ + do { \ + extern struct v3_os_hooks * os_hooks; \ + if ((os_hooks) && (os_hooks)->vfree) { \ + (os_hooks)->vfree(addr); \ + } \ + } while (0) + // uint_t V3_CPU_KHZ(); #define V3_CPU_KHZ() ({ \ unsigned int khz = 0; \ @@ -338,10 +356,16 @@ struct v3_os_hooks { // For page allocation: // - node_id -1 => any node, otherwise the numa node we want to alloc from // - constraint = 0 => no constraints, otherwise a bitwise-or of the following flags + // Allocates physically contiguous pages #define V3_ALLOC_PAGES_CONSTRAINT_4GB 1 void *(*allocate_pages)(int num_pages, unsigned int alignment, int node_id, int constraint); void (*free_pages)(void * page, int num_pages); + // Allocates virtually contiguous memory + void *(*vmalloc)(unsigned int size); + void (*vfree)(void * addr); + + // Allocates virtually and physically contiguous memory void *(*malloc)(unsigned int size); void (*free)(void * addr); diff --git a/palacios/src/palacios/vmm_mem.c b/palacios/src/palacios/vmm_mem.c index a074bfc..aa71a8b 100644 --- a/palacios/src/palacios/vmm_mem.c +++ b/palacios/src/palacios/vmm_mem.c @@ -185,12 +185,11 @@ int v3_init_mem_map(struct v3_vm_info * vm) { PrintDebug(VM_NONE, VCORE_NONE, "v3_init_mem_map: %llu base regions will be allocated of %llu base regions in guest\n", (uint64_t)num_base_regions_host_mem, (uint64_t)map->num_base_regions); - map->base_regions = V3_AllocPages(CEIL_DIV(sizeof(struct v3_mem_region) * map->num_base_regions, PAGE_SIZE_4KB)); + map->base_regions = V3_VMalloc(sizeof(struct v3_mem_region) * map->num_base_regions); if (map->base_regions == NULL) { PrintError(vm, VCORE_NONE, "Could not allocate base region array\n"); return -1; } - map->base_regions = V3_VAddr(map->base_regions); memset(map->base_regions, 0, sizeof(struct v3_mem_region) * map->num_base_regions); @@ -297,8 +296,7 @@ void v3_delete_mem_map(struct v3_vm_info * vm) { #endif } - V3_FreePages(V3_PAddr(map->base_regions), - CEIL_DIV(sizeof(struct v3_mem_region) * map->num_base_regions, PAGE_SIZE_4KB)); + V3_VFree(map->base_regions); }