xref: /titanic_41/usr/src/uts/common/sys/kmem.h (revision f29fbe76ce646ba8bcf62627d89087d5f02c62a8)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /*	  All Rights Reserved	*/
29 
30 #ifndef _SYS_KMEM_H
31 #define	_SYS_KMEM_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 #include <sys/types.h>
36 #include <sys/vmem.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * Kernel memory allocator: DDI interfaces.
44  * See kmem_alloc(9F) for details.
45  */
46 
47 #define	KM_SLEEP	0x0000	/* can block for memory; success guaranteed */
48 #define	KM_NOSLEEP	0x0001	/* cannot block for memory; may fail */
49 #define	KM_PANIC	0x0002	/* if memory cannot be allocated, panic */
50 #define	KM_PUSHPAGE	0x0004	/* can block for memory; may use reserve */
51 #define	KM_VMFLAGS	0x00ff	/* flags that must match VM_* flags */
52 
53 #define	KM_FLAGS	0xffff	/* all settable kmem flags */
54 
55 #ifdef _KERNEL
56 
57 extern void *kmem_alloc(size_t size, int kmflags);
58 extern void *kmem_zalloc(size_t size, int kmflags);
59 extern void kmem_free(void *buf, size_t size);
60 extern void *kmem_alloc_tryhard(size_t size, size_t *alloc_size, int kmflags);
61 
62 #endif	/* _KERNEL */
63 
64 /*
65  * Kernel memory allocator: private interfaces.
66  * These interfaces are still evolving.
67  * Do not use them in unbundled drivers.
68  */
69 
70 /*
71  * Flags for kmem_cache_create()
72  */
73 #define	KMC_NOTOUCH	0x00010000
74 #define	KMC_NODEBUG	0x00020000
75 #define	KMC_NOMAGAZINE	0x00040000
76 #define	KMC_NOHASH	0x00080000
77 #define	KMC_QCACHE	0x00100000
78 #define	KMC_KMEM_ALLOC	0x00200000	/* internal use only */
79 #define	KMC_IDENTIFIER	0x00400000	/* internal use only */
80 
81 struct kmem_cache;		/* cache structure is opaque to kmem clients */
82 
83 typedef struct kmem_cache kmem_cache_t;
84 
85 #ifdef _KERNEL
86 
87 extern int kmem_ready;
88 extern pgcnt_t kmem_reapahead;
89 
90 extern void kmem_init(void);
91 extern void kmem_thread_init(void);
92 extern void kmem_mp_init(void);
93 extern void kmem_reap(void);
94 extern void kmem_reap_idspace(void);
95 extern int kmem_debugging(void);
96 extern size_t kmem_avail(void);
97 extern size_t kmem_maxavail(void);
98 
99 extern kmem_cache_t *kmem_cache_create(char *, size_t, size_t,
100 	int (*)(void *, void *, int), void (*)(void *, void *),
101 	void (*)(void *), void *, vmem_t *, int);
102 extern void kmem_cache_destroy(kmem_cache_t *);
103 extern void *kmem_cache_alloc(kmem_cache_t *, int);
104 extern void kmem_cache_free(kmem_cache_t *, void *);
105 extern uint64_t kmem_cache_stat(kmem_cache_t *, char *);
106 extern void kmem_cache_reap_now(kmem_cache_t *);
107 
108 #endif	/* _KERNEL */
109 
110 #ifdef	__cplusplus
111 }
112 #endif
113 
114 #endif	/* _SYS_KMEM_H */
115