1/*- 2 * Copyright (c) 2002-2005, 2009 Jeffrey Roberson <jeff@FreeBSD.org> 3 * Copyright (c) 2004, 2005 Bosko Milekic <bmilekic@FreeBSD.org> 4 * Copyright (c) 2004-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 --- 34 unchanged lines hidden (view full) --- 43 44/* 45 * TODO: 46 * - Improve memory usage for large allocations 47 * - Investigate cache size adjustments 48 */ 49 50#include <sys/cdefs.h> |
51__FBSDID("$FreeBSD: head/sys/vm/uma_core.c 226313 2011-10-12 18:08:28Z glebius $"); |
52 53/* I should really use ktr.. */ 54/* 55#define UMA_DEBUG 1 56#define UMA_DEBUG_ALLOC 1 57#define UMA_DEBUG_ALLOC_1 1 58*/ 59 60#include "opt_ddb.h" 61#include "opt_param.h" |
62#include "opt_vm.h" |
63 64#include <sys/param.h> 65#include <sys/systm.h> 66#include <sys/kernel.h> 67#include <sys/types.h> 68#include <sys/queue.h> 69#include <sys/malloc.h> 70#include <sys/ktr.h> --- 13 unchanged lines hidden (view full) --- 84#include <vm/vm_kern.h> 85#include <vm/vm_extern.h> 86#include <vm/uma.h> 87#include <vm/uma_int.h> 88#include <vm/uma_dbg.h> 89 90#include <ddb/ddb.h> 91 |
92#ifdef DEBUG_MEMGUARD 93#include <vm/memguard.h> 94#endif 95 |
96/* 97 * This is the zone and keg from which all zones are spawned. The idea is that 98 * even the zone & keg heads are allocated from the allocator, so we use the 99 * bss section to bootstrap us. 100 */ 101static struct uma_keg masterkeg; 102static struct uma_zone masterzone_k; 103static struct uma_zone masterzone_z; --- 1874 unchanged lines hidden (view full) --- 1978#endif 1979 CTR3(KTR_UMA, "uma_zalloc_arg thread %x zone %s flags %d", curthread, 1980 zone->uz_name, flags); 1981 1982 if (flags & M_WAITOK) { 1983 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, 1984 "uma_zalloc_arg: zone \"%s\"", zone->uz_name); 1985 } |
1986#ifdef DEBUG_MEMGUARD 1987 if (memguard_cmp_zone(zone)) { 1988 item = memguard_alloc(zone->uz_size, flags); 1989 if (item != NULL) { 1990 /* 1991 * Avoid conflict with the use-after-free 1992 * protecting infrastructure from INVARIANTS. 1993 */ 1994 if (zone->uz_init != NULL && 1995 zone->uz_init != mtrash_init && 1996 zone->uz_init(item, zone->uz_size, flags) != 0) 1997 return (NULL); 1998 if (zone->uz_ctor != NULL && 1999 zone->uz_ctor != mtrash_ctor && 2000 zone->uz_ctor(item, zone->uz_size, udata, flags) != 0) { 2001 zone->uz_fini(item, zone->uz_size); 2002 return (NULL); 2003 } 2004 return (item); 2005 } 2006 /* This is unfortunate but should not be fatal. */ 2007 } 2008#endif |
2009 /* 2010 * If possible, allocate from the per-CPU cache. There are two 2011 * requirements for safe access to the per-CPU cache: (1) the thread 2012 * accessing the cache must not be preempted or yield during access, 2013 * and (2) the thread must not migrate CPUs without switching which 2014 * cache it accesses. We rely on a critical section to prevent 2015 * preemption and migration. We release the critical section in 2016 * order to acquire the zone mutex if we are unable to allocate from --- 549 unchanged lines hidden (view full) --- 2566 printf("Freeing item %p to %s(%p)\n", item, zone->uz_name, zone); 2567#endif 2568 CTR2(KTR_UMA, "uma_zfree_arg thread %x zone %s", curthread, 2569 zone->uz_name); 2570 2571 /* uma_zfree(..., NULL) does nothing, to match free(9). */ 2572 if (item == NULL) 2573 return; |
2574#ifdef DEBUG_MEMGUARD 2575 if (is_memguard_addr(item)) { 2576 if (zone->uz_dtor != NULL && zone->uz_dtor != mtrash_dtor) 2577 zone->uz_dtor(item, zone->uz_size, udata); 2578 if (zone->uz_fini != NULL && zone->uz_fini != mtrash_fini) 2579 zone->uz_fini(item, zone->uz_size); 2580 memguard_free(item); 2581 return; 2582 } 2583#endif |
2584 if (zone->uz_dtor) 2585 zone->uz_dtor(item, zone->uz_size, udata); 2586 2587#ifdef INVARIANTS 2588 ZONE_LOCK(zone); 2589 if (zone->uz_flags & UMA_ZONE_MALLOC) 2590 uma_dbg_free(zone, udata, item); 2591 else --- 796 unchanged lines hidden --- |