summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2011-04-20 23:35:42 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2011-04-20 23:40:16 +0200
commit67d4e8403fe12592f99cf6fc51e4f33684899d6b (patch)
treec4f8ed13d12ab04e067d396dd3c39b6afeadeb1a
parenta44f51203c43bb4306a225506075740cdacaccfa (diff)
Warn once when part of the kernel is lacking memory
* kern/printf.h (printf_once): New macro. * ipc/mach_port.c (mach_port_names, mach_port_get_set_status): Warn when returning KERN_RESOURCE_SHORTAGE. * vm/vm_kern.c: Include printf.h. (kmem_alloc, kmem_realloc, kmem_alloc_wired, kmem_alloc_aligned, kmem_alloc_pageable): Warn when failing. * vm/vm_resident.c (vm_page_grab_contiguous_pages): Warn when returning KERN_RESOURCE_SHORTAGE.
-rw-r--r--ipc/mach_port.c9
-rw-r--r--kern/printf.h9
-rw-r--r--vm/vm_kern.c9
-rw-r--r--vm/vm_resident.c2
4 files changed, 26 insertions, 3 deletions
diff --git a/ipc/mach_port.c b/ipc/mach_port.c
index 122d5d9..904fd14 100644
--- a/ipc/mach_port.c
+++ b/ipc/mach_port.c
@@ -205,11 +205,14 @@ mach_port_names(
size = size_needed;
kr = vm_allocate(ipc_kernel_map, &addr1, size, TRUE);
- if (kr != KERN_SUCCESS)
+ if (kr != KERN_SUCCESS) {
+ printf_once("no more room in ipc_kernel_map\n");
return KERN_RESOURCE_SHORTAGE;
+ }
kr = vm_allocate(ipc_kernel_map, &addr2, size, TRUE);
if (kr != KERN_SUCCESS) {
+ printf_once("no more room in ipc_kernel_map\n");
kmem_free(ipc_kernel_map, addr1, size);
return KERN_RESOURCE_SHORTAGE;
}
@@ -982,8 +985,10 @@ mach_port_get_set_status(
ipc_pset_t pset;
kr = vm_allocate(ipc_kernel_map, &addr, size, TRUE);
- if (kr != KERN_SUCCESS)
+ if (kr != KERN_SUCCESS) {
+ printf_once("no more room in ipc_kernel_map\n");
return KERN_RESOURCE_SHORTAGE;
+ }
/* can't fault while we hold locks */
diff --git a/kern/printf.h b/kern/printf.h
index 1383198..c5effe5 100644
--- a/kern/printf.h
+++ b/kern/printf.h
@@ -43,6 +43,15 @@ extern int sprintf (char *buf, const char *fmt, ...);
extern int printf (const char *fmt, ...);
+#define printf_once(fmt, ...) \
+ MACRO_BEGIN \
+ static int __once = 0; \
+ if (!__once) { \
+ printf(fmt, ##__VA_ARGS__); \
+ __once = 1; \
+ } \
+ MACRO_END
+
extern int indent;
extern void iprintf (const char *fmt, ...);
diff --git a/vm/vm_kern.c b/vm/vm_kern.c
index dc7f7e4..cfa33ff 100644
--- a/vm/vm_kern.c
+++ b/vm/vm_kern.c
@@ -43,6 +43,7 @@
#include <kern/debug.h>
#include <kern/lock.h>
#include <kern/thread.h>
+#include <kern/printf.h>
#include <vm/pmap.h>
#include <vm/vm_fault.h>
#include <vm/vm_kern.h>
@@ -387,6 +388,7 @@ kmem_alloc(map, addrp, size)
kr = vm_map_find_entry(map, &addr, size, (vm_offset_t) 0,
VM_OBJECT_NULL, &entry);
if (kr != KERN_SUCCESS) {
+ printf_once("no more room for kmem_alloc in %p\n", map);
vm_map_unlock(map);
vm_object_deallocate(object);
return kr;
@@ -453,6 +455,7 @@ kern_return_t kmem_realloc(map, oldaddr, oldsize, newaddrp, newsize)
VM_OBJECT_NULL, &newentry);
if (kr != KERN_SUCCESS) {
vm_map_unlock(map);
+ printf_once("no more room for kmem_realloc in %p\n", map);
return kr;
}
@@ -537,6 +540,7 @@ kmem_alloc_wired(map, addrp, size)
kr = vm_map_find_entry(map, &addr, size, (vm_offset_t) 0,
kernel_object, &entry);
if (kr != KERN_SUCCESS) {
+ printf_once("no more room for kmem_alloc_wired in %p\n", map);
vm_map_unlock(map);
return kr;
}
@@ -611,6 +615,7 @@ kmem_alloc_aligned(map, addrp, size)
kr = vm_map_find_entry(map, &addr, size, size - 1,
kernel_object, &entry);
if (kr != KERN_SUCCESS) {
+ printf_once("no more rooom for kmem_alloc_aligned in %p\n", map);
vm_map_unlock(map);
return kr;
}
@@ -672,8 +677,10 @@ kmem_alloc_pageable(map, addrp, size)
(vm_offset_t) 0, TRUE,
VM_OBJECT_NULL, (vm_offset_t) 0, FALSE,
VM_PROT_DEFAULT, VM_PROT_ALL, VM_INHERIT_DEFAULT);
- if (kr != KERN_SUCCESS)
+ if (kr != KERN_SUCCESS) {
+ printf_once("no more room for kmem_alloc_pageable in %p\n", map);
return kr;
+ }
*addrp = addr;
return KERN_SUCCESS;
diff --git a/vm/vm_resident.c b/vm/vm_resident.c
index b23e0f3..a633498 100644
--- a/vm/vm_resident.c
+++ b/vm/vm_resident.c
@@ -976,6 +976,7 @@ vm_page_grab_contiguous_pages(
if ((vm_page_free_count < vm_page_free_reserved)
|| (vm_page_external_count >= vm_page_external_limit)) {
+ printf_once("no more room for vm_page_grab_contiguous_pages");
simple_unlock(&vm_page_queue_free_lock);
return KERN_RESOURCE_SHORTAGE;
}
@@ -1064,6 +1065,7 @@ count_ones:
*/
simple_unlock(&vm_page_queue_free_lock);
+ printf_once("no contiguous room for vm_page_grab_contiguous_pages");
ret = KERN_RESOURCE_SHORTAGE;
goto out;