Print this page
8115 parallel zfs mount
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libfakekernel/common/kmem.c
+++ new/usr/src/lib/libfakekernel/common/kmem.c
1 1 /*
2 2 * This file and its contents are supplied under the terms of the
3 3 * Common Development and Distribution License ("CDDL"), version 1.0.
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
4 4 * You may only use this file in accordance with the terms of version
5 5 * 1.0 of the CDDL.
6 6 *
7 7 * A full copy of the text of the CDDL should have accompanied this
8 8 * source. A copy of the CDDL is also available via the Internet at
9 9 * http://www.illumos.org/license/CDDL.
10 10 */
11 11
12 12 /*
13 13 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
14 + * Copyright 2017 RackTop Systems.
14 15 */
15 16
16 17 #include <sys/kmem.h>
17 18
18 19 #include <sys/debug.h>
19 20 #include <sys/ksynch.h>
20 21 #include <sys/systm.h>
22 +#include <sys/cmn_err.h>
21 23
22 24 #include <umem.h>
23 25
24 26 void abort(void) __NORETURN;
25 27
26 28 static int
27 29 kmem_failed_cb(void)
28 30 {
29 31 abort();
30 32 return (UMEM_CALLBACK_RETRY);
31 33 }
32 34
33 35 #pragma init(_kmem_init)
34 36 static int
35 37 _kmem_init(void)
36 38 {
37 39 umem_nofail_callback(kmem_failed_cb);
38 40 return (0);
39 41 }
40 42
41 43 static int
42 44 kmem2umem_flags(int kmflags)
43 45 {
44 46 int umflags = UMEM_NOFAIL;
45 47 if (kmflags & KM_NOSLEEP)
46 48 umflags = UMEM_DEFAULT;
47 49 return (umflags);
48 50 }
49 51
50 52 int
51 53 kmem_debugging(void)
52 54 {
53 55 return (0);
54 56 }
55 57
56 58 void *
57 59 kmem_alloc(size_t size, int kmflags)
↓ open down ↓ |
27 lines elided |
↑ open up ↑ |
58 60 {
59 61 return (umem_alloc(size, kmem2umem_flags(kmflags)));
60 62 }
61 63
62 64 void *
63 65 kmem_zalloc(size_t size, int kmflags)
64 66 {
65 67 return (umem_zalloc(size, kmem2umem_flags(kmflags)));
66 68 }
67 69
70 +/*
71 + * Do not change the length of the returned string; it must be freed
72 + * with strfree().
73 + */
74 +char *
75 +kmem_asprintf(const char *fmt, ...)
76 +{
77 + int size;
78 + va_list adx;
79 + char *buf;
68 80
81 + va_start(adx, fmt);
82 + size = vsnprintf(NULL, 0, fmt, adx) + 1;
83 + va_end(adx);
84 +
85 + buf = kmem_alloc(size, KM_SLEEP);
86 +
87 + va_start(adx, fmt);
88 + size = vsnprintf(buf, size, fmt, adx);
89 + va_end(adx);
90 +
91 + return (buf);
92 +}
93 +
69 94 void
70 95 kmem_free(void *buf, size_t size)
71 96 {
72 97 umem_free(buf, size);
73 98 }
74 99
75 100 /* void *kmem_alloc_tryhard(size_t size, size_t *alloc_size, int kmflags); */
76 101
77 102 kmem_cache_t *
78 103 kmem_cache_create(
79 104 char *name, /* descriptive name for this cache */
80 105 size_t bufsize, /* size of the objects it manages */
81 106 size_t align, /* required object alignment */
82 107 int (*constructor)(void *, void *, int), /* object constructor */
83 108 void (*destructor)(void *, void *), /* object destructor */
84 109 void (*reclaim)(void *), /* memory reclaim callback */
85 110 void *private, /* pass-thru arg for constr/destr/reclaim */
86 111 vmem_t *vmp, /* vmem source for slab allocation */
87 112 int kcflags) /* cache creation flags */
88 113 {
89 114 umem_cache_t *uc;
90 115 int ucflags = 0;
91 116
92 117 /* Ignore KMC_NOTOUCH - not needed for userland caches */
93 118 if (kcflags & KMC_NODEBUG)
94 119 ucflags |= UMC_NODEBUG;
95 120 if (kcflags & KMC_NOMAGAZINE)
96 121 ucflags |= UMC_NOMAGAZINE;
97 122 if (kcflags & KMC_NOHASH)
98 123 ucflags |= UMC_NOHASH;
99 124
100 125 uc = umem_cache_create(name, bufsize, align,
101 126 constructor, destructor, reclaim,
102 127 private, vmp, ucflags);
103 128 return ((kmem_cache_t *)uc);
104 129 }
105 130
106 131 void
107 132 kmem_cache_destroy(kmem_cache_t *kc)
108 133 {
109 134 umem_cache_destroy((umem_cache_t *)kc);
110 135 }
111 136
112 137 void *
113 138 kmem_cache_alloc(kmem_cache_t *kc, int kmflags)
114 139 {
115 140 return (umem_cache_alloc((umem_cache_t *)kc,
116 141 kmem2umem_flags(kmflags)));
117 142 }
118 143
119 144 void
120 145 kmem_cache_free(kmem_cache_t *kc, void *p)
121 146 {
122 147 umem_cache_free((umem_cache_t *)kc, p);
123 148 }
124 149
125 150 /* ARGSUSED */
126 151 void
127 152 kmem_cache_set_move(kmem_cache_t *kc,
128 153 kmem_cbrc_t (*fun)(void *, void *, size_t, void *))
129 154 {
130 155 }
131 156
132 157 /* ARGSUSED */
133 158 void
134 159 kmem_cache_reap_now(kmem_cache_t *kc)
135 160 {
136 161 }
137 162
138 163 /* uint64_t kmem_cache_stat(kmem_cache_t *, char *); */
139 164
140 165 /* ARGSUSED */
141 166 void
142 167 vmem_qcache_reap(struct vmem *vmp)
143 168 {
144 169 }
145 170
146 171 void
147 172 strfree(char *str)
148 173 {
149 174 ASSERT(str != NULL);
150 175 kmem_free(str, strlen(str) + 1);
151 176 }
↓ open down ↓ |
73 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX