1/*- 2 * Copyright (c) 1987, 1991, 1993 3 * The Regents of the University of California. 4 * Copyright (c) 2005-2006 Robert N. M. Watson 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 29 unchanged lines hidden (view full) --- 38 * and a special UMA allocation interface is used for larger allocations. 39 * Callers declare memory types, and statistics are maintained independently 40 * for each memory type. Statistics are maintained per-CPU for performance 41 * reasons. See malloc(9) and comments in malloc.h for a detailed 42 * description. 43 */ 44 45#include <sys/cdefs.h> |
46__FBSDID("$FreeBSD: head/sys/kern/kern_malloc.c 187681 2009-01-25 09:11:24Z jeff $"); |
47 48#include "opt_ddb.h" 49#include "opt_kdtrace.h" 50#include "opt_vm.h" 51 52#include <sys/param.h> 53#include <sys/systm.h> 54#include <sys/kdb.h> --- 269 unchanged lines hidden (view full) --- 324 * the allocation fails. 325 */ 326void * 327malloc(unsigned long size, struct malloc_type *mtp, int flags) 328{ 329 int indx; 330 caddr_t va; 331 uma_zone_t zone; |
332#if defined(DIAGNOSTIC) || defined(DEBUG_REDZONE) 333 unsigned long osize = size; 334#endif 335 336#ifdef INVARIANTS 337 /* 338 * Check that exactly one of M_WAITOK or M_NOWAIT is specified. 339 */ --- 32 unchanged lines hidden (view full) --- 372 size = redzone_size_ntor(size); 373#endif 374 375 if (size <= KMEM_ZMAX) { 376 if (size & KMEM_ZMASK) 377 size = (size & ~KMEM_ZMASK) + KMEM_ZBASE; 378 indx = kmemsize[size >> KMEM_ZSHIFT]; 379 zone = kmemzones[indx].kz_zone; |
380#ifdef MALLOC_PROFILE 381 krequests[size >> KMEM_ZSHIFT]++; 382#endif 383 va = uma_zalloc(zone, flags); 384 if (va != NULL) |
385 size = zone->uz_size; |
386 malloc_type_zone_allocated(mtp, va == NULL ? 0 : size, indx); 387 } else { 388 size = roundup(size, PAGE_SIZE); 389 zone = NULL; |
390 va = uma_large_malloc(size, flags); 391 malloc_type_allocated(mtp, va == NULL ? 0 : size); 392 } 393 if (flags & M_WAITOK) 394 KASSERT(va != NULL, ("malloc(M_WAITOK) returned NULL")); 395 else if (va == NULL) 396 t_malloc_fail = time_uptime; 397#ifdef DIAGNOSTIC --- 553 unchanged lines hidden --- |