X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=linux_module%2Fmm.c;h=1b70b74639ef2d267176b130b2312f6aaa2878e3;hb=e42b257e5364f8ddba2c86668631013859cb2e46;hp=5e98f799a6a53dc0d4fb426e7b19b76ed126edba;hpb=82071a7f5f0b18fbf1a4adc2a37fed1624572a79;p=palacios.git diff --git a/linux_module/mm.c b/linux_module/mm.c index 5e98f79..1b70b74 100644 --- a/linux_module/mm.c +++ b/linux_module/mm.c @@ -76,7 +76,19 @@ void free_palacios_pgs(uintptr_t pg_addr, u64 num_pages) { int node_id = numa_addr_to_node(pg_addr); //DEBUG("Freeing Memory page %p\n", (void *)pg_addr); - buddy_free(memzones[node_id], pg_addr, get_order(num_pages * PAGE_SIZE) + PAGE_SHIFT); + if (buddy_free(memzones[node_id], pg_addr, get_order(num_pages * PAGE_SIZE) + PAGE_SHIFT)) { + // it is possible that the allocation was actually on a different zone, + // so, just to be sure, we'll try to dellocate on each + for (node_id=0;node_idtype,r->node,r->base_addr,r->num_pages); // fixup request regardless of its type - if (r->num_pages*4096 < V3_CONFIG_MEM_BLOCK_SIZE) { + if (r->num_pages*4096 < get_palacios_mem_block_size()) { WARNING("Allocating a memory pool smaller than the Palacios block size - may not be useful\n"); } @@ -130,7 +160,7 @@ int add_palacios_memory(struct v3_mem_region *r) { ERROR("Unable to satisfy allocation request\n"); palacios_free(keep); return -1; - } + } r->base_addr = page_to_pfn(pgs) << PAGE_SHIFT; } @@ -153,7 +183,7 @@ int add_palacios_memory(struct v3_mem_region *r) { if (buddy_add_pool(memzones[node_id], r->base_addr, pool_order, keep)) { ERROR("ALERT ALERT ALERT Unable to add pool to buddy allocator...\n"); if (r->type==REQUESTED || r->type==REQUESTED32) { - free_pages((uintptr_t)__va(r->base_addr), get_order(r->num_pages)); + free_pages((uintptr_t)__va(r->base_addr), get_order(r->num_pages*PAGE_SIZE)); } palacios_free(keep); return -1; @@ -164,27 +194,47 @@ int add_palacios_memory(struct v3_mem_region *r) { -int palacios_remove_memory(uintptr_t base_addr) { - int node_id = numa_addr_to_node(base_addr); +int remove_palacios_memory(struct v3_mem_region *req) { + int node_id = numa_addr_to_node(req->base_addr); struct v3_mem_region *r; - if (buddy_remove_pool(memzones[node_id], base_addr, 0, (void**)(&r))) { //unforced remove - ERROR("Cannot remove memory at base address 0x%p because it is in use\n", (void*)base_addr); + if (buddy_remove_pool(memzones[node_id], req->base_addr, 0, (void**)(&r))) { //unforced remove + ERROR("Cannot remove memory at base address 0x%p\n", (void*)(req->base_addr)); return -1; } - if (r->type==REQUESTED || r->type==REQUESTED32) { - free_pages((uintptr_t)__va(r->base_addr), get_order(r->num_pages)); - } else { - // user space resposible for onlining + if (r) { + if (r->type==REQUESTED || r->type==REQUESTED32) { + free_pages((uintptr_t)__va(r->base_addr), get_order(r->num_pages*PAGE_SIZE)); + } else { + // user space responsible for onlining + } + palacios_free(r); } - - palacios_free(r); return 0; } +static int handle_free(void *meta) +{ + struct v3_mem_region *r = (struct v3_mem_region *)meta; + + if (r) { + if (r->type==REQUESTED || r->type==REQUESTED32) { + //INFO("Freeing %llu pages at %p\n",r->num_pages,(void*)(r->base_addr)); + free_pages((uintptr_t)__va(r->base_addr), get_order(r->num_pages*PAGE_SIZE)); + } else { + // user space responsible for onlining + } + palacios_free(r); + } + + return 0; +} + + + int palacios_deinit_mm( void ) { @@ -194,7 +244,8 @@ int palacios_deinit_mm( void ) { for (i = 0; i < numa_num_nodes(); i++) { if (memzones[i]) { - buddy_deinit(memzones[i]); + INFO("Deiniting memory zone %d\n",i); + buddy_deinit(memzones[i],handle_free); } // note that the memory is not onlined here - offlining and onlining @@ -202,6 +253,7 @@ int palacios_deinit_mm( void ) { if (seed_addrs[i]) { // free the seed regions + INFO("Freeing seed addrs %d\n",i); free_pages((uintptr_t)__va(seed_addrs[i]), MAX_ORDER - 1); } } @@ -248,13 +300,15 @@ int palacios_init_mm( void ) { { struct page * pgs; - + int actual_node; + // attempt to first allocate below 4 GB for compatibility with // 32 bit shadow paging pgs = alloc_pages_node(node_id, GFP_DMA32, MAX_ORDER - 1); + if (!pgs) { - INFO("Could not allocate initial memory block for node %d beloew 4GB\n", node_id); + INFO("Could not allocate initial memory block for node %d below 4GB\n", node_id); pgs = alloc_pages_node(node_id, GFP_KERNEL, MAX_ORDER - 1); @@ -266,12 +320,25 @@ int palacios_init_mm( void ) { palacios_deinit_mm(); return -1; } + } else { + actual_node=numa_addr_to_node((uintptr_t)(page_to_pfn(pgs) << PAGE_SHIFT)); + if (actual_node != node_id) { + WARNING("Initial 64 bit allocation attempt for node %d resulted in allocation on node %d\n",node_id,actual_node); + } } + + } else { + actual_node=numa_addr_to_node((uintptr_t)(page_to_pfn(pgs) << PAGE_SHIFT)); + if (actual_node != node_id) { + WARNING("Initial 32bit-limited allocation attempt for node %d resulted in allocation on node %d\n",node_id,actual_node); + } } seed_addrs[node_id] = page_to_pfn(pgs) << PAGE_SHIFT; } + // Initialization is done using the compile-time memory block size since + // at this point, we do not yet know what the run-time size is zone = buddy_init(get_order(V3_CONFIG_MEM_BLOCK_SIZE) + PAGE_SHIFT, PAGE_SHIFT, node_id); if (zone == NULL) {