1/*- 2 * Copyright (c) 2002, 2003, 2004, 2005 Jeffrey Roberson <jeff@FreeBSD.org> 3 * Copyright (c) 2004, 2005 Bosko Milekic <bmilekic@FreeBSD.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 10 unchanged lines hidden (view full) --- 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * |
27 * $FreeBSD: head/sys/vm/uma.h 244024 2012-12-08 09:23:05Z pjd $ |
28 * 29 */ 30 31/* 32 * uma.h - External definitions for the Universal Memory Allocator 33 * 34*/ 35 --- 9 unchanged lines hidden (view full) --- 45/* Types and type defs */ 46 47struct uma_zone; 48/* Opaque type used as a handle to the zone */ 49typedef struct uma_zone * uma_zone_t; 50 51void zone_drain(uma_zone_t); 52 |
53/* |
54 * Item constructor 55 * 56 * Arguments: 57 * item A pointer to the memory which has been allocated. 58 * arg The arg field passed to uma_zalloc_arg 59 * size The size of the allocated item 60 * flags See zalloc flags |
61 * |
62 * Returns: 63 * 0 on success 64 * errno on failure 65 * 66 * Discussion: 67 * The constructor is called just before the memory is returned 68 * to the user. It may block if necessary. 69 */ 70typedef int (*uma_ctor)(void *mem, int size, void *arg, int flags); 71 72/* 73 * Item destructor 74 * 75 * Arguments: 76 * item A pointer to the memory which has been allocated. 77 * size The size of the item being destructed. 78 * arg Argument passed through uma_zfree_arg |
79 * |
80 * Returns: 81 * Nothing 82 * 83 * Discussion: 84 * The destructor may perform operations that differ from those performed 85 * by the initializer, but it must leave the object in the same state. 86 * This IS type stable storage. This is called after EVERY zfree call. 87 */ 88typedef void (*uma_dtor)(void *mem, int size, void *arg); 89 |
90/* |
91 * Item initializer 92 * 93 * Arguments: 94 * item A pointer to the memory which has been allocated. 95 * size The size of the item being initialized. 96 * flags See zalloc flags |
97 * |
98 * Returns: 99 * 0 on success 100 * errno on failure 101 * 102 * Discussion: |
103 * The initializer is called when the memory is cached in the uma zone. |
104 * The initializer and the destructor should leave the object in the same 105 * state. 106 */ 107typedef int (*uma_init)(void *mem, int size, int flags); 108 109/* 110 * Item discard function 111 * 112 * Arguments: |
113 * item A pointer to memory which has been 'freed' but has not left the |
114 * zone's cache. 115 * size The size of the item being discarded. 116 * 117 * Returns: 118 * Nothing 119 * 120 * Discussion: 121 * This routine is called when memory leaves a zone and is returned to the 122 * system for other uses. It is the counter-part to the init function. 123 */ 124typedef void (*uma_fini)(void *mem, int size); 125 126/* 127 * What's the difference between initializing and constructing? 128 * |
129 * The item is initialized when it is cached, and this is the state that the |
130 * object should be in when returned to the allocator. The purpose of this is 131 * to remove some code which would otherwise be called on each allocation by 132 * utilizing a known, stable state. This differs from the constructor which 133 * will be called on EVERY allocation. 134 * 135 * For example, in the initializer you may want to initialize embedded locks, 136 * NULL list pointers, set up initial states, magic numbers, etc. This way if 137 * the object is held in the allocator and re-used it won't be necessary to --- 68 unchanged lines hidden (view full) --- 206 207/* 208 * Add a second master to a secondary zone. This provides multiple data 209 * backends for objects with the same size. Both masters must have 210 * compatible allocation flags. Presently, UMA_ZONE_MALLOC type zones are 211 * the only supported. 212 * 213 * Returns: |
214 * Error on failure, 0 on success. |
215 */ 216int uma_zsecond_add(uma_zone_t zone, uma_zone_t master); 217 218/* 219 * Definitions for uma_zcreate flags 220 * 221 * These flags share space with UMA_ZFLAGs in uma_int.h. Be careful not to 222 * overlap when adding new features. 0xf0000000 is in use by uma_int.h. --- 175 unchanged lines hidden (view full) --- 398 * None 399 * 400 * Returns: 401 * Nothing 402 * 403 * Discussion: 404 * uma_startup2 is called by kmeminit() to enable us of uma for malloc. 405 */ |
406 |
407void uma_startup2(void); 408 409/* 410 * Reclaims unused memory for all zones 411 * 412 * Arguments: 413 * None 414 * Returns: --- 163 unchanged lines hidden (view full) --- 578 579/* 580 * Used to lookup the reference counter allocated for an item 581 * from a UMA_ZONE_REFCNT zone. For UMA_ZONE_REFCNT zones, 582 * reference counters are allocated for items and stored in 583 * the underlying slab header. 584 * 585 * Arguments: |
586 * zone The UMA_ZONE_REFCNT zone to which the item belongs. |
587 * item The address of the item for which we want a refcnt. 588 * 589 * Returns: |
590 * A pointer to a u_int32_t reference counter. |
591 */ 592u_int32_t *uma_find_refcnt(uma_zone_t zone, void *item); 593 594/* 595 * Used to determine if a fixed-size zone is exhausted. 596 * 597 * Arguments: 598 * zone The zone to check 599 * 600 * Returns: |
601 * Non-zero if zone is exhausted. |
602 */ 603int uma_zone_exhausted(uma_zone_t zone); 604int uma_zone_exhausted_nolock(uma_zone_t zone); 605 606/* 607 * Exported statistics structures to be used by user space monitoring tools. 608 * Statistics stream consists of a uma_stream_header, followed by a series of 609 * alternative uma_type_header and uma_type_stat structures. --- 45 unchanged lines hidden --- |