summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_malloc.c
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2002-11-01 18:58:12 +0000
committerphk <phk@FreeBSD.org>2002-11-01 18:58:12 +0000
commit27173bd0dd93081098b8676a7b2156fd227c52d3 (patch)
treeca1df1a49f6cbc6f4cec369bd425e89deaf84e2a /sys/kern/kern_malloc.c
parent3ce3aae31e0179d6c2fec1801690b152f9187cf6 (diff)
downloadFreeBSD-src-27173bd0dd93081098b8676a7b2156fd227c52d3.zip
FreeBSD-src-27173bd0dd93081098b8676a7b2156fd227c52d3.tar.gz
Introduce malloc_last_fail() which returns the number of seconds since
malloc(9) failed last time. This is intended to help code adjust memory usage to the current circumstances. A typical use could be: if (malloc_last_fail() < 60) reduce_cache_by_one();
Diffstat (limited to 'sys/kern/kern_malloc.c')
-rw-r--r--sys/kern/kern_malloc.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index 3d6307a..577b5da 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -46,6 +46,7 @@
#include <sys/vmmeter.h>
#include <sys/proc.h>
#include <sys/sysctl.h>
+#include <sys/time.h>
#include <vm/vm.h>
#include <vm/pmap.h>
@@ -134,6 +135,16 @@ static int sysctl_kern_mprof(SYSCTL_HANDLER_ARGS);
static int sysctl_kern_malloc(SYSCTL_HANDLER_ARGS);
+/* time_uptime of last malloc(9) failure */
+static time_t t_malloc_fail;
+
+int
+malloc_last_fail(void)
+{
+
+ return (time_uptime - t_malloc_fail);
+}
+
/*
* malloc:
*
@@ -191,6 +202,11 @@ out:
ksp->ks_maxused = ksp->ks_memuse;
mtx_unlock(&ksp->ks_mtx);
+ if (!(flags & M_NOWAIT))
+ KASSERT(va != NULL, ("malloc(M_WAITOK) returned NULL"));
+ if (va == NULL) {
+ t_malloc_fail = time_uptime;
+ }
return ((void *) va);
}
OpenPOWER on IntegriCloud