xref: /illumos-gate/usr/src/uts/common/vm/seg_kmem.h (revision 04909c8c)
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*04909c8cSJohn Levon  * Copyright 2018 Joyent, Inc.
25f06dce2cSAndrew Stormont  * Copyright 2017 RackTop Systems.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #ifndef _VM_SEG_KMEM_H
297c478bd9Sstevel@tonic-gate #define	_VM_SEG_KMEM_H
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <sys/types.h>
377c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
387c478bd9Sstevel@tonic-gate #include <sys/vmem.h>
397c478bd9Sstevel@tonic-gate #include <vm/as.h>
407c478bd9Sstevel@tonic-gate #include <vm/seg.h>
417c478bd9Sstevel@tonic-gate #include <vm/page.h>
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * VM - Kernel Segment Driver
457c478bd9Sstevel@tonic-gate  */
467c478bd9Sstevel@tonic-gate 
47f06dce2cSAndrew Stormont #if defined(_KERNEL) || defined(_FAKE_KERNEL)
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate extern char *kernelheap;	/* start of primary kernel heap */
507c478bd9Sstevel@tonic-gate extern char *ekernelheap;	/* end of primary kernel heap */
517c478bd9Sstevel@tonic-gate extern char *heap_lp_base;	/* start of kernel large page heap arena */
527c478bd9Sstevel@tonic-gate extern char *heap_lp_end;	/* end of kernel large page heap arena */
537c478bd9Sstevel@tonic-gate extern struct seg kvseg;	/* primary kernel heap segment */
547c478bd9Sstevel@tonic-gate extern struct seg kvseg_core;	/* "core" kernel heap segment */
55ad23a2dbSjohansen extern struct seg kzioseg;	/* Segment for zio mappings */
567bc98a2eSeg extern vmem_t *heap_lp_arena;	/* kernel large page heap arena */
577c478bd9Sstevel@tonic-gate extern vmem_t *heap_arena;	/* primary kernel heap arena */
587c478bd9Sstevel@tonic-gate extern vmem_t *hat_memload_arena; /* HAT translation arena */
597c478bd9Sstevel@tonic-gate extern struct seg kvseg32;	/* 32-bit kernel heap segment */
607c478bd9Sstevel@tonic-gate extern vmem_t *heap32_arena;	/* 32-bit kernel heap arena */
617c478bd9Sstevel@tonic-gate extern vmem_t *heaptext_arena;	/* kernel text arena, from heap */
627c478bd9Sstevel@tonic-gate extern struct as kas;		/* kernel address space */
637c478bd9Sstevel@tonic-gate extern int segkmem_reloc;	/* enable/disable segkmem relocatable pages */
647c478bd9Sstevel@tonic-gate extern vmem_t *static_arena;	/* arena for caches to import static memory */
657c478bd9Sstevel@tonic-gate extern vmem_t *static_alloc_arena;	/* arena for allocating static memory */
66ad23a2dbSjohansen extern vmem_t *zio_arena;	/* arena for zio caches */
67ad23a2dbSjohansen extern vmem_t *zio_alloc_arena;	/* arena for zio caches */
68*04909c8cSJohn Levon 
69*04909c8cSJohn Levon #if defined(__amd64)
70*04909c8cSJohn Levon extern struct seg kvmmseg;	/* Segment for vmm mappings */
71*04909c8cSJohn Levon extern vmem_t *kvmm_arena;	/* arena for vmm VA */
72*04909c8cSJohn Levon extern void segkmem_kvmm_init(void *, size_t);
73*04909c8cSJohn Levon #endif
74*04909c8cSJohn Levon 
75af4c679fSSean McEnroe extern struct vnode kvps[];
76af4c679fSSean McEnroe /*
77*04909c8cSJohn Levon  * segkmem page vnodes (please don't add more defines here...)
78af4c679fSSean McEnroe  */
79af4c679fSSean McEnroe #define	kvp		(kvps[KV_KVP])
80af4c679fSSean McEnroe #if defined(__sparc)
81af4c679fSSean McEnroe #define	mpvp		(kvps[KV_MPVP])
82af4c679fSSean McEnroe #define	promvp		(kvps[KV_PROMVP])
83af4c679fSSean McEnroe #endif	/* __sparc */
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate extern int segkmem_create(struct seg *);
867c478bd9Sstevel@tonic-gate extern page_t *segkmem_page_create(void *, size_t, int, void *);
877c478bd9Sstevel@tonic-gate extern void *segkmem_xalloc(vmem_t *, void *, size_t, int, uint_t,
887c478bd9Sstevel@tonic-gate 	page_t *(*page_create_func)(void *, size_t, int, void *), void *);
897c478bd9Sstevel@tonic-gate extern void *segkmem_alloc(vmem_t *, size_t, int);
907c478bd9Sstevel@tonic-gate extern void *segkmem_alloc_permanent(vmem_t *, size_t, int);
917c478bd9Sstevel@tonic-gate extern void segkmem_free(vmem_t *, void *, size_t);
92*04909c8cSJohn Levon extern void segkmem_xfree(vmem_t *, void *, size_t,
93*04909c8cSJohn Levon     struct vnode *, void (*)(page_t *));
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate extern void *boot_alloc(void *, size_t, uint_t);
967c478bd9Sstevel@tonic-gate extern void boot_mapin(caddr_t addr, size_t size);
977c478bd9Sstevel@tonic-gate extern void kernelheap_init(void *, void *, char *, void *, void *);
987c478bd9Sstevel@tonic-gate extern void segkmem_gc(void);
997c478bd9Sstevel@tonic-gate 
100ad23a2dbSjohansen extern void segkmem_zio_init(void *, size_t);
101ad23a2dbSjohansen 
1027c478bd9Sstevel@tonic-gate /*
1037c478bd9Sstevel@tonic-gate  * Flags for segkmem_xalloc().
1047c478bd9Sstevel@tonic-gate  *
1057c478bd9Sstevel@tonic-gate  * SEGKMEM_SHARELOCKED requests pages which are locked SE_SHARED to be
1067c478bd9Sstevel@tonic-gate  * returned rather than unlocked which is now the default.  Note that
1077c478bd9Sstevel@tonic-gate  * memory returned by SEGKMEM_SHARELOCKED cannot be freed by segkmem_free().
1087c478bd9Sstevel@tonic-gate  * This is a hack for seg_dev that should be cleaned up in the future.
1097c478bd9Sstevel@tonic-gate  */
1107c478bd9Sstevel@tonic-gate #define	SEGKMEM_SHARELOCKED	0x20000
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate /*
1137c478bd9Sstevel@tonic-gate  * Large page for kmem caches support
1147c478bd9Sstevel@tonic-gate  */
1157c478bd9Sstevel@tonic-gate typedef struct segkmem_lpcb {
1167c478bd9Sstevel@tonic-gate 	kmutex_t	lp_lock;
1177c478bd9Sstevel@tonic-gate 	kcondvar_t	lp_cv;
1187c478bd9Sstevel@tonic-gate 	uint_t		lp_wait;
1197c478bd9Sstevel@tonic-gate 	uint_t		lp_uselp;
1207c478bd9Sstevel@tonic-gate 	ulong_t		lp_throttle;
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 	/* stats */
1237c478bd9Sstevel@tonic-gate 	uint64_t	sleep_allocs_failed;
1247c478bd9Sstevel@tonic-gate 	uint64_t	nosleep_allocs_failed;
1257c478bd9Sstevel@tonic-gate 	uint64_t	allocs_throttled;
1267c478bd9Sstevel@tonic-gate 	uint64_t	allocs_limited;
1277c478bd9Sstevel@tonic-gate 	uint64_t	alloc_bytes_failed;
1287c478bd9Sstevel@tonic-gate } segkmem_lpcb_t;
1297c478bd9Sstevel@tonic-gate 
130aaa10e67Sha extern void	*segkmem_alloc_lp(vmem_t *, size_t *, size_t, int);
1317c478bd9Sstevel@tonic-gate extern void	segkmem_free_lp(vmem_t *, void *, size_t);
1327c478bd9Sstevel@tonic-gate extern int	segkmem_lpsetup();
1337c478bd9Sstevel@tonic-gate extern void	segkmem_heap_lp_init(void);
1347c478bd9Sstevel@tonic-gate 
135081a94b0Saguzovsk extern size_t	segkmem_lpsize;
136081a94b0Saguzovsk extern int	segkmem_lpszc;
137081a94b0Saguzovsk extern size_t	segkmem_heaplp_quantum;
138081a94b0Saguzovsk extern size_t	segkmem_kmemlp_max;
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate #define	SEGKMEM_USE_LARGEPAGES (segkmem_lpsize > PAGESIZE)
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate #define	IS_KMEM_VA_LARGEPAGE(vaddr)				        \
1437c478bd9Sstevel@tonic-gate 	(((vaddr) >= heap_lp_base) && ((vaddr) < heap_lp_end))
1447c478bd9Sstevel@tonic-gate 
1452428aad8SPatrick Mooney extern struct seg_ops segkmem_ops;
1462428aad8SPatrick Mooney 
147f06dce2cSAndrew Stormont #endif	/* _KERNEL || _FAKE_KERNEL */
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1507c478bd9Sstevel@tonic-gate }
1517c478bd9Sstevel@tonic-gate #endif
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate #endif	/* _VM_SEG_KMEM_H */
154