Print this page
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/sys/kmem.h
+++ new/usr/src/uts/common/sys/kmem.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 * Copyright (c) 2012 by Delphix. All rights reserved.
25 25 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
26 26 * Copyright 2022 Joyent, Inc.
27 27 */
28 28
29 29 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
30 30 /* All Rights Reserved */
31 31
32 32 #ifndef _SYS_KMEM_H
33 33 #define _SYS_KMEM_H
34 34
35 35 #include <sys/types.h>
36 36 #include <sys/vmem.h>
37 37
38 38 #ifdef __cplusplus
39 39 extern "C" {
40 40 #endif
41 41
42 42 /*
43 43 * Kernel memory allocator: DDI interfaces.
44 44 * See kmem_alloc(9F) for details.
45 45 */
46 46
47 47 #define KM_SLEEP 0x0000 /* can block for memory; success guaranteed */
48 48 #define KM_NOSLEEP 0x0001 /* cannot block for memory; may fail */
49 49 #define KM_PANIC 0x0002 /* if memory cannot be allocated, panic */
50 50 #define KM_PUSHPAGE 0x0004 /* can block for memory; may use reserve */
51 51 #define KM_NORMALPRI 0x0008 /* with KM_NOSLEEP, lower priority allocation */
52 52 #define KM_NOSLEEP_LAZY (KM_NOSLEEP | KM_NORMALPRI) /* Syntactic sugar. */
53 53 #define KM_VMFLAGS 0x00ff /* flags that must match VM_* flags */
54 54
55 55 #define KM_FLAGS 0xffff /* all settable kmem flags */
56 56
57 57 #if defined(_KERNEL) || defined(_FAKE_KERNEL)
58 58
59 59 extern void *kmem_alloc(size_t size, int kmflags);
60 60 extern void *kmem_zalloc(size_t size, int kmflags);
61 61 extern void kmem_free(void *buf, size_t size);
62 62 extern void *kmem_alloc_tryhard(size_t size, size_t *alloc_size, int kmflags);
63 63 extern void kmem_dump_init(size_t);
64 64 extern void kmem_dump_begin(void);
65 65 extern size_t kmem_dump_finish(char *buf, size_t size);
66 66 extern void *kmem_rezalloc(void *, size_t, size_t, int);
67 67
68 68 #endif /* _KERNEL */
69 69
70 70 /*
71 71 * Kernel memory allocator: private interfaces.
72 72 * These interfaces are still evolving.
73 73 * Do not use them in unbundled drivers.
74 74 */
75 75
76 76 /*
77 77 * Flags for kmem_cache_create()
78 78 */
79 79 #define KMC_NOTOUCH 0x00010000
80 80 #define KMC_NODEBUG 0x00020000
81 81 #define KMC_NOMAGAZINE 0x00040000
82 82 #define KMC_NOHASH 0x00080000
83 83 #define KMC_QCACHE 0x00100000
84 84 #define KMC_KMEM_ALLOC 0x00200000 /* internal use only */
85 85 #define KMC_IDENTIFIER 0x00400000 /* internal use only */
86 86 #define KMC_PREFILL 0x00800000
87 87
88 88 struct kmem_cache; /* cache structure is opaque to kmem clients */
89 89
90 90 typedef struct kmem_cache kmem_cache_t;
91 91
92 92 /* Client response to kmem move callback */
93 93 typedef enum kmem_cbrc {
94 94 KMEM_CBRC_YES,
95 95 KMEM_CBRC_NO,
96 96 KMEM_CBRC_LATER,
97 97 KMEM_CBRC_DONT_NEED,
98 98 KMEM_CBRC_DONT_KNOW
99 99 } kmem_cbrc_t;
100 100
101 101 #if defined(_KERNEL) || defined(_FAKE_KERNEL)
102 102
103 103 /*
104 104 * Helps clients implementing the move() callback to recognize known objects by
105 105 * testing a client-designated pointer member. Takes advantage of the fact that
106 106 * any scribbling to freed memory done by kmem is guaranteed to set one of the
107 107 * two low order bits.
108 108 */
109 109 #define POINTER_IS_VALID(p) (!((uintptr_t)(p) & 0x3))
110 110 #define POINTER_INVALIDATE(pp) (*(pp) = (void *)((uintptr_t)(*(pp)) | 0x1))
111 111
112 112 extern int kmem_ready;
113 113 extern pgcnt_t kmem_reapahead;
114 114 extern size_t kmem_max_cached;
115 115
116 116 extern void kmem_init(void);
117 117 extern void kmem_thread_init(void);
118 118 extern void kmem_mp_init(void);
119 119 extern void kmem_reap(void);
120 120 extern void kmem_reap_idspace(void);
121 121 extern int kmem_debugging(void);
122 122 extern size_t kmem_avail(void);
123 123 extern size_t kmem_maxavail(void);
124 124
125 125 extern kmem_cache_t *kmem_cache_create(char *, size_t, size_t,
126 126 int (*)(void *, void *, int), void (*)(void *, void *),
127 127 void (*)(void *), void *, vmem_t *, int);
128 128 extern void kmem_cache_set_move(kmem_cache_t *,
129 129 kmem_cbrc_t (*)(void *, void *, size_t, void *));
130 130 extern void kmem_cache_destroy(kmem_cache_t *);
131 131 extern void *kmem_cache_alloc(kmem_cache_t *, int);
132 132 extern void kmem_cache_free(kmem_cache_t *, void *);
133 133 extern uint64_t kmem_cache_stat(kmem_cache_t *, char *);
134 134 extern boolean_t kmem_cache_reap_active(void);
135 135 extern void kmem_cache_reap_soon(kmem_cache_t *);
136 136 extern void kmem_cache_move_notify(kmem_cache_t *, void *);
137 137
138 138 #endif /* _KERNEL */
139 139
140 140 #ifdef __cplusplus
141 141 }
142 142 #endif
143 143
144 144 #endif /* _SYS_KMEM_H */
|
↓ open down ↓ |
144 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX