xref: /titanic_41/usr/src/uts/common/vm/seg_kmem.h (revision 3fb517f786391b507780c78aabb8d98bfea9efe9)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _VM_SEG_KMEM_H
27 #define	_VM_SEG_KMEM_H
28 
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #include <sys/types.h>
35 #include <sys/vnode.h>
36 #include <sys/vmem.h>
37 #include <vm/as.h>
38 #include <vm/seg.h>
39 #include <vm/page.h>
40 
41 /*
42  * VM - Kernel Segment Driver
43  */
44 
45 #if defined(_KERNEL)
46 
47 extern char *kernelheap;	/* start of primary kernel heap */
48 extern char *ekernelheap;	/* end of primary kernel heap */
49 extern char *heap_lp_base;	/* start of kernel large page heap arena */
50 extern char *heap_lp_end;	/* end of kernel large page heap arena */
51 extern struct seg kvseg;	/* primary kernel heap segment */
52 extern struct seg kvseg_core;	/* "core" kernel heap segment */
53 extern struct seg kzioseg;	/* Segment for zio mappings */
54 extern vmem_t *heap_lp_arena;	/* kernel large page heap arena */
55 extern vmem_t *heap_arena;	/* primary kernel heap arena */
56 extern vmem_t *hat_memload_arena; /* HAT translation arena */
57 extern struct seg kvseg32;	/* 32-bit kernel heap segment */
58 extern vmem_t *heap32_arena;	/* 32-bit kernel heap arena */
59 extern vmem_t *heaptext_arena;	/* kernel text arena, from heap */
60 extern struct as kas;		/* kernel address space */
61 extern int segkmem_reloc;	/* enable/disable segkmem relocatable pages */
62 extern vmem_t *static_arena;	/* arena for caches to import static memory */
63 extern vmem_t *static_alloc_arena;	/* arena for allocating static memory */
64 extern vmem_t *zio_arena;	/* arena for zio caches */
65 extern vmem_t *zio_alloc_arena;	/* arena for zio caches */
66 extern struct vnode kvps[];
67 /*
68  * segkmem page vnodes
69  */
70 #define	kvp		(kvps[KV_KVP])
71 #define	zvp		(kvps[KV_ZVP])
72 #if defined(__sparc)
73 #define	mpvp		(kvps[KV_MPVP])
74 #define	promvp		(kvps[KV_PROMVP])
75 #endif	/* __sparc */
76 
77 extern int segkmem_create(struct seg *);
78 extern page_t *segkmem_page_create(void *, size_t, int, void *);
79 extern void *segkmem_xalloc(vmem_t *, void *, size_t, int, uint_t,
80 	page_t *(*page_create_func)(void *, size_t, int, void *), void *);
81 extern void *segkmem_alloc(vmem_t *, size_t, int);
82 extern void *segkmem_alloc_permanent(vmem_t *, size_t, int);
83 extern void segkmem_free(vmem_t *, void *, size_t);
84 extern void segkmem_xfree(vmem_t *, void *, size_t, void (*)(page_t *));
85 
86 extern void *boot_alloc(void *, size_t, uint_t);
87 extern void boot_mapin(caddr_t addr, size_t size);
88 extern void kernelheap_init(void *, void *, char *, void *, void *);
89 extern void segkmem_gc(void);
90 
91 extern void *segkmem_zio_alloc(vmem_t *, size_t, int);
92 extern int segkmem_zio_create(struct seg *);
93 extern void segkmem_zio_free(vmem_t *, void *, size_t);
94 extern void segkmem_zio_init(void *, size_t);
95 
96 /*
97  * Flags for segkmem_xalloc().
98  *
99  * SEGKMEM_SHARELOCKED requests pages which are locked SE_SHARED to be
100  * returned rather than unlocked which is now the default.  Note that
101  * memory returned by SEGKMEM_SHARELOCKED cannot be freed by segkmem_free().
102  * This is a hack for seg_dev that should be cleaned up in the future.
103  */
104 #define	SEGKMEM_SHARELOCKED	0x20000
105 
106 /*
107  * Large page for kmem caches support
108  */
109 typedef struct segkmem_lpcb {
110 	kmutex_t	lp_lock;
111 	kcondvar_t	lp_cv;
112 	uint_t		lp_wait;
113 	uint_t		lp_uselp;
114 	ulong_t		lp_throttle;
115 
116 	/* stats */
117 	uint64_t	sleep_allocs_failed;
118 	uint64_t	nosleep_allocs_failed;
119 	uint64_t	allocs_throttled;
120 	uint64_t	allocs_limited;
121 	uint64_t	alloc_bytes_failed;
122 } segkmem_lpcb_t;
123 
124 extern void	*segkmem_alloc_lp(vmem_t *, size_t *, size_t, int);
125 extern void	segkmem_free_lp(vmem_t *, void *, size_t);
126 extern int	segkmem_lpsetup();
127 extern void	segkmem_heap_lp_init(void);
128 
129 extern size_t	segkmem_lpsize;
130 extern int	segkmem_lpszc;
131 extern size_t	segkmem_heaplp_quantum;
132 extern size_t	segkmem_kmemlp_max;
133 
134 #define	SEGKMEM_USE_LARGEPAGES (segkmem_lpsize > PAGESIZE)
135 
136 #define	IS_KMEM_VA_LARGEPAGE(vaddr)				        \
137 	(((vaddr) >= heap_lp_base) && ((vaddr) < heap_lp_end))
138 
139 #endif	/* _KERNEL */
140 
141 #ifdef	__cplusplus
142 }
143 #endif
144 
145 #endif	/* _VM_SEG_KMEM_H */
146