aboutsummaryrefslogtreecommitdiff
path: root/core/malloc.c
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2015-05-12 18:12:20 +0800
committerStewart Smith <stewart@linux.vnet.ibm.com>2015-05-13 14:01:35 +1000
commitf96dd8b3d82543ea733a7ab0e854b8331875d524 (patch)
tree41b87ac71ac02d24b0a37dc556974522e97c3831 /core/malloc.c
parent8f527a0290068f1b2224fcfd7d88d91eab6ddd6f (diff)
downloadskiboot-f96dd8b3d82543ea733a7ab0e854b8331875d524.zip
skiboot-f96dd8b3d82543ea733a7ab0e854b8331875d524.tar.gz
skiboot-f96dd8b3d82543ea733a7ab0e854b8331875d524.tar.bz2
core: Move free-list locking to a separate per-region lock
Currently, we have a single lock for the entire mem_region system; this protects both the global region list, and the allocations from each region. This means we can't allocate memory while traversing the global region list, as any malloc/realloc/free will try to acquire the mem_region lock again. This change separates the locking into different functions. We keep the mem_region_lock to protect the regions list, and introduce a per-region lock to protect allocations from the regions' free_lists. Then we remove the open-coded invocations of mem_alloc, where we'd avoided malloc() due to the above locking issue. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'core/malloc.c')
-rw-r--r--core/malloc.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/core/malloc.c b/core/malloc.c
index 9e715f6..669cc59 100644
--- a/core/malloc.c
+++ b/core/malloc.c
@@ -25,9 +25,9 @@ void *__memalign(size_t blocksize, size_t bytes, const char *location)
{
void *p;
- lock(&mem_region_lock);
+ lock(&skiboot_heap.free_list_lock);
p = mem_alloc(&skiboot_heap, bytes, blocksize, location);
- unlock(&mem_region_lock);
+ unlock(&skiboot_heap.free_list_lock);
return p;
}
@@ -39,9 +39,9 @@ void *__malloc(size_t bytes, const char *location)
void __free(void *p, const char *location)
{
- lock(&mem_region_lock);
+ lock(&skiboot_heap.free_list_lock);
mem_free(&skiboot_heap, p, location);
- unlock(&mem_region_lock);
+ unlock(&skiboot_heap.free_list_lock);
}
void *__realloc(void *ptr, size_t size, const char *location)
@@ -56,7 +56,7 @@ void *__realloc(void *ptr, size_t size, const char *location)
if (!ptr)
return __malloc(size, location);
- lock(&mem_region_lock);
+ lock(&skiboot_heap.free_list_lock);
if (mem_resize(&skiboot_heap, ptr, size, location)) {
newptr = ptr;
} else {
@@ -70,7 +70,7 @@ void *__realloc(void *ptr, size_t size, const char *location)
mem_free(&skiboot_heap, ptr, location);
}
}
- unlock(&mem_region_lock);
+ unlock(&skiboot_heap.free_list_lock);
return newptr;
}