kern_malloc.c (106305) | kern_malloc.c (109623) |
---|---|
1/* 2 * Copyright (c) 1987, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)kern_malloc.c 8.3 (Berkeley) 1/4/94 | 1/* 2 * Copyright (c) 1987, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)kern_malloc.c 8.3 (Berkeley) 1/4/94 |
34 * $FreeBSD: head/sys/kern/kern_malloc.c 106305 2002-11-01 18:58:12Z phk $ | 34 * $FreeBSD: head/sys/kern/kern_malloc.c 109623 2003-01-21 08:56:16Z alfred $ |
35 */ 36 37#include "opt_vm.h" 38 39#include <sys/param.h> 40#include <sys/systm.h> 41#include <sys/kernel.h> 42#include <sys/lock.h> --- 122 unchanged lines hidden (view full) --- 165 register struct malloc_type *ksp = type; 166 167#if 0 168 if (size == 0) 169 Debugger("zero size malloc"); 170#endif 171 if (!(flags & M_NOWAIT)) 172 KASSERT(curthread->td_intr_nesting_level == 0, | 35 */ 36 37#include "opt_vm.h" 38 39#include <sys/param.h> 40#include <sys/systm.h> 41#include <sys/kernel.h> 42#include <sys/lock.h> --- 122 unchanged lines hidden (view full) --- 165 register struct malloc_type *ksp = type; 166 167#if 0 168 if (size == 0) 169 Debugger("zero size malloc"); 170#endif 171 if (!(flags & M_NOWAIT)) 172 KASSERT(curthread->td_intr_nesting_level == 0, |
173 ("malloc(M_WAITOK) in interrupt context")); | 173 ("malloc() without M_NOWAIT in interrupt context")); |
174 if (size <= KMEM_ZMAX) { 175 if (size & KMEM_ZMASK) 176 size = (size & ~KMEM_ZMASK) + KMEM_ZBASE; 177 indx = kmemsize[size >> KMEM_ZSHIFT]; 178 zone = kmemzones[indx].kz_zone; 179#ifdef MALLOC_PROFILE 180 krequests[size >> KMEM_ZSHIFT]++; 181#endif --- 16 unchanged lines hidden (view full) --- 198 ksp->ks_inuse++; 199out: 200 ksp->ks_calls++; 201 if (ksp->ks_memuse > ksp->ks_maxused) 202 ksp->ks_maxused = ksp->ks_memuse; 203 204 mtx_unlock(&ksp->ks_mtx); 205 if (!(flags & M_NOWAIT)) | 174 if (size <= KMEM_ZMAX) { 175 if (size & KMEM_ZMASK) 176 size = (size & ~KMEM_ZMASK) + KMEM_ZBASE; 177 indx = kmemsize[size >> KMEM_ZSHIFT]; 178 zone = kmemzones[indx].kz_zone; 179#ifdef MALLOC_PROFILE 180 krequests[size >> KMEM_ZSHIFT]++; 181#endif --- 16 unchanged lines hidden (view full) --- 198 ksp->ks_inuse++; 199out: 200 ksp->ks_calls++; 201 if (ksp->ks_memuse > ksp->ks_maxused) 202 ksp->ks_maxused = ksp->ks_memuse; 203 204 mtx_unlock(&ksp->ks_mtx); 205 if (!(flags & M_NOWAIT)) |
206 KASSERT(va != NULL, ("malloc(M_WAITOK) returned NULL")); | 206 KASSERT(va != NULL, ("malloc() without M_NOWAIT returned NULL")); |
207 if (va == NULL) { 208 t_malloc_fail = time_uptime; 209 } 210 return ((void *) va); 211} 212 213/* 214 * free: --- 273 unchanged lines hidden (view full) --- 488 cnt = 0; 489 490 mtx_lock(&malloc_mtx); 491 for (type = kmemstatistics; type != NULL; type = type->ks_next) 492 cnt++; 493 494 mtx_unlock(&malloc_mtx); 495 bufsize = linesize * (cnt + 1); | 207 if (va == NULL) { 208 t_malloc_fail = time_uptime; 209 } 210 return ((void *) va); 211} 212 213/* 214 * free: --- 273 unchanged lines hidden (view full) --- 488 cnt = 0; 489 490 mtx_lock(&malloc_mtx); 491 for (type = kmemstatistics; type != NULL; type = type->ks_next) 492 cnt++; 493 494 mtx_unlock(&malloc_mtx); 495 bufsize = linesize * (cnt + 1); |
496 p = buf = (char *)malloc(bufsize, M_TEMP, M_WAITOK|M_ZERO); | 496 p = buf = (char *)malloc(bufsize, M_TEMP, M_ZERO); |
497 mtx_lock(&malloc_mtx); 498 499 len = snprintf(p, linesize, 500 "\n Type InUse MemUse HighUse Requests Size(s)\n"); 501 p += len; 502 503 for (type = kmemstatistics; cnt != 0 && type != NULL; 504 type = type->ks_next, cnt--) { --- 63 unchanged lines hidden (view full) --- 568 int i; 569 570 bufsize = linesize * (KMEM_ZSIZE + 1); 571 bufsize += 128; /* For the stats line */ 572 bufsize += 128; /* For the banner line */ 573 waste = 0; 574 mem = 0; 575 | 497 mtx_lock(&malloc_mtx); 498 499 len = snprintf(p, linesize, 500 "\n Type InUse MemUse HighUse Requests Size(s)\n"); 501 p += len; 502 503 for (type = kmemstatistics; cnt != 0 && type != NULL; 504 type = type->ks_next, cnt--) { --- 63 unchanged lines hidden (view full) --- 568 int i; 569 570 bufsize = linesize * (KMEM_ZSIZE + 1); 571 bufsize += 128; /* For the stats line */ 572 bufsize += 128; /* For the banner line */ 573 waste = 0; 574 mem = 0; 575 |
576 p = buf = (char *)malloc(bufsize, M_TEMP, M_WAITOK|M_ZERO); | 576 p = buf = (char *)malloc(bufsize, M_TEMP, M_ZERO); |
577 len = snprintf(p, bufsize, 578 "\n Size Requests Real Size\n"); 579 bufsize -= len; 580 p += len; 581 582 for (i = 0; i < KMEM_ZSIZE; i++) { 583 size = i << KMEM_ZSHIFT; 584 rsize = kmemzones[kmemsize[i]].kz_size; --- 26 unchanged lines hidden --- | 577 len = snprintf(p, bufsize, 578 "\n Size Requests Real Size\n"); 579 bufsize -= len; 580 p += len; 581 582 for (i = 0; i < KMEM_ZSIZE; i++) { 583 size = i << KMEM_ZSHIFT; 584 rsize = kmemzones[kmemsize[i]].kz_size; --- 26 unchanged lines hidden --- |