From: Peter Dinda Date: Fri, 2 Aug 2013 00:46:08 +0000 (-0500) Subject: Buddy allocator metadata for pools X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=84c84a909e8c3374e2cd7768ef4240ca9d73222f;hp=9b50e169b294dba9c1e36ad15d5ff85898c0f21e;p=palacios.git Buddy allocator metadata for pools --- diff --git a/linux_module/buddy.c b/linux_module/buddy.c index 01cf392..548c7ff 100644 --- a/linux_module/buddy.c +++ b/linux_module/buddy.c @@ -139,7 +139,8 @@ insert_mempool(struct buddy_memzone * zone, int buddy_add_pool(struct buddy_memzone * zone, unsigned long base_addr, - unsigned long pool_order) { + unsigned long pool_order, + void *user_metadata) { struct buddy_mempool * mp = NULL; unsigned long flags = 0; int ret = 0; @@ -164,6 +165,8 @@ int buddy_add_pool(struct buddy_memzone * zone, mp->zone = zone; mp->num_free_blocks = 0; + mp->user_metadata = user_metadata; + /* Allocate a bitmap with 1 bit per minimum-sized block */ mp->num_blocks = (1UL << pool_order) / (1UL << zone->min_order); @@ -200,7 +203,9 @@ int buddy_add_pool(struct buddy_memzone * zone, */ static int __buddy_remove_mempool(struct buddy_memzone * zone, unsigned long base_addr, - unsigned char force) { + unsigned char force, + void **user_metadata) +{ struct buddy_mempool * pool = NULL; struct block * block = NULL; @@ -217,6 +222,8 @@ static int __buddy_remove_mempool(struct buddy_memzone * zone, return -1; } + *user_metadata = pool->user_metadata; + block = (struct block *)__va(pool->base_addr); list_del(&(block->link)); @@ -231,13 +238,15 @@ static int __buddy_remove_mempool(struct buddy_memzone * zone, } int buddy_remove_pool(struct buddy_memzone * zone, - unsigned long base_addr, - unsigned char force) { + unsigned long base_addr, + unsigned char force, + void **user_metadata) +{ unsigned long flags = 0; int ret = 0; palacios_spinlock_lock_irqsave(&(zone->lock), flags); - ret = __buddy_remove_mempool(zone, base_addr, force); + ret = __buddy_remove_mempool(zone, base_addr, force, user_metadata); palacios_spinlock_unlock_irqrestore(&(zone->lock), flags); return ret; diff --git a/linux_module/buddy.h b/linux_module/buddy.h index 54c24a7..34742e1 100644 --- a/linux_module/buddy.h +++ b/linux_module/buddy.h @@ -48,6 +48,8 @@ struct buddy_mempool { */ unsigned long num_free_blocks; + + void *user_metadata; // whatever the user wants struct rb_node tree_node; }; @@ -77,14 +79,16 @@ buddy_deinit(struct buddy_memzone * zone); extern int buddy_add_pool(struct buddy_memzone * zone, unsigned long base_addr, - unsigned long pool_order); + unsigned long pool_order, + void *user_metadata); /* Remove pool based at given physical address */ extern int buddy_remove_pool(struct buddy_memzone * zone, unsigned long base_addr, - unsigned char force); + unsigned char force, + void **user_metadata); /* Allocate pages, returns physical address */