2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
18 #include <sys/debug.h>
19 #include <sys/ksynch.h>
20 #include <sys/systm.h>
24 void abort(void) __NORETURN
;
30 return (UMEM_CALLBACK_RETRY
);
33 #pragma init(_kmem_init)
37 umem_nofail_callback(kmem_failed_cb
);
42 kmem2umem_flags(int kmflags
)
44 int umflags
= UMEM_NOFAIL
;
45 if (kmflags
& KM_NOSLEEP
)
46 umflags
= UMEM_DEFAULT
;
57 kmem_alloc(size_t size
, int kmflags
)
59 return (umem_alloc(size
, kmem2umem_flags(kmflags
)));
63 kmem_zalloc(size_t size
, int kmflags
)
65 return (umem_zalloc(size
, kmem2umem_flags(kmflags
)));
70 kmem_free(void *buf
, size_t size
)
75 /* void *kmem_alloc_tryhard(size_t size, size_t *alloc_size, int kmflags); */
79 char *name
, /* descriptive name for this cache */
80 size_t bufsize
, /* size of the objects it manages */
81 size_t align
, /* required object alignment */
82 int (*constructor
)(void *, void *, int), /* object constructor */
83 void (*destructor
)(void *, void *), /* object destructor */
84 void (*reclaim
)(void *), /* memory reclaim callback */
85 void *private, /* pass-thru arg for constr/destr/reclaim */
86 vmem_t
*vmp
, /* vmem source for slab allocation */
87 int kcflags
) /* cache creation flags */
92 /* Ignore KMC_NOTOUCH - not needed for userland caches */
93 if (kcflags
& KMC_NODEBUG
)
94 ucflags
|= UMC_NODEBUG
;
95 if (kcflags
& KMC_NOMAGAZINE
)
96 ucflags
|= UMC_NOMAGAZINE
;
97 if (kcflags
& KMC_NOHASH
)
98 ucflags
|= UMC_NOHASH
;
100 uc
= umem_cache_create(name
, bufsize
, align
,
101 constructor
, destructor
, reclaim
,
102 private, vmp
, ucflags
);
103 return ((kmem_cache_t
*)uc
);
107 kmem_cache_destroy(kmem_cache_t
*kc
)
109 umem_cache_destroy((umem_cache_t
*)kc
);
113 kmem_cache_alloc(kmem_cache_t
*kc
, int kmflags
)
115 return (umem_cache_alloc((umem_cache_t
*)kc
,
116 kmem2umem_flags(kmflags
)));
120 kmem_cache_free(kmem_cache_t
*kc
, void *p
)
122 umem_cache_free((umem_cache_t
*)kc
, p
);
127 kmem_cache_set_move(kmem_cache_t
*kc
,
128 kmem_cbrc_t (*fun
)(void *, void *, size_t, void *))
134 kmem_cache_reap_now(kmem_cache_t
*kc
)
138 /* uint64_t kmem_cache_stat(kmem_cache_t *, char *); */
142 vmem_qcache_reap(struct vmem
*vmp
)
150 kmem_free(str
, strlen(str
) + 1);