1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #ifndef _SYS_KMEM_H 31*7c478bd9Sstevel@tonic-gate #define _SYS_KMEM_H 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 36*7c478bd9Sstevel@tonic-gate #include <sys/vmem.h> 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 39*7c478bd9Sstevel@tonic-gate extern "C" { 40*7c478bd9Sstevel@tonic-gate #endif 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate /* 43*7c478bd9Sstevel@tonic-gate * Kernel memory allocator: DDI interfaces. 44*7c478bd9Sstevel@tonic-gate * See kmem_alloc(9F) for details. 45*7c478bd9Sstevel@tonic-gate */ 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate #define KM_SLEEP 0x0000 /* can block for memory; success guaranteed */ 48*7c478bd9Sstevel@tonic-gate #define KM_NOSLEEP 0x0001 /* cannot block for memory; may fail */ 49*7c478bd9Sstevel@tonic-gate #define KM_PANIC 0x0002 /* if memory cannot be allocated, panic */ 50*7c478bd9Sstevel@tonic-gate #define KM_PUSHPAGE 0x0004 /* can block for memory; may use reserve */ 51*7c478bd9Sstevel@tonic-gate #define KM_VMFLAGS 0x00ff /* flags that must match VM_* flags */ 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate #define KM_FLAGS 0xffff /* all settable kmem flags */ 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate extern void *kmem_alloc(size_t size, int kmflags); 58*7c478bd9Sstevel@tonic-gate extern void *kmem_zalloc(size_t size, int kmflags); 59*7c478bd9Sstevel@tonic-gate extern void kmem_free(void *buf, size_t size); 60*7c478bd9Sstevel@tonic-gate extern void *kmem_alloc_tryhard(size_t size, size_t *alloc_size, int kmflags); 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 63*7c478bd9Sstevel@tonic-gate 64*7c478bd9Sstevel@tonic-gate /* 65*7c478bd9Sstevel@tonic-gate * Kernel memory allocator: private interfaces. 66*7c478bd9Sstevel@tonic-gate * These interfaces are still evolving. 67*7c478bd9Sstevel@tonic-gate * Do not use them in unbundled drivers. 68*7c478bd9Sstevel@tonic-gate */ 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate /* 71*7c478bd9Sstevel@tonic-gate * Flags for kmem_cache_create() 72*7c478bd9Sstevel@tonic-gate */ 73*7c478bd9Sstevel@tonic-gate #define KMC_NOTOUCH 0x00010000 74*7c478bd9Sstevel@tonic-gate #define KMC_NODEBUG 0x00020000 75*7c478bd9Sstevel@tonic-gate #define KMC_NOMAGAZINE 0x00040000 76*7c478bd9Sstevel@tonic-gate #define KMC_NOHASH 0x00080000 77*7c478bd9Sstevel@tonic-gate #define KMC_QCACHE 0x00100000 78*7c478bd9Sstevel@tonic-gate #define KMC_KMEM_ALLOC 0x00200000 /* internal use only */ 79*7c478bd9Sstevel@tonic-gate #define KMC_IDENTIFIER 0x00400000 /* internal use only */ 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate struct kmem_cache; /* cache structure is opaque to kmem clients */ 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate typedef struct kmem_cache kmem_cache_t; 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate extern int kmem_ready; 88*7c478bd9Sstevel@tonic-gate extern pgcnt_t kmem_reapahead; 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate extern void kmem_init(void); 91*7c478bd9Sstevel@tonic-gate extern void kmem_thread_init(void); 92*7c478bd9Sstevel@tonic-gate extern void kmem_mp_init(void); 93*7c478bd9Sstevel@tonic-gate extern void kmem_reap(void); 94*7c478bd9Sstevel@tonic-gate extern void kmem_reap_idspace(void); 95*7c478bd9Sstevel@tonic-gate extern size_t kmem_avail(void); 96*7c478bd9Sstevel@tonic-gate extern size_t kmem_maxavail(void); 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate extern kmem_cache_t *kmem_cache_create(char *, size_t, size_t, 99*7c478bd9Sstevel@tonic-gate int (*)(void *, void *, int), void (*)(void *, void *), 100*7c478bd9Sstevel@tonic-gate void (*)(void *), void *, vmem_t *, int); 101*7c478bd9Sstevel@tonic-gate extern void kmem_cache_destroy(kmem_cache_t *); 102*7c478bd9Sstevel@tonic-gate extern void *kmem_cache_alloc(kmem_cache_t *, int); 103*7c478bd9Sstevel@tonic-gate extern void kmem_cache_free(kmem_cache_t *, void *); 104*7c478bd9Sstevel@tonic-gate extern uint64_t kmem_cache_stat(kmem_cache_t *, char *); 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 109*7c478bd9Sstevel@tonic-gate } 110*7c478bd9Sstevel@tonic-gate #endif 111*7c478bd9Sstevel@tonic-gate 112*7c478bd9Sstevel@tonic-gate #endif /* _SYS_KMEM_H */ 113