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 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _VM_SEG_KMEM_H 280Sstevel@tonic-gate #define _VM_SEG_KMEM_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate #ifdef __cplusplus 330Sstevel@tonic-gate extern "C" { 340Sstevel@tonic-gate #endif 350Sstevel@tonic-gate 360Sstevel@tonic-gate #include <sys/types.h> 370Sstevel@tonic-gate #include <sys/vnode.h> 380Sstevel@tonic-gate #include <sys/vmem.h> 390Sstevel@tonic-gate #include <vm/as.h> 400Sstevel@tonic-gate #include <vm/seg.h> 410Sstevel@tonic-gate #include <vm/page.h> 420Sstevel@tonic-gate 430Sstevel@tonic-gate /* 440Sstevel@tonic-gate * VM - Kernel Segment Driver 450Sstevel@tonic-gate */ 460Sstevel@tonic-gate 470Sstevel@tonic-gate #if defined(_KERNEL) 480Sstevel@tonic-gate 490Sstevel@tonic-gate extern char *kernelheap; /* start of primary kernel heap */ 500Sstevel@tonic-gate extern char *ekernelheap; /* end of primary kernel heap */ 510Sstevel@tonic-gate extern char *heap_lp_base; /* start of kernel large page heap arena */ 520Sstevel@tonic-gate extern char *heap_lp_end; /* end of kernel large page heap arena */ 530Sstevel@tonic-gate extern struct seg kvseg; /* primary kernel heap segment */ 540Sstevel@tonic-gate extern struct seg kvseg_core; /* "core" kernel heap segment */ 55*5Seg155566 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 ctx *kctx; /* kernel context */ 620Sstevel@tonic-gate extern struct as kas; /* kernel address space */ 630Sstevel@tonic-gate extern struct vnode kvp; /* vnode for all segkmem pages */ 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 */ 670Sstevel@tonic-gate 680Sstevel@tonic-gate extern int segkmem_create(struct seg *); 690Sstevel@tonic-gate extern page_t *segkmem_page_create(void *, size_t, int, void *); 700Sstevel@tonic-gate extern void *segkmem_xalloc(vmem_t *, void *, size_t, int, uint_t, 710Sstevel@tonic-gate page_t *(*page_create_func)(void *, size_t, int, void *), void *); 720Sstevel@tonic-gate extern void *segkmem_alloc(vmem_t *, size_t, int); 730Sstevel@tonic-gate extern void *segkmem_alloc_permanent(vmem_t *, size_t, int); 740Sstevel@tonic-gate extern void segkmem_free(vmem_t *, void *, size_t); 750Sstevel@tonic-gate 760Sstevel@tonic-gate extern void *boot_alloc(void *, size_t, uint_t); 770Sstevel@tonic-gate extern void boot_mapin(caddr_t addr, size_t size); 780Sstevel@tonic-gate extern void kernelheap_init(void *, void *, char *, void *, void *); 790Sstevel@tonic-gate extern void kernelheap_extend(void *, void *); 800Sstevel@tonic-gate extern void segkmem_gc(void); 810Sstevel@tonic-gate 820Sstevel@tonic-gate /* 830Sstevel@tonic-gate * Flags for segkmem_xalloc(). 840Sstevel@tonic-gate * 850Sstevel@tonic-gate * SEGKMEM_SHARELOCKED requests pages which are locked SE_SHARED to be 860Sstevel@tonic-gate * returned rather than unlocked which is now the default. Note that 870Sstevel@tonic-gate * memory returned by SEGKMEM_SHARELOCKED cannot be freed by segkmem_free(). 880Sstevel@tonic-gate * This is a hack for seg_dev that should be cleaned up in the future. 890Sstevel@tonic-gate */ 900Sstevel@tonic-gate #define SEGKMEM_SHARELOCKED 0x20000 910Sstevel@tonic-gate 920Sstevel@tonic-gate /* 930Sstevel@tonic-gate * Large page for kmem caches support 940Sstevel@tonic-gate */ 950Sstevel@tonic-gate typedef struct segkmem_lpcb { 960Sstevel@tonic-gate kmutex_t lp_lock; 970Sstevel@tonic-gate kcondvar_t lp_cv; 980Sstevel@tonic-gate uint_t lp_wait; 990Sstevel@tonic-gate uint_t lp_uselp; 1000Sstevel@tonic-gate ulong_t lp_throttle; 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate /* stats */ 1030Sstevel@tonic-gate uint64_t sleep_allocs_failed; 1040Sstevel@tonic-gate uint64_t nosleep_allocs_failed; 1050Sstevel@tonic-gate uint64_t allocs_throttled; 1060Sstevel@tonic-gate uint64_t allocs_limited; 1070Sstevel@tonic-gate uint64_t alloc_bytes_failed; 1080Sstevel@tonic-gate } segkmem_lpcb_t; 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate extern void *segkmem_alloc_lp(vmem_t *, size_t *, int); 1110Sstevel@tonic-gate extern void segkmem_free_lp(vmem_t *, void *, size_t); 1120Sstevel@tonic-gate extern int segkmem_lpsetup(); 1130Sstevel@tonic-gate extern void segkmem_heap_lp_init(void); 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate extern size_t segkmem_lpsize; 1160Sstevel@tonic-gate extern size_t segkmem_heaplp_quantum; 1170Sstevel@tonic-gate extern size_t segkmem_kmemlp_max; 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate #define SEGKMEM_USE_LARGEPAGES (segkmem_lpsize > PAGESIZE) 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate #define IS_KMEM_VA_LARGEPAGE(vaddr) \ 1220Sstevel@tonic-gate (((vaddr) >= heap_lp_base) && ((vaddr) < heap_lp_end)) 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate #endif /* _KERNEL */ 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate #ifdef __cplusplus 1270Sstevel@tonic-gate } 1280Sstevel@tonic-gate #endif 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate #endif /* _VM_SEG_KMEM_H */ 131