xref: /illumos-gate/usr/src/uts/common/sys/kmem.h (revision 23a80de1aec78d238d06caf311eaceb81dd5a440)
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
5b5fca8f8Stomee  * Common Development and Distribution License (the "License").
6b5fca8f8Stomee  * 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  */
21b5fca8f8Stomee 
227c478bd9Sstevel@tonic-gate /*
23b942e89bSDavid Valin  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef _SYS_KMEM_H
307c478bd9Sstevel@tonic-gate #define	_SYS_KMEM_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/vmem.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
367c478bd9Sstevel@tonic-gate extern "C" {
377c478bd9Sstevel@tonic-gate #endif
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * Kernel memory allocator: DDI interfaces.
417c478bd9Sstevel@tonic-gate  * See kmem_alloc(9F) for details.
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #define	KM_SLEEP	0x0000	/* can block for memory; success guaranteed */
457c478bd9Sstevel@tonic-gate #define	KM_NOSLEEP	0x0001	/* cannot block for memory; may fail */
467c478bd9Sstevel@tonic-gate #define	KM_PANIC	0x0002	/* if memory cannot be allocated, panic */
477c478bd9Sstevel@tonic-gate #define	KM_PUSHPAGE	0x0004	/* can block for memory; may use reserve */
48*23a80de1SStan Studzinski #define	KM_NORMALPRI	0x0008  /* with KM_NOSLEEP, lower priority allocation */
497c478bd9Sstevel@tonic-gate #define	KM_VMFLAGS	0x00ff	/* flags that must match VM_* flags */
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate #define	KM_FLAGS	0xffff	/* all settable kmem flags */
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate #ifdef _KERNEL
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate extern void *kmem_alloc(size_t size, int kmflags);
567c478bd9Sstevel@tonic-gate extern void *kmem_zalloc(size_t size, int kmflags);
577c478bd9Sstevel@tonic-gate extern void kmem_free(void *buf, size_t size);
587c478bd9Sstevel@tonic-gate extern void *kmem_alloc_tryhard(size_t size, size_t *alloc_size, int kmflags);
599dd77bc8SDave Plauger extern void kmem_dump_init(size_t);
609dd77bc8SDave Plauger extern void kmem_dump_begin(void);
619dd77bc8SDave Plauger extern size_t kmem_dump_finish(char *buf, size_t size);
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate /*
667c478bd9Sstevel@tonic-gate  * Kernel memory allocator: private interfaces.
677c478bd9Sstevel@tonic-gate  * These interfaces are still evolving.
687c478bd9Sstevel@tonic-gate  * Do not use them in unbundled drivers.
697c478bd9Sstevel@tonic-gate  */
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate  * Flags for kmem_cache_create()
737c478bd9Sstevel@tonic-gate  */
747c478bd9Sstevel@tonic-gate #define	KMC_NOTOUCH	0x00010000
757c478bd9Sstevel@tonic-gate #define	KMC_NODEBUG	0x00020000
767c478bd9Sstevel@tonic-gate #define	KMC_NOMAGAZINE	0x00040000
777c478bd9Sstevel@tonic-gate #define	KMC_NOHASH	0x00080000
787c478bd9Sstevel@tonic-gate #define	KMC_QCACHE	0x00100000
797c478bd9Sstevel@tonic-gate #define	KMC_KMEM_ALLOC	0x00200000	/* internal use only */
807c478bd9Sstevel@tonic-gate #define	KMC_IDENTIFIER	0x00400000	/* internal use only */
81b942e89bSDavid Valin #define	KMC_PREFILL	0x00800000
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate struct kmem_cache;		/* cache structure is opaque to kmem clients */
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate typedef struct kmem_cache kmem_cache_t;
867c478bd9Sstevel@tonic-gate 
87b5fca8f8Stomee /* Client response to kmem move callback */
88b5fca8f8Stomee typedef enum kmem_cbrc {
89b5fca8f8Stomee 	KMEM_CBRC_YES,
90b5fca8f8Stomee 	KMEM_CBRC_NO,
91b5fca8f8Stomee 	KMEM_CBRC_LATER,
92b5fca8f8Stomee 	KMEM_CBRC_DONT_NEED,
93b5fca8f8Stomee 	KMEM_CBRC_DONT_KNOW
94b5fca8f8Stomee } kmem_cbrc_t;
95b5fca8f8Stomee 
967c478bd9Sstevel@tonic-gate #ifdef _KERNEL
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate extern int kmem_ready;
997c478bd9Sstevel@tonic-gate extern pgcnt_t kmem_reapahead;
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate extern void kmem_init(void);
1027c478bd9Sstevel@tonic-gate extern void kmem_thread_init(void);
1037c478bd9Sstevel@tonic-gate extern void kmem_mp_init(void);
1047c478bd9Sstevel@tonic-gate extern void kmem_reap(void);
1057c478bd9Sstevel@tonic-gate extern void kmem_reap_idspace(void);
106fa9e4066Sahrens extern int kmem_debugging(void);
1077c478bd9Sstevel@tonic-gate extern size_t kmem_avail(void);
1087c478bd9Sstevel@tonic-gate extern size_t kmem_maxavail(void);
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate extern kmem_cache_t *kmem_cache_create(char *, size_t, size_t,
1117c478bd9Sstevel@tonic-gate 	int (*)(void *, void *, int), void (*)(void *, void *),
1127c478bd9Sstevel@tonic-gate 	void (*)(void *), void *, vmem_t *, int);
113b5fca8f8Stomee extern void kmem_cache_set_move(kmem_cache_t *,
114b5fca8f8Stomee 	kmem_cbrc_t (*)(void *, void *, size_t, void *));
1157c478bd9Sstevel@tonic-gate extern void kmem_cache_destroy(kmem_cache_t *);
1167c478bd9Sstevel@tonic-gate extern void *kmem_cache_alloc(kmem_cache_t *, int);
1177c478bd9Sstevel@tonic-gate extern void kmem_cache_free(kmem_cache_t *, void *);
1187c478bd9Sstevel@tonic-gate extern uint64_t kmem_cache_stat(kmem_cache_t *, char *);
119fa9e4066Sahrens extern void kmem_cache_reap_now(kmem_cache_t *);
120b5fca8f8Stomee extern void kmem_cache_move_notify(kmem_cache_t *, void *);
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1257c478bd9Sstevel@tonic-gate }
1267c478bd9Sstevel@tonic-gate #endif
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate #endif	/* _SYS_KMEM_H */
129