From 7a42f7ffe10fbe958c0754572319ab87538aed03 Mon Sep 17 00:00:00 2001 From: Greg Haerr Date: Wed, 8 Jan 2025 19:11:45 -0700 Subject: [PATCH] [libc] Don't call sysctl every malloc, set DEBUG=1 default in fmalloc --- libc/malloc/dmalloc.c | 2 +- libc/malloc/fmalloc.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libc/malloc/dmalloc.c b/libc/malloc/dmalloc.c index 54734f8a9..3439728c6 100644 --- a/libc/malloc/dmalloc.c +++ b/libc/malloc/dmalloc.c @@ -85,7 +85,7 @@ _dmalloc(size_t nbytes) unsigned int nw, temp; #if DEBUG == 1 - sysctl(CTL_GET, "malloc.debug", &debug_level); + if (debug_level == 1) sysctl(CTL_GET, "malloc.debug", &debug_level); #endif if (allocs[0].ptr == 0) { /*first time*/ allocs[0].ptr = setbusy(&allocs[1]); diff --git a/libc/malloc/fmalloc.c b/libc/malloc/fmalloc.c index 3e9b125ea..ac93e8e3d 100644 --- a/libc/malloc/fmalloc.c +++ b/libc/malloc/fmalloc.c @@ -17,7 +17,7 @@ #include #include #include -#define DEBUG 0 /* =1 use sysctl, =2 debug output, =3 show heap */ +#define DEBUG 1 /* =1 use sysctl, =2 debug output, =3 show heap */ /* C storage allocator * circular first-fit strategy @@ -110,7 +110,7 @@ _fmalloc(size_t nbytes) unsigned int nw, temp; #if DEBUG == 1 - sysctl(CTL_GET, "malloc.debug", &debug_level); + if (debug_level == 1) sysctl(CTL_GET, "malloc.debug", &debug_level); #endif debug("(%d)malloc(%5u) ", getpid(), nbytes); @@ -137,7 +137,7 @@ _fmalloc(size_t nbytes) /* combine free areas at heap start before allocating from free area past allocp */ //allocp = (NPTR)allocs; /* NOTE: start at last allocation for speed */ for(p=allocp; ; ) { - //f = nb = n = 0; + //int f = 0, nb = 0, n = 0; for(temp=0; ; ) { if(!testbusy(next(p))) { while(!testbusy(next(q = next(p)))) {