aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/core')
-rw-r--r--src/kernel/core/freemem.c2
-rw-r--r--src/kernel/core/kmalloc.c10
-rw-r--r--src/kernel/core/thread.c2
3 files changed, 12 insertions, 2 deletions
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) {