xref: /illumos-gate/usr/src/uts/common/sys/vmem.h (revision 94dd93ae)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5aaa10e67Sha  * Common Development and Distribution License (the "License").
6aaa10e67Sha  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
2223a80de1SStan Studzinski  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
23*94dd93aeSGeorge Wilson  * Copyright (c) 2012 by Delphix. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _SYS_VMEM_H
277c478bd9Sstevel@tonic-gate #define	_SYS_VMEM_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
327c478bd9Sstevel@tonic-gate extern "C" {
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /*
377c478bd9Sstevel@tonic-gate  * Per-allocation flags
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate #define	VM_SLEEP	0x00000000	/* same as KM_SLEEP */
407c478bd9Sstevel@tonic-gate #define	VM_NOSLEEP	0x00000001	/* same as KM_NOSLEEP */
417c478bd9Sstevel@tonic-gate #define	VM_PANIC	0x00000002	/* same as KM_PANIC */
427c478bd9Sstevel@tonic-gate #define	VM_PUSHPAGE	0x00000004	/* same as KM_PUSHPAGE */
4323a80de1SStan Studzinski #define	VM_NORMALPRI	0x00000008	/* same as KM_NORMALPRI */
447c478bd9Sstevel@tonic-gate #define	VM_KMFLAGS	0x000000ff	/* flags that must match KM_* flags */
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #define	VM_BESTFIT	0x00000100
477c478bd9Sstevel@tonic-gate #define	VM_FIRSTFIT	0x00000200
487c478bd9Sstevel@tonic-gate #define	VM_NEXTFIT	0x00000400
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate /*
517c478bd9Sstevel@tonic-gate  * The following flags are restricted for use only within the kernel.
527c478bd9Sstevel@tonic-gate  * VM_MEMLOAD is for use by the HAT to avoid infinite recursion.
537c478bd9Sstevel@tonic-gate  * VM_NORELOC is used by the kernel when static VA->PA mappings are required.
547c478bd9Sstevel@tonic-gate  */
557c478bd9Sstevel@tonic-gate #define	VM_MEMLOAD	0x00000800
567c478bd9Sstevel@tonic-gate #define	VM_NORELOC	0x00001000
577c478bd9Sstevel@tonic-gate /*
587c478bd9Sstevel@tonic-gate  * VM_ABORT requests that vmem_alloc() *ignore* the VM_SLEEP/VM_NOSLEEP flags
597c478bd9Sstevel@tonic-gate  * and forgo reaping if the allocation or attempted import, fails.  This
607c478bd9Sstevel@tonic-gate  * flag is a segkmem-specific flag, and should not be used by anyone else.
617c478bd9Sstevel@tonic-gate  */
627c478bd9Sstevel@tonic-gate #define	VM_ABORT	0x00002000
637c478bd9Sstevel@tonic-gate 
640616c1c3SMichael Corcoran /*
650616c1c3SMichael Corcoran  * VM_ENDALLOC requests that large addresses be preferred in allocations.
660616c1c3SMichael Corcoran  * Has no effect if VM_NEXTFIT is active.
670616c1c3SMichael Corcoran  */
680616c1c3SMichael Corcoran #define	VM_ENDALLOC	0x00004000
690616c1c3SMichael Corcoran 
707c478bd9Sstevel@tonic-gate #define	VM_FLAGS	0x0000FFFF
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate  * Arena creation flags
747c478bd9Sstevel@tonic-gate  */
757c478bd9Sstevel@tonic-gate #define	VMC_POPULATOR	0x00010000
767c478bd9Sstevel@tonic-gate #define	VMC_NO_QCACHE	0x00020000	/* cannot use quantum caches */
777c478bd9Sstevel@tonic-gate #define	VMC_IDENTIFIER	0x00040000	/* not backed by memory */
789dd77bc8SDave Plauger #define	VMC_DUMPSAFE	0x00200000	/* can use alternate dump memory */
797c478bd9Sstevel@tonic-gate /*
807c478bd9Sstevel@tonic-gate  * internal use only;	the import function uses the vmem_ximport_t interface
81aaa10e67Sha  *			and may increase the request size if it so desires.
82aaa10e67Sha  *			VMC_XALIGN, for use with vmem_xcreate, specifies that
83aaa10e67Sha  *			the address returned by the import function will be
84aaa10e67Sha  *			aligned according to the alignment argument.
857c478bd9Sstevel@tonic-gate  */
867c478bd9Sstevel@tonic-gate #define	VMC_XALLOC	0x00080000
87aaa10e67Sha #define	VMC_XALIGN	0x00100000
887c478bd9Sstevel@tonic-gate #define	VMC_FLAGS	0xFFFF0000
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate /*
917c478bd9Sstevel@tonic-gate  * Public segment types
927c478bd9Sstevel@tonic-gate  */
937c478bd9Sstevel@tonic-gate #define	VMEM_ALLOC	0x01
947c478bd9Sstevel@tonic-gate #define	VMEM_FREE	0x02
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate  * Implementation-private segment types
987c478bd9Sstevel@tonic-gate  */
997c478bd9Sstevel@tonic-gate #define	VMEM_SPAN	0x10
1007c478bd9Sstevel@tonic-gate #define	VMEM_ROTOR	0x20
1017c478bd9Sstevel@tonic-gate #define	VMEM_WALKER	0x40
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate /*
1047c478bd9Sstevel@tonic-gate  * VMEM_REENTRANT indicates to vmem_walk() that the callback routine may
1057c478bd9Sstevel@tonic-gate  * call back into the arena being walked, so vmem_walk() must drop the
1067c478bd9Sstevel@tonic-gate  * arena lock before each callback.  The caveat is that since the arena
1077c478bd9Sstevel@tonic-gate  * isn't locked, its state can change.  Therefore it is up to the callback
1087c478bd9Sstevel@tonic-gate  * routine to handle cases where the segment isn't of the expected type.
1097c478bd9Sstevel@tonic-gate  * For example, we use this to walk heap_arena when generating a crash dump;
1107c478bd9Sstevel@tonic-gate  * see segkmem_dump() for sample usage.
1117c478bd9Sstevel@tonic-gate  */
1127c478bd9Sstevel@tonic-gate #define	VMEM_REENTRANT	0x80000000
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate typedef struct vmem vmem_t;
1157c478bd9Sstevel@tonic-gate typedef void *(vmem_alloc_t)(vmem_t *, size_t, int);
1167c478bd9Sstevel@tonic-gate typedef void (vmem_free_t)(vmem_t *, void *, size_t);
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate /*
1197c478bd9Sstevel@tonic-gate  * Alternate import style; the requested size is passed in a pointer,
1207c478bd9Sstevel@tonic-gate  * which can be increased by the import function if desired.
1217c478bd9Sstevel@tonic-gate  */
122aaa10e67Sha typedef void *(vmem_ximport_t)(vmem_t *, size_t *, size_t, int);
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1257c478bd9Sstevel@tonic-gate extern vmem_t *vmem_init(const char *, void *, size_t, size_t,
1267c478bd9Sstevel@tonic-gate     vmem_alloc_t *, vmem_free_t *);
1277c478bd9Sstevel@tonic-gate extern void vmem_update(void *);
1287c478bd9Sstevel@tonic-gate extern int vmem_is_populator();
1297c478bd9Sstevel@tonic-gate extern size_t vmem_seg_size;
1307c478bd9Sstevel@tonic-gate #endif
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate extern vmem_t *vmem_create(const char *, void *, size_t, size_t,
1337c478bd9Sstevel@tonic-gate     vmem_alloc_t *, vmem_free_t *, vmem_t *, size_t, int);
1347c478bd9Sstevel@tonic-gate extern vmem_t *vmem_xcreate(const char *, void *, size_t, size_t,
1357c478bd9Sstevel@tonic-gate     vmem_ximport_t *, vmem_free_t *, vmem_t *, size_t, int);
1367c478bd9Sstevel@tonic-gate extern void vmem_destroy(vmem_t *);
1377c478bd9Sstevel@tonic-gate extern void *vmem_alloc(vmem_t *, size_t, int);
1387c478bd9Sstevel@tonic-gate extern void *vmem_xalloc(vmem_t *, size_t, size_t, size_t, size_t,
1397c478bd9Sstevel@tonic-gate     void *, void *, int);
1407c478bd9Sstevel@tonic-gate extern void vmem_free(vmem_t *, void *, size_t);
1417c478bd9Sstevel@tonic-gate extern void vmem_xfree(vmem_t *, void *, size_t);
1427c478bd9Sstevel@tonic-gate extern void *vmem_add(vmem_t *, void *, size_t, int);
1437c478bd9Sstevel@tonic-gate extern int vmem_contains(vmem_t *, void *, size_t);
1447c478bd9Sstevel@tonic-gate extern void vmem_walk(vmem_t *, int, void (*)(void *, void *, size_t), void *);
1457c478bd9Sstevel@tonic-gate extern size_t vmem_size(vmem_t *, int);
146*94dd93aeSGeorge Wilson extern void vmem_qcache_reap(vmem_t *vmp);
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1497c478bd9Sstevel@tonic-gate }
1507c478bd9Sstevel@tonic-gate #endif
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate #endif	/* _SYS_VMEM_H */
153