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