summaryrefslogtreecommitdiff
path: root/Kernel/Heap
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-05-15 10:06:41 +0200
committerAndreas Kling <kling@serenityos.org>2021-05-15 16:30:14 +0200
commitf89e8fb71a4893911ee5125f34bd5bbb99327d33 (patch)
treec22e44ba3db1066277af7bb4dbc3f49d40d903a0 /Kernel/Heap
parent4ab9d8736b9cb4199caed31e53ccdf30c202bee5 (diff)
downloadserenity-f89e8fb71a4893911ee5125f34bd5bbb99327d33.zip
AK+LibC: Implement malloc_good_size() and use it for Vector/HashTable
This implements the macOS API malloc_good_size() which returns the true allocation size for a given requested allocation size. This allows us to make use of all the available memory in a malloc chunk. For example, for a malloc request of 35 bytes our malloc would internally use a chunk of size 64, however the remaining 29 bytes would be unused. Knowing the true allocation size allows us to request more usable memory that would otherwise be wasted and make that available for Vector, HashTable and potentially other callers in the future.
Diffstat (limited to 'Kernel/Heap')
-rw-r--r--Kernel/Heap/kmalloc.cpp5
-rw-r--r--Kernel/Heap/kmalloc.h2
2 files changed, 7 insertions, 0 deletions
diff --git a/Kernel/Heap/kmalloc.cpp b/Kernel/Heap/kmalloc.cpp
index 1e96825f87..c7759f4ad7 100644
--- a/Kernel/Heap/kmalloc.cpp
+++ b/Kernel/Heap/kmalloc.cpp
@@ -277,6 +277,11 @@ void* krealloc(void* ptr, size_t new_size)
return g_kmalloc_global->m_heap.reallocate(ptr, new_size);
}
+size_t kmalloc_good_size(size_t size)
+{
+ return size;
+}
+
void* operator new(size_t size) noexcept
{
return kmalloc(size);
diff --git a/Kernel/Heap/kmalloc.h b/Kernel/Heap/kmalloc.h
index 6fdc974c32..624758ea53 100644
--- a/Kernel/Heap/kmalloc.h
+++ b/Kernel/Heap/kmalloc.h
@@ -66,4 +66,6 @@ inline void kfree_aligned(void* ptr)
kfree((u8*)ptr - ((const ptrdiff_t*)ptr)[-1]);
}
+size_t kmalloc_good_size(size_t);
+
void kmalloc_enable_expand();