aboutsummaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2015-03-14 16:16:53 +0100
committerAlex Auvolat <alex@adnab.me>2015-03-14 16:16:53 +0100
commit57c5eceb846f3109d017b4e6d4cbd7c507c0d098 (patch)
treed4aa0917310a5ad7925736f9dadc07bcb5734383 /src/kernel
parentf574c22f86d90f735107fda199bb5b4982cd9621 (diff)
downloadkogata-57c5eceb846f3109d017b4e6d4cbd7c507c0d098.tar.gz
kogata-57c5eceb846f3109d017b4e6d4cbd7c507c0d098.zip
Begin implement escape sequence handling in terminal.
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/config.h1
-rw-r--r--src/kernel/core/freemem.c2
-rw-r--r--src/kernel/core/kmalloc.c10
-rw-r--r--src/kernel/core/thread.c2
-rw-r--r--src/kernel/user/process.c2
5 files changed, 15 insertions, 2 deletions
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 <freemem.h>
#include <thread.h>
#include <debug.h>
+#include <frame.h>
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();
}
}