kern_malloc.c (42453) | kern_malloc.c (42957) |
---|---|
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 * $Id: kern_malloc.c,v 1.50 1999/01/08 17:31:09 eivind Exp $ | 34 * $Id: kern_malloc.c,v 1.51 1999/01/10 01:58:24 eivind Exp $ |
35 */ 36 37#include "opt_vm.h" 38 39#include <sys/param.h> 40#include <sys/systm.h> 41#include <sys/kernel.h> 42#define MALLOC_INSTANTIATE --- 53 unchanged lines hidden (view full) --- 96}; 97#else /* !INVARIANTS */ 98struct freelist { 99 caddr_t next; 100}; 101#endif /* INVARIANTS */ 102 103/* | 35 */ 36 37#include "opt_vm.h" 38 39#include <sys/param.h> 40#include <sys/systm.h> 41#include <sys/kernel.h> 42#define MALLOC_INSTANTIATE --- 53 unchanged lines hidden (view full) --- 96}; 97#else /* !INVARIANTS */ 98struct freelist { 99 caddr_t next; 100}; 101#endif /* INVARIANTS */ 102 103/* |
104 * Allocate a block of memory | 104 * malloc: 105 * 106 * Allocate a block of memory. 107 * 108 * If M_NOWAIT is set, this routine will not block and return NULL if 109 * the allocation fails. 110 * 111 * If M_ASLEEP is set (M_NOWAIT must also be set), this routine 112 * will have the side effect of calling asleep() if it returns NULL, 113 * allowing the parent to await() at some future time. |
105 */ 106void * 107malloc(size, type, flags) 108 unsigned long size; 109 struct malloc_type *type; 110 int flags; 111{ 112 register struct kmembuckets *kbp; --- 4 unchanged lines hidden (view full) --- 117 caddr_t va, cp, savedlist; 118#ifdef INVARIANTS 119 long *end, *lp; 120 int copysize; 121 char *savedtype; 122#endif 123 register struct malloc_type *ksp = type; 124 | 114 */ 115void * 116malloc(size, type, flags) 117 unsigned long size; 118 struct malloc_type *type; 119 int flags; 120{ 121 register struct kmembuckets *kbp; --- 4 unchanged lines hidden (view full) --- 126 caddr_t va, cp, savedlist; 127#ifdef INVARIANTS 128 long *end, *lp; 129 int copysize; 130 char *savedtype; 131#endif 132 register struct malloc_type *ksp = type; 133 |
125 if (!type->ks_next) | 134 /* 135 * Must be at splmem() prior to initializing segment to handle 136 * potential initialization race. 137 */ 138 139 s = splmem(); 140 141 if (!type->ks_next) { |
126 malloc_init(type); | 142 malloc_init(type); |
143 } |
|
127 128 indx = BUCKETINDX(size); 129 kbp = &bucket[indx]; | 144 145 indx = BUCKETINDX(size); 146 kbp = &bucket[indx]; |
130 s = splmem(); | 147 |
131 while (ksp->ks_memuse >= ksp->ks_limit) { | 148 while (ksp->ks_memuse >= ksp->ks_limit) { |
149 if (flags & M_ASLEEP) { 150 if (ksp->ks_limblocks < 65535) 151 ksp->ks_limblocks++; 152 asleep((caddr_t)ksp, PSWP+2, type->ks_shortdesc, 0); 153 } |
|
132 if (flags & M_NOWAIT) { 133 splx(s); 134 return ((void *) NULL); 135 } 136 if (ksp->ks_limblocks < 65535) 137 ksp->ks_limblocks++; 138 tsleep((caddr_t)ksp, PSWP+2, type->ks_shortdesc, 0); 139 } --- 94 unchanged lines hidden (view full) --- 234 ksp->ks_calls++; 235 if (ksp->ks_memuse > ksp->ks_maxused) 236 ksp->ks_maxused = ksp->ks_memuse; 237 splx(s); 238 return ((void *) va); 239} 240 241/* | 154 if (flags & M_NOWAIT) { 155 splx(s); 156 return ((void *) NULL); 157 } 158 if (ksp->ks_limblocks < 65535) 159 ksp->ks_limblocks++; 160 tsleep((caddr_t)ksp, PSWP+2, type->ks_shortdesc, 0); 161 } --- 94 unchanged lines hidden (view full) --- 256 ksp->ks_calls++; 257 if (ksp->ks_memuse > ksp->ks_maxused) 258 ksp->ks_maxused = ksp->ks_memuse; 259 splx(s); 260 return ((void *) va); 261} 262 263/* |
242 * Free a block of memory allocated by malloc. | 264 * free: 265 * 266 * Free a block of memory allocated by malloc. 267 * 268 * This routine may not block. |
243 */ 244void 245free(addr, type) 246 void *addr; 247 struct malloc_type *type; 248{ 249 register struct kmembuckets *kbp; 250 register struct kmemusage *kup; --- 225 unchanged lines hidden --- | 269 */ 270void 271free(addr, type) 272 void *addr; 273 struct malloc_type *type; 274{ 275 register struct kmembuckets *kbp; 276 register struct kmemusage *kup; --- 225 unchanged lines hidden --- |