xref: /titanic_41/usr/src/uts/common/sys/vmem.h (revision 4445fffbbb1ea25fd0e9ea68b9380dd7a6709025)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright (c) 2012 by Delphix. All rights reserved.
24  */
25 
26 #ifndef _SYS_VMEM_H
27 #define	_SYS_VMEM_H
28 
29 #include <sys/types.h>
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 
36 /*
37  * Per-allocation flags
38  */
39 #define	VM_SLEEP	0x00000000	/* same as KM_SLEEP */
40 #define	VM_NOSLEEP	0x00000001	/* same as KM_NOSLEEP */
41 #define	VM_PANIC	0x00000002	/* same as KM_PANIC */
42 #define	VM_PUSHPAGE	0x00000004	/* same as KM_PUSHPAGE */
43 #define	VM_NORMALPRI	0x00000008	/* same as KM_NORMALPRI */
44 #define	VM_KMFLAGS	0x000000ff	/* flags that must match KM_* flags */
45 
46 #define	VM_BESTFIT	0x00000100
47 #define	VM_FIRSTFIT	0x00000200
48 #define	VM_NEXTFIT	0x00000400
49 
50 /*
51  * The following flags are restricted for use only within the kernel.
52  * VM_MEMLOAD is for use by the HAT to avoid infinite recursion.
53  * VM_NORELOC is used by the kernel when static VA->PA mappings are required.
54  */
55 #define	VM_MEMLOAD	0x00000800
56 #define	VM_NORELOC	0x00001000
57 /*
58  * VM_ABORT requests that vmem_alloc() *ignore* the VM_SLEEP/VM_NOSLEEP flags
59  * and forgo reaping if the allocation or attempted import, fails.  This
60  * flag is a segkmem-specific flag, and should not be used by anyone else.
61  */
62 #define	VM_ABORT	0x00002000
63 
64 /*
65  * VM_ENDALLOC requests that large addresses be preferred in allocations.
66  * Has no effect if VM_NEXTFIT is active.
67  */
68 #define	VM_ENDALLOC	0x00004000
69 
70 #define	VM_FLAGS	0x0000FFFF
71 
72 /*
73  * Arena creation flags
74  */
75 #define	VMC_POPULATOR	0x00010000
76 #define	VMC_NO_QCACHE	0x00020000	/* cannot use quantum caches */
77 #define	VMC_IDENTIFIER	0x00040000	/* not backed by memory */
78 #define	VMC_DUMPSAFE	0x00200000	/* can use alternate dump memory */
79 /*
80  * internal use only;	the import function uses the vmem_ximport_t interface
81  *			and may increase the request size if it so desires.
82  *			VMC_XALIGN, for use with vmem_xcreate, specifies that
83  *			the address returned by the import function will be
84  *			aligned according to the alignment argument.
85  */
86 #define	VMC_XALLOC	0x00080000
87 #define	VMC_XALIGN	0x00100000
88 #define	VMC_FLAGS	0xFFFF0000
89 
90 /*
91  * Public segment types
92  */
93 #define	VMEM_ALLOC	0x01
94 #define	VMEM_FREE	0x02
95 
96 /*
97  * Implementation-private segment types
98  */
99 #define	VMEM_SPAN	0x10
100 #define	VMEM_ROTOR	0x20
101 #define	VMEM_WALKER	0x40
102 
103 /*
104  * VMEM_REENTRANT indicates to vmem_walk() that the callback routine may
105  * call back into the arena being walked, so vmem_walk() must drop the
106  * arena lock before each callback.  The caveat is that since the arena
107  * isn't locked, its state can change.  Therefore it is up to the callback
108  * routine to handle cases where the segment isn't of the expected type.
109  * For example, we use this to walk heap_arena when generating a crash dump;
110  * see segkmem_dump() for sample usage.
111  */
112 #define	VMEM_REENTRANT	0x80000000
113 
114 typedef struct vmem vmem_t;
115 typedef void *(vmem_alloc_t)(vmem_t *, size_t, int);
116 typedef void (vmem_free_t)(vmem_t *, void *, size_t);
117 
118 /*
119  * Alternate import style; the requested size is passed in a pointer,
120  * which can be increased by the import function if desired.
121  */
122 typedef void *(vmem_ximport_t)(vmem_t *, size_t *, size_t, int);
123 
124 #ifdef _KERNEL
125 extern vmem_t *vmem_init(const char *, void *, size_t, size_t,
126     vmem_alloc_t *, vmem_free_t *);
127 extern void vmem_update(void *);
128 extern int vmem_is_populator();
129 extern size_t vmem_seg_size;
130 #endif
131 
132 extern vmem_t *vmem_create(const char *, void *, size_t, size_t,
133     vmem_alloc_t *, vmem_free_t *, vmem_t *, size_t, int);
134 extern vmem_t *vmem_xcreate(const char *, void *, size_t, size_t,
135     vmem_ximport_t *, vmem_free_t *, vmem_t *, size_t, int);
136 extern void vmem_destroy(vmem_t *);
137 extern void *vmem_alloc(vmem_t *, size_t, int);
138 extern void *vmem_xalloc(vmem_t *, size_t, size_t, size_t, size_t,
139     void *, void *, int);
140 extern void vmem_free(vmem_t *, void *, size_t);
141 extern void vmem_xfree(vmem_t *, void *, size_t);
142 extern void *vmem_add(vmem_t *, void *, size_t, int);
143 extern int vmem_contains(vmem_t *, void *, size_t);
144 extern void vmem_walk(vmem_t *, int, void (*)(void *, void *, size_t), void *);
145 extern size_t vmem_size(vmem_t *, int);
146 extern void vmem_qcache_reap(vmem_t *vmp);
147 
148 #ifdef	__cplusplus
149 }
150 #endif
151 
152 #endif	/* _SYS_VMEM_H */
153