From b062823d817b8d2bdffe10cb3d390230dffdff18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sat, 29 Sep 2007 15:46:40 +0000 Subject: [PATCH] * register_low_memory_handler() was called too early by several kernel components - now, we divide the initialization of that service into two parts which allows this (before, most handlers were gone after boot). * Added debugger command that dumps the low memory handlers. * The slab allocator now registers its low memory handler with a higher priority, so that it'll run before the potentially heavier ones. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22374 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/vm_low_memory.h | 3 +- src/system/kernel/slab/Slab.cpp | 2 +- src/system/kernel/vm/vm.cpp | 4 +- src/system/kernel/vm/vm_low_memory.cpp | 56 ++++++++++++++++++++------ 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/headers/private/kernel/vm_low_memory.h b/headers/private/kernel/vm_low_memory.h index 331e0f7df6..936647bb04 100644 --- a/headers/private/kernel/vm_low_memory.h +++ b/headers/private/kernel/vm_low_memory.h @@ -1,5 +1,5 @@ /* - * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2005-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _KERNEL_VM_LOW_MEMORY_H @@ -24,6 +24,7 @@ extern "C" { #endif status_t vm_low_memory_init(void); +status_t vm_low_memory_init_post_thread(void); int32 vm_low_memory_state(void); void vm_low_memory(size_t requirements); diff --git a/src/system/kernel/slab/Slab.cpp b/src/system/kernel/slab/Slab.cpp index 220473df4e..0af86a1766 100644 --- a/src/system/kernel/slab/Slab.cpp +++ b/src/system/kernel/slab/Slab.cpp @@ -449,7 +449,7 @@ object_cache_init(object_cache *cache, const char *name, size_t objectSize, cache->free_pages = area_free_pages; } - register_low_memory_handler(object_cache_low_memory, cache, 0); + register_low_memory_handler(object_cache_low_memory, cache, 5); BenaphoreLocker _(sObjectCacheListLock); sObjectCaches.Add(cache); diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index 7b2488a7ca..fdfa4814b4 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -3405,6 +3405,8 @@ vm_init(kernel_args *args) TRACE(("heap at 0x%lx\n", heapBase)); heap_init(heapBase, heapSize); + vm_low_memory_init(); + size_t slabInitialSize = 2 * B_PAGE_SIZE; addr_t slabInitialBase = vm_allocate_early(args, slabInitialSize, slabInitialSize, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); @@ -3525,7 +3527,7 @@ vm_init_post_thread(kernel_args *args) { vm_page_init_post_thread(args); vm_daemon_init(); - vm_low_memory_init(); + vm_low_memory_init_post_thread(); return heap_init_post_thread(args); } diff --git a/src/system/kernel/vm/vm_low_memory.cpp b/src/system/kernel/vm/vm_low_memory.cpp index a0d1d4b1a6..addd16c57a 100644 --- a/src/system/kernel/vm/vm_low_memory.cpp +++ b/src/system/kernel/vm/vm_low_memory.cpp @@ -4,18 +4,20 @@ */ -#include - #include -#include -#include -#include -#include #include #include #include +#include + +#include +#include +#include +#include +#include + //#define TRACE_LOW_MEMORY #ifdef TRACE_LOW_MEMORY @@ -110,6 +112,30 @@ low_memory(void *) } +static int +dump_handlers(int argc, char **argv) +{ + HandlerList::Iterator iterator = sLowMemoryHandlers.GetIterator(); + kprintf("function data prio function-name\n"); + + while (iterator.HasNext()) { + low_memory_handler *handler = iterator.Next(); + + const char* symbol = NULL; + elf_debug_lookup_symbol_address((addr_t)handler->function, NULL, + &symbol, NULL, NULL); + + kprintf("%p %p %3ld %s\n", handler->function, handler->data, + handler->priority, symbol); + } + + return 0; +} + + +// #pragma mark - private kernel API + + void vm_low_memory(size_t requirements) { @@ -129,8 +155,17 @@ vm_low_memory_state(void) status_t vm_low_memory_init(void) { - thread_id thread; + new(&sLowMemoryHandlers) HandlerList; + // static initializers do not work in the kernel, + // so we have to do it here, manually + return B_OK; +} + + +status_t +vm_low_memory_init_post_thread(void) +{ if (mutex_init(&sLowMemoryMutex, "low memory") < B_OK) return B_ERROR; @@ -138,14 +173,11 @@ vm_low_memory_init(void) if (sLowMemoryWaitSem < B_OK) return sLowMemoryWaitSem; - new(&sLowMemoryHandlers) HandlerList; - // static initializers do not work in the kernel, - // so we have to do it here, manually - - thread = spawn_kernel_thread(&low_memory, "low memory handler", + thread_id thread = spawn_kernel_thread(&low_memory, "low memory handler", B_LOW_PRIORITY, NULL); send_signal_etc(thread, SIGCONT, B_DO_NOT_RESCHEDULE); + add_debugger_command("low_memory", &dump_handlers, "Dump list of low memory handlers"); return B_OK; }