From 57c5eceb846f3109d017b4e6d4cbd7c507c0d098 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sat, 14 Mar 2015 16:16:53 +0100 Subject: Begin implement escape sequence handling in terminal. --- src/kernel/config.h | 1 + src/kernel/core/freemem.c | 2 ++ src/kernel/core/kmalloc.c | 10 +++++++++- src/kernel/core/thread.c | 2 +- src/kernel/user/process.c | 2 ++ 5 files changed, 15 insertions(+), 2 deletions(-) (limited to 'src/kernel') diff --git a/src/kernel/config.h b/src/kernel/config.h index 4d5d01f..1792d52 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -31,5 +31,6 @@ #define SPAM_WAIT_RESUME_ON 0 // trace wait_on and resume_on calls #define SPAM_FS_REF 0 // show reference inc/dec on VFS items #define SPAM_BEGIN_EXIT 1 // trace thread creation/deletion && process begin/exit +#define SPAM_OOM_REASON 1 // print a message saying where we are when calling free_some_memory /* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/kernel/core/freemem.c b/src/kernel/core/freemem.c index 153ec7a..18cc740 100644 --- a/src/kernel/core/freemem.c +++ b/src/kernel/core/freemem.c @@ -1,8 +1,10 @@ #include #include #include +#include void free_some_memory() { + dbg_print_frame_stats(); dbg_printf("Currently out of memory ; free_some_memory not implemented. Waiting.\n"); usleep(1000000); // Hope someone will do something... } diff --git a/src/kernel/core/kmalloc.c b/src/kernel/core/kmalloc.c index 53ac83c..95347b3 100644 --- a/src/kernel/core/kmalloc.c +++ b/src/kernel/core/kmalloc.c @@ -10,7 +10,14 @@ void* page_alloc_fun_for_kmalloc(size_t bytes) { void* addr = region_alloc(bytes, "Core kernel heap"); - if (addr == 0) return 0; + if (addr == 0) { + if (SPAM_OOM_REASON) { + dbg_printf("Could not allocate region for kmalloc.\n"); + dbg_print_frame_stats(); + dbg_print_region_info(); + } + return 0; + } // Map physical memory for (void* i = addr; i < addr + bytes; i += PAGE_SIZE) { @@ -74,6 +81,7 @@ void* malloc(size_t sz) { int tries = 0; while ((res = malloc0(sz)) == 0 && (tries++) < 3) { + if (SPAM_OOM_REASON) dbg_printf("OOM in kmalloc\n"); free_some_memory(); } diff --git a/src/kernel/core/thread.c b/src/kernel/core/thread.c index fab4eef..f2ddf9b 100644 --- a/src/kernel/core/thread.c +++ b/src/kernel/core/thread.c @@ -176,7 +176,7 @@ thread_t *new_thread(entry_t entry, void* data) { uint32_t f; int tries = 0; while ((f = frame_alloc(1)) == 0 && (tries++) < 3) { - dbg_printf("thread stack alloc OOM\n"); + if (SPAM_OOM_REASON) dbg_printf("OOM when allocating thread stack\n"); free_some_memory(); } if (f == 0) { diff --git a/src/kernel/user/process.c b/src/kernel/user/process.c index d96b486..7b0c351 100644 --- a/src/kernel/user/process.c +++ b/src/kernel/user/process.c @@ -794,11 +794,13 @@ void proc_usermem_pf(void* p, registers_t *regs, void* addr) { do { frame = pager_get_frame(r->pager, addr - r->addr + r->offset); if (frame == 0) { + if (SPAM_OOM_REASON) dbg_printf("Pager OOM\n"); free_some_memory(); } } while (frame == 0); while(!pd_map_page(addr, frame, (r->mode & MM_WRITE) != 0)) { + if (SPAM_OOM_REASON) dbg_printf("pd_map_page OOM\n"); free_some_memory(); } } -- cgit v1.2.3