summaryrefslogtreecommitdiff
path: root/mach-defpager/kalloc.c
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2014-11-10 03:32:19 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2014-11-10 03:32:19 +0100
commitcfafc1a905f11da2b856aecea02b8c7e1f95e5dd (patch)
tree3042743b607d790617051c3e27cb97cb437533ee /mach-defpager/kalloc.c
parentb11e2e666ce3e1a8ad167c82bfc1fc9b820f97f3 (diff)
Fix mach-defpager's kalloc values
* mach-defpager/kalloc.c (MINSIZE): Set to sizeof(vm_offset_t) instead of hardcoded 4. (kalloc_init): Set kalloc_max to MINSIZE << (KLIST_MAX-1) instead of hardcoded 16384. (kalloc, kfree): Use the cache for the maximum size too.
Diffstat (limited to 'mach-defpager/kalloc.c')
-rw-r--r--mach-defpager/kalloc.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/mach-defpager/kalloc.c b/mach-defpager/kalloc.c
index 2f8f002e..ef844acc 100644
--- a/mach-defpager/kalloc.c
+++ b/mach-defpager/kalloc.c
@@ -58,7 +58,7 @@ void (*__MALLOC_HOOK_VOLATILE __malloc_initialize_hook) (void) = init_hook;
* next highest power of 2.
*/
vm_size_t kalloc_max; /* max before we use vm_allocate */
-#define MINSIZE 4 /* minimum allocation size */
+#define MINSIZE sizeof(vm_offset_t) /* minimum allocation size */
struct free_list {
pthread_spinlock_t lock;
@@ -99,8 +99,8 @@ void kalloc_init(void)
* 16Kbytes, whichever is less.
*/
- if (vm_page_size > 16*1024)
- kalloc_max = 16*1024;
+ if (vm_page_size > (MINSIZE << (KLIST_MAX-1)))
+ kalloc_max = (MINSIZE << (KLIST_MAX-1));
else
kalloc_max = vm_page_size;
@@ -197,7 +197,7 @@ void *kalloc(vm_size_t size)
/* compute the size of the block that we will actually allocate */
allocsize = size;
- if (size < kalloc_max) {
+ if (size <= kalloc_max) {
allocsize = MINSIZE;
fl = kfree_list;
while (allocsize < size) {
@@ -211,7 +211,7 @@ void *kalloc(vm_size_t size)
* and allocate.
*/
- if (allocsize < kalloc_max) {
+ if (allocsize <= kalloc_max) {
pthread_spin_lock(&fl->lock);
if ((addr = fl->head) != 0) {
fl->head = *(vm_offset_t *)addr;
@@ -241,7 +241,7 @@ kfree( void *data,
struct free_list *fl;
freesize = size;
- if (size < kalloc_max) {
+ if (size <= kalloc_max) {
freesize = MINSIZE;
fl = kfree_list;
while (freesize < size) {
@@ -250,7 +250,7 @@ kfree( void *data,
}
}
- if (freesize < kalloc_max) {
+ if (freesize <= kalloc_max) {
pthread_spin_lock(&fl->lock);
*(vm_offset_t *)data = fl->head;
fl->head = (vm_offset_t) data;