10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 52241Shuah * Common Development and Distribution License (the "License"). 62241Shuah * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 222241Shuah * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _VM_SEG_KMEM_H 270Sstevel@tonic-gate #define _VM_SEG_KMEM_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate #ifdef __cplusplus 320Sstevel@tonic-gate extern "C" { 330Sstevel@tonic-gate #endif 340Sstevel@tonic-gate 350Sstevel@tonic-gate #include <sys/types.h> 360Sstevel@tonic-gate #include <sys/vnode.h> 370Sstevel@tonic-gate #include <sys/vmem.h> 380Sstevel@tonic-gate #include <vm/as.h> 390Sstevel@tonic-gate #include <vm/seg.h> 400Sstevel@tonic-gate #include <vm/page.h> 410Sstevel@tonic-gate 420Sstevel@tonic-gate /* 430Sstevel@tonic-gate * VM - Kernel Segment Driver 440Sstevel@tonic-gate */ 450Sstevel@tonic-gate 460Sstevel@tonic-gate #if defined(_KERNEL) 470Sstevel@tonic-gate 480Sstevel@tonic-gate extern char *kernelheap; /* start of primary kernel heap */ 490Sstevel@tonic-gate extern char *ekernelheap; /* end of primary kernel heap */ 500Sstevel@tonic-gate extern char *heap_lp_base; /* start of kernel large page heap arena */ 510Sstevel@tonic-gate extern char *heap_lp_end; /* end of kernel large page heap arena */ 520Sstevel@tonic-gate extern struct seg kvseg; /* primary kernel heap segment */ 530Sstevel@tonic-gate extern struct seg kvseg_core; /* "core" kernel heap segment */ 54*3290Sjohansen extern struct seg kzioseg; /* Segment for zio mappings */ 555Seg155566 extern vmem_t *heap_lp_arena; /* kernel large page heap arena */ 560Sstevel@tonic-gate extern vmem_t *heap_arena; /* primary kernel heap arena */ 570Sstevel@tonic-gate extern vmem_t *hat_memload_arena; /* HAT translation arena */ 580Sstevel@tonic-gate extern struct seg kvseg32; /* 32-bit kernel heap segment */ 590Sstevel@tonic-gate extern vmem_t *heap32_arena; /* 32-bit kernel heap arena */ 600Sstevel@tonic-gate extern vmem_t *heaptext_arena; /* kernel text arena, from heap */ 610Sstevel@tonic-gate extern struct as kas; /* kernel address space */ 620Sstevel@tonic-gate extern struct vnode kvp; /* vnode for all segkmem pages */ 63*3290Sjohansen extern struct vnode zvp; /* vnode for all segkmem pages for zfs */ 640Sstevel@tonic-gate extern int segkmem_reloc; /* enable/disable segkmem relocatable pages */ 650Sstevel@tonic-gate extern vmem_t *static_arena; /* arena for caches to import static memory */ 660Sstevel@tonic-gate extern vmem_t *static_alloc_arena; /* arena for allocating static memory */ 67*3290Sjohansen extern vmem_t *zio_arena; /* arena for zio caches */ 68*3290Sjohansen extern vmem_t *zio_alloc_arena; /* arena for zio caches */ 690Sstevel@tonic-gate 700Sstevel@tonic-gate extern int segkmem_create(struct seg *); 710Sstevel@tonic-gate extern page_t *segkmem_page_create(void *, size_t, int, void *); 720Sstevel@tonic-gate extern void *segkmem_xalloc(vmem_t *, void *, size_t, int, uint_t, 730Sstevel@tonic-gate page_t *(*page_create_func)(void *, size_t, int, void *), void *); 740Sstevel@tonic-gate extern void *segkmem_alloc(vmem_t *, size_t, int); 750Sstevel@tonic-gate extern void *segkmem_alloc_permanent(vmem_t *, size_t, int); 760Sstevel@tonic-gate extern void segkmem_free(vmem_t *, void *, size_t); 770Sstevel@tonic-gate 780Sstevel@tonic-gate extern void *boot_alloc(void *, size_t, uint_t); 790Sstevel@tonic-gate extern void boot_mapin(caddr_t addr, size_t size); 800Sstevel@tonic-gate extern void kernelheap_init(void *, void *, char *, void *, void *); 810Sstevel@tonic-gate extern void kernelheap_extend(void *, void *); 820Sstevel@tonic-gate extern void segkmem_gc(void); 830Sstevel@tonic-gate 84*3290Sjohansen extern void *segkmem_zio_alloc(vmem_t *, size_t, int); 85*3290Sjohansen extern int segkmem_zio_create(struct seg *); 86*3290Sjohansen extern void segkmem_zio_free(vmem_t *, void *, size_t); 87*3290Sjohansen extern void segkmem_zio_init(void *, size_t); 88*3290Sjohansen 890Sstevel@tonic-gate /* 900Sstevel@tonic-gate * Flags for segkmem_xalloc(). 910Sstevel@tonic-gate * 920Sstevel@tonic-gate * SEGKMEM_SHARELOCKED requests pages which are locked SE_SHARED to be 930Sstevel@tonic-gate * returned rather than unlocked which is now the default. Note that 940Sstevel@tonic-gate * memory returned by SEGKMEM_SHARELOCKED cannot be freed by segkmem_free(). 950Sstevel@tonic-gate * This is a hack for seg_dev that should be cleaned up in the future. 960Sstevel@tonic-gate */ 970Sstevel@tonic-gate #define SEGKMEM_SHARELOCKED 0x20000 980Sstevel@tonic-gate 990Sstevel@tonic-gate /* 1000Sstevel@tonic-gate * Large page for kmem caches support 1010Sstevel@tonic-gate */ 1020Sstevel@tonic-gate typedef struct segkmem_lpcb { 1030Sstevel@tonic-gate kmutex_t lp_lock; 1040Sstevel@tonic-gate kcondvar_t lp_cv; 1050Sstevel@tonic-gate uint_t lp_wait; 1060Sstevel@tonic-gate uint_t lp_uselp; 1070Sstevel@tonic-gate ulong_t lp_throttle; 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate /* stats */ 1100Sstevel@tonic-gate uint64_t sleep_allocs_failed; 1110Sstevel@tonic-gate uint64_t nosleep_allocs_failed; 1120Sstevel@tonic-gate uint64_t allocs_throttled; 1130Sstevel@tonic-gate uint64_t allocs_limited; 1140Sstevel@tonic-gate uint64_t alloc_bytes_failed; 1150Sstevel@tonic-gate } segkmem_lpcb_t; 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate extern void *segkmem_alloc_lp(vmem_t *, size_t *, int); 1180Sstevel@tonic-gate extern void segkmem_free_lp(vmem_t *, void *, size_t); 1190Sstevel@tonic-gate extern int segkmem_lpsetup(); 1200Sstevel@tonic-gate extern void segkmem_heap_lp_init(void); 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate extern size_t segkmem_lpsize; 1230Sstevel@tonic-gate extern size_t segkmem_heaplp_quantum; 1240Sstevel@tonic-gate extern size_t segkmem_kmemlp_max; 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate #define SEGKMEM_USE_LARGEPAGES (segkmem_lpsize > PAGESIZE) 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate #define IS_KMEM_VA_LARGEPAGE(vaddr) \ 1290Sstevel@tonic-gate (((vaddr) >= heap_lp_base) && ((vaddr) < heap_lp_end)) 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate #endif /* _KERNEL */ 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate #ifdef __cplusplus 1340Sstevel@tonic-gate } 1350Sstevel@tonic-gate #endif 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate #endif /* _VM_SEG_KMEM_H */ 138