blob: e20d2ada67f00d670a559e4e220a497ad81ce1b2 [file] [log] [blame]
tuexen5bc8d3d2012-05-23 09:39:05 +00001/*-
2 * Copyright (c) 2009-2010 Brad Penoff
3 * Copyright (c) 2009-2010 Humaira Kamal
4 * Copyright (c) 2011-2012 Irene Ruengeler
5 * Copyright (c) 2011-2012 Michael Tuexen
6 *
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#ifndef _USER_UMA_H_
32#define _USER_UMA_H_
33
tuexenaf04b472011-11-01 23:02:02 +000034#define UMA_ZFLAG_FULL 0x40000000 /* Reached uz_maxpages */
35#define UMA_ALIGN_PTR (sizeof(void *) - 1) /* Alignment fit for ptr */
36
tuexen5bc8d3d2012-05-23 09:39:05 +000037/* __Userspace__ All these definitions will change for
38userspace Universal Memory Allocator (UMA). These are included
tuexenaf04b472011-11-01 23:02:02 +000039for reference purposes and to avoid compile errors for the time being.
40*/
41typedef int (*uma_ctor)(void *mem, int size, void *arg, int flags);
42typedef void (*uma_dtor)(void *mem, int size, void *arg);
43typedef int (*uma_init)(void *mem, int size, int flags);
44typedef void (*uma_fini)(void *mem, int size);
45typedef struct uma_zone * uma_zone_t;
46typedef struct uma_keg * uma_keg_t;
47
48struct uma_cache {
Felix Weinrankdb272162020-01-20 15:34:50 +010049 int stub; /* TODO __Userspace__ */
tuexenaf04b472011-11-01 23:02:02 +000050};
51
52struct uma_keg {
Felix Weinrankdb272162020-01-20 15:34:50 +010053 int stub; /* TODO __Userspace__ */
tuexenaf04b472011-11-01 23:02:02 +000054};
55
56struct uma_zone {
57 char *uz_name; /* Text name of the zone */
58 struct mtx *uz_lock; /* Lock for the zone (keg's lock) */
59 uma_keg_t uz_keg; /* Our underlying Keg */
60
61 LIST_ENTRY(uma_zone) uz_link; /* List of all zones in keg */
62 LIST_HEAD(,uma_bucket) uz_full_bucket; /* full buckets */
63 LIST_HEAD(,uma_bucket) uz_free_bucket; /* Buckets for frees */
64
65 uma_ctor uz_ctor; /* Constructor for each allocation */
66 uma_dtor uz_dtor; /* Destructor */
67 uma_init uz_init; /* Initializer for each item */
68 uma_fini uz_fini; /* Discards memory */
69
70 u_int64_t uz_allocs; /* Total number of allocations */
71 u_int64_t uz_frees; /* Total number of frees */
72 u_int64_t uz_fails; /* Total number of alloc failures */
73 uint16_t uz_fills; /* Outstanding bucket fills */
74 uint16_t uz_count; /* Highest value ub_ptr can have */
75
76 /*
77 * This HAS to be the last item because we adjust the zone size
78 * based on NCPU and then allocate the space for the zones.
79 */
80 struct uma_cache uz_cpu[1]; /* Per cpu caches */
81};
82
83/* Prototype */
84uma_zone_t
85uma_zcreate(char *name, size_t size, uma_ctor ctor, uma_dtor dtor,
86 uma_init uminit, uma_fini fini, int align, u_int32_t flags);
87
88
89#define uma_zone_set_max(zone, number) /* stub TODO __Userspace__ */
90
91uma_zone_t
92uma_zcreate(char *name, size_t size, uma_ctor ctor, uma_dtor dtor,
Felix Weinrankdb272162020-01-20 15:34:50 +010093 uma_init uminit, uma_fini fini, int align, u_int32_t flags) {
94 return NULL; /* stub TODO __Userspace__. Also place implementation in a separate .c file */
tuexenaf04b472011-11-01 23:02:02 +000095}
tuexen5bc8d3d2012-05-23 09:39:05 +000096#endif