Deleted Added
full compact
kern_malloc.c (180308) kern_malloc.c (187681)
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>
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 180308 2008-07-05 19:34:33Z alc $");
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;
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 uma_keg_t keg;
333#if defined(DIAGNOSTIC) || defined(DEBUG_REDZONE)
334 unsigned long osize = size;
335#endif
336
337#ifdef INVARIANTS
338 /*
339 * Check that exactly one of M_WAITOK or M_NOWAIT is specified.
340 */

--- 32 unchanged lines hidden (view full) ---

373 size = redzone_size_ntor(size);
374#endif
375
376 if (size <= KMEM_ZMAX) {
377 if (size & KMEM_ZMASK)
378 size = (size & ~KMEM_ZMASK) + KMEM_ZBASE;
379 indx = kmemsize[size >> KMEM_ZSHIFT];
380 zone = kmemzones[indx].kz_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;
381 keg = zone->uz_keg;
382#ifdef MALLOC_PROFILE
383 krequests[size >> KMEM_ZSHIFT]++;
384#endif
385 va = uma_zalloc(zone, flags);
386 if (va != NULL)
380#ifdef MALLOC_PROFILE
381 krequests[size >> KMEM_ZSHIFT]++;
382#endif
383 va = uma_zalloc(zone, flags);
384 if (va != NULL)
387 size = keg->uk_size;
385 size = zone->uz_size;
388 malloc_type_zone_allocated(mtp, va == NULL ? 0 : size, indx);
389 } else {
390 size = roundup(size, PAGE_SIZE);
391 zone = NULL;
386 malloc_type_zone_allocated(mtp, va == NULL ? 0 : size, indx);
387 } else {
388 size = roundup(size, PAGE_SIZE);
389 zone = NULL;
392 keg = NULL;
393 va = uma_large_malloc(size, flags);
394 malloc_type_allocated(mtp, va == NULL ? 0 : size);
395 }
396 if (flags & M_WAITOK)
397 KASSERT(va != NULL, ("malloc(M_WAITOK) returned NULL"));
398 else if (va == NULL)
399 t_malloc_fail = time_uptime;
400#ifdef DIAGNOSTIC

--- 553 unchanged lines hidden ---
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 ---