xref: /titanic_51/usr/src/uts/common/vm/seg_kmem.h (revision 263f549e5da8b32c4922f586afb365b8ae388a6c)
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
51e2e7a75Shuah  * Common Development and Distribution License (the "License").
61e2e7a75Shuah  * 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 /*
22af4c679fSSean McEnroe  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
24*263f549eSPatrick Mooney  * Copyright 2016 Joyent, Inc.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _VM_SEG_KMEM_H
287c478bd9Sstevel@tonic-gate #define	_VM_SEG_KMEM_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
327c478bd9Sstevel@tonic-gate extern "C" {
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <sys/types.h>
367c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
377c478bd9Sstevel@tonic-gate #include <sys/vmem.h>
387c478bd9Sstevel@tonic-gate #include <vm/as.h>
397c478bd9Sstevel@tonic-gate #include <vm/seg.h>
407c478bd9Sstevel@tonic-gate #include <vm/page.h>
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate  * VM - Kernel Segment Driver
447c478bd9Sstevel@tonic-gate  */
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate extern char *kernelheap;	/* start of primary kernel heap */
497c478bd9Sstevel@tonic-gate extern char *ekernelheap;	/* end of primary kernel heap */
507c478bd9Sstevel@tonic-gate extern char *heap_lp_base;	/* start of kernel large page heap arena */
517c478bd9Sstevel@tonic-gate extern char *heap_lp_end;	/* end of kernel large page heap arena */
527c478bd9Sstevel@tonic-gate extern struct seg kvseg;	/* primary kernel heap segment */
537c478bd9Sstevel@tonic-gate extern struct seg kvseg_core;	/* "core" kernel heap segment */
54ad23a2dbSjohansen extern struct seg kzioseg;	/* Segment for zio mappings */
557bc98a2eSeg155566 extern vmem_t *heap_lp_arena;	/* kernel large page heap arena */
567c478bd9Sstevel@tonic-gate extern vmem_t *heap_arena;	/* primary kernel heap arena */
577c478bd9Sstevel@tonic-gate extern vmem_t *hat_memload_arena; /* HAT translation arena */
587c478bd9Sstevel@tonic-gate extern struct seg kvseg32;	/* 32-bit kernel heap segment */
597c478bd9Sstevel@tonic-gate extern vmem_t *heap32_arena;	/* 32-bit kernel heap arena */
607c478bd9Sstevel@tonic-gate extern vmem_t *heaptext_arena;	/* kernel text arena, from heap */
617c478bd9Sstevel@tonic-gate extern struct as kas;		/* kernel address space */
627c478bd9Sstevel@tonic-gate extern int segkmem_reloc;	/* enable/disable segkmem relocatable pages */
637c478bd9Sstevel@tonic-gate extern vmem_t *static_arena;	/* arena for caches to import static memory */
647c478bd9Sstevel@tonic-gate extern vmem_t *static_alloc_arena;	/* arena for allocating static memory */
65ad23a2dbSjohansen extern vmem_t *zio_arena;	/* arena for zio caches */
66ad23a2dbSjohansen extern vmem_t *zio_alloc_arena;	/* arena for zio caches */
67af4c679fSSean McEnroe extern struct vnode kvps[];
68af4c679fSSean McEnroe /*
69af4c679fSSean McEnroe  * segkmem page vnodes
70af4c679fSSean McEnroe  */
71af4c679fSSean McEnroe #define	kvp		(kvps[KV_KVP])
72af4c679fSSean McEnroe #define	zvp		(kvps[KV_ZVP])
73af4c679fSSean McEnroe #if defined(__sparc)
74af4c679fSSean McEnroe #define	mpvp		(kvps[KV_MPVP])
75af4c679fSSean McEnroe #define	promvp		(kvps[KV_PROMVP])
76af4c679fSSean McEnroe #endif	/* __sparc */
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate extern int segkmem_create(struct seg *);
797c478bd9Sstevel@tonic-gate extern page_t *segkmem_page_create(void *, size_t, int, void *);
807c478bd9Sstevel@tonic-gate extern void *segkmem_xalloc(vmem_t *, void *, size_t, int, uint_t,
817c478bd9Sstevel@tonic-gate 	page_t *(*page_create_func)(void *, size_t, int, void *), void *);
827c478bd9Sstevel@tonic-gate extern void *segkmem_alloc(vmem_t *, size_t, int);
837c478bd9Sstevel@tonic-gate extern void *segkmem_alloc_permanent(vmem_t *, size_t, int);
847c478bd9Sstevel@tonic-gate extern void segkmem_free(vmem_t *, void *, size_t);
85843e1988Sjohnlev extern void segkmem_xfree(vmem_t *, void *, size_t, void (*)(page_t *));
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate extern void *boot_alloc(void *, size_t, uint_t);
887c478bd9Sstevel@tonic-gate extern void boot_mapin(caddr_t addr, size_t size);
897c478bd9Sstevel@tonic-gate extern void kernelheap_init(void *, void *, char *, void *, void *);
907c478bd9Sstevel@tonic-gate extern void segkmem_gc(void);
917c478bd9Sstevel@tonic-gate 
92ad23a2dbSjohansen extern void *segkmem_zio_alloc(vmem_t *, size_t, int);
93ad23a2dbSjohansen extern int segkmem_zio_create(struct seg *);
94ad23a2dbSjohansen extern void segkmem_zio_free(vmem_t *, void *, size_t);
95ad23a2dbSjohansen extern void segkmem_zio_init(void *, size_t);
96ad23a2dbSjohansen 
977c478bd9Sstevel@tonic-gate /*
987c478bd9Sstevel@tonic-gate  * Flags for segkmem_xalloc().
997c478bd9Sstevel@tonic-gate  *
1007c478bd9Sstevel@tonic-gate  * SEGKMEM_SHARELOCKED requests pages which are locked SE_SHARED to be
1017c478bd9Sstevel@tonic-gate  * returned rather than unlocked which is now the default.  Note that
1027c478bd9Sstevel@tonic-gate  * memory returned by SEGKMEM_SHARELOCKED cannot be freed by segkmem_free().
1037c478bd9Sstevel@tonic-gate  * This is a hack for seg_dev that should be cleaned up in the future.
1047c478bd9Sstevel@tonic-gate  */
1057c478bd9Sstevel@tonic-gate #define	SEGKMEM_SHARELOCKED	0x20000
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate /*
1087c478bd9Sstevel@tonic-gate  * Large page for kmem caches support
1097c478bd9Sstevel@tonic-gate  */
1107c478bd9Sstevel@tonic-gate typedef struct segkmem_lpcb {
1117c478bd9Sstevel@tonic-gate 	kmutex_t	lp_lock;
1127c478bd9Sstevel@tonic-gate 	kcondvar_t	lp_cv;
1137c478bd9Sstevel@tonic-gate 	uint_t		lp_wait;
1147c478bd9Sstevel@tonic-gate 	uint_t		lp_uselp;
1157c478bd9Sstevel@tonic-gate 	ulong_t		lp_throttle;
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 	/* stats */
1187c478bd9Sstevel@tonic-gate 	uint64_t	sleep_allocs_failed;
1197c478bd9Sstevel@tonic-gate 	uint64_t	nosleep_allocs_failed;
1207c478bd9Sstevel@tonic-gate 	uint64_t	allocs_throttled;
1217c478bd9Sstevel@tonic-gate 	uint64_t	allocs_limited;
1227c478bd9Sstevel@tonic-gate 	uint64_t	alloc_bytes_failed;
1237c478bd9Sstevel@tonic-gate } segkmem_lpcb_t;
1247c478bd9Sstevel@tonic-gate 
125aaa10e67Sha137994 extern void	*segkmem_alloc_lp(vmem_t *, size_t *, size_t, int);
1267c478bd9Sstevel@tonic-gate extern void	segkmem_free_lp(vmem_t *, void *, size_t);
1277c478bd9Sstevel@tonic-gate extern int	segkmem_lpsetup();
1287c478bd9Sstevel@tonic-gate extern void	segkmem_heap_lp_init(void);
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate extern size_t	segkmem_lpsize;
131081a94b0Saguzovsk extern int	segkmem_lpszc;
1327c478bd9Sstevel@tonic-gate extern size_t	segkmem_heaplp_quantum;
1337c478bd9Sstevel@tonic-gate extern size_t	segkmem_kmemlp_max;
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate #define	SEGKMEM_USE_LARGEPAGES (segkmem_lpsize > PAGESIZE)
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate #define	IS_KMEM_VA_LARGEPAGE(vaddr)				        \
1387c478bd9Sstevel@tonic-gate 	(((vaddr) >= heap_lp_base) && ((vaddr) < heap_lp_end))
1397c478bd9Sstevel@tonic-gate 
140*263f549eSPatrick Mooney extern struct seg_ops segkmem_ops;
141*263f549eSPatrick Mooney 
1427c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1457c478bd9Sstevel@tonic-gate }
1467c478bd9Sstevel@tonic-gate #endif
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate #endif	/* _VM_SEG_KMEM_H */
149