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 56712Stomee * Common Development and Distribution License (the "License"). 66712Stomee * 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 */ 216712Stomee 220Sstevel@tonic-gate /* 2312093SDavid.Valin@Sun.COM * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 270Sstevel@tonic-gate /* All Rights Reserved */ 280Sstevel@tonic-gate 290Sstevel@tonic-gate #ifndef _SYS_KMEM_H 300Sstevel@tonic-gate #define _SYS_KMEM_H 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #include <sys/vmem.h> 340Sstevel@tonic-gate 350Sstevel@tonic-gate #ifdef __cplusplus 360Sstevel@tonic-gate extern "C" { 370Sstevel@tonic-gate #endif 380Sstevel@tonic-gate 390Sstevel@tonic-gate /* 400Sstevel@tonic-gate * Kernel memory allocator: DDI interfaces. 410Sstevel@tonic-gate * See kmem_alloc(9F) for details. 420Sstevel@tonic-gate */ 430Sstevel@tonic-gate 440Sstevel@tonic-gate #define KM_SLEEP 0x0000 /* can block for memory; success guaranteed */ 450Sstevel@tonic-gate #define KM_NOSLEEP 0x0001 /* cannot block for memory; may fail */ 460Sstevel@tonic-gate #define KM_PANIC 0x0002 /* if memory cannot be allocated, panic */ 470Sstevel@tonic-gate #define KM_PUSHPAGE 0x0004 /* can block for memory; may use reserve */ 4812156SStan.Studzinski@Sun.COM #define KM_NORMALPRI 0x0008 /* with KM_NOSLEEP, lower priority allocation */ 490Sstevel@tonic-gate #define KM_VMFLAGS 0x00ff /* flags that must match VM_* flags */ 500Sstevel@tonic-gate 510Sstevel@tonic-gate #define KM_FLAGS 0xffff /* all settable kmem flags */ 520Sstevel@tonic-gate 530Sstevel@tonic-gate #ifdef _KERNEL 540Sstevel@tonic-gate 550Sstevel@tonic-gate extern void *kmem_alloc(size_t size, int kmflags); 560Sstevel@tonic-gate extern void *kmem_zalloc(size_t size, int kmflags); 570Sstevel@tonic-gate extern void kmem_free(void *buf, size_t size); 580Sstevel@tonic-gate extern void *kmem_alloc_tryhard(size_t size, size_t *alloc_size, int kmflags); 5911178SDave.Plauger@Sun.COM extern void kmem_dump_init(size_t); 6011178SDave.Plauger@Sun.COM extern void kmem_dump_begin(void); 6111178SDave.Plauger@Sun.COM extern size_t kmem_dump_finish(char *buf, size_t size); 620Sstevel@tonic-gate 630Sstevel@tonic-gate #endif /* _KERNEL */ 640Sstevel@tonic-gate 650Sstevel@tonic-gate /* 660Sstevel@tonic-gate * Kernel memory allocator: private interfaces. 670Sstevel@tonic-gate * These interfaces are still evolving. 680Sstevel@tonic-gate * Do not use them in unbundled drivers. 690Sstevel@tonic-gate */ 700Sstevel@tonic-gate 710Sstevel@tonic-gate /* 720Sstevel@tonic-gate * Flags for kmem_cache_create() 730Sstevel@tonic-gate */ 740Sstevel@tonic-gate #define KMC_NOTOUCH 0x00010000 750Sstevel@tonic-gate #define KMC_NODEBUG 0x00020000 760Sstevel@tonic-gate #define KMC_NOMAGAZINE 0x00040000 770Sstevel@tonic-gate #define KMC_NOHASH 0x00080000 780Sstevel@tonic-gate #define KMC_QCACHE 0x00100000 790Sstevel@tonic-gate #define KMC_KMEM_ALLOC 0x00200000 /* internal use only */ 800Sstevel@tonic-gate #define KMC_IDENTIFIER 0x00400000 /* internal use only */ 8112093SDavid.Valin@Sun.COM #define KMC_PREFILL 0x00800000 820Sstevel@tonic-gate 830Sstevel@tonic-gate struct kmem_cache; /* cache structure is opaque to kmem clients */ 840Sstevel@tonic-gate 850Sstevel@tonic-gate typedef struct kmem_cache kmem_cache_t; 860Sstevel@tonic-gate 876712Stomee /* Client response to kmem move callback */ 886712Stomee typedef enum kmem_cbrc { 896712Stomee KMEM_CBRC_YES, 906712Stomee KMEM_CBRC_NO, 916712Stomee KMEM_CBRC_LATER, 926712Stomee KMEM_CBRC_DONT_NEED, 936712Stomee KMEM_CBRC_DONT_KNOW 946712Stomee } kmem_cbrc_t; 956712Stomee 960Sstevel@tonic-gate #ifdef _KERNEL 970Sstevel@tonic-gate 98*12684STom.Erickson@Sun.COM /* 99*12684STom.Erickson@Sun.COM * Helps clients implementing the move() callback to recognize known objects by 100*12684STom.Erickson@Sun.COM * testing a client-designated pointer member. Takes advantage of the fact that 101*12684STom.Erickson@Sun.COM * any scribbling to freed memory done by kmem is guaranteed to set one of the 102*12684STom.Erickson@Sun.COM * two low order bits. 103*12684STom.Erickson@Sun.COM */ 104*12684STom.Erickson@Sun.COM #define POINTER_IS_VALID(p) (!((uintptr_t)(p) & 0x3)) 105*12684STom.Erickson@Sun.COM #define POINTER_INVALIDATE(pp) (*(pp) = (void *)((uintptr_t)(*(pp)) | 0x1)) 106*12684STom.Erickson@Sun.COM 1070Sstevel@tonic-gate extern int kmem_ready; 1080Sstevel@tonic-gate extern pgcnt_t kmem_reapahead; 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate extern void kmem_init(void); 1110Sstevel@tonic-gate extern void kmem_thread_init(void); 1120Sstevel@tonic-gate extern void kmem_mp_init(void); 1130Sstevel@tonic-gate extern void kmem_reap(void); 1140Sstevel@tonic-gate extern void kmem_reap_idspace(void); 115789Sahrens extern int kmem_debugging(void); 1160Sstevel@tonic-gate extern size_t kmem_avail(void); 1170Sstevel@tonic-gate extern size_t kmem_maxavail(void); 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate extern kmem_cache_t *kmem_cache_create(char *, size_t, size_t, 1200Sstevel@tonic-gate int (*)(void *, void *, int), void (*)(void *, void *), 1210Sstevel@tonic-gate void (*)(void *), void *, vmem_t *, int); 1226712Stomee extern void kmem_cache_set_move(kmem_cache_t *, 1236712Stomee kmem_cbrc_t (*)(void *, void *, size_t, void *)); 1240Sstevel@tonic-gate extern void kmem_cache_destroy(kmem_cache_t *); 1250Sstevel@tonic-gate extern void *kmem_cache_alloc(kmem_cache_t *, int); 1260Sstevel@tonic-gate extern void kmem_cache_free(kmem_cache_t *, void *); 1270Sstevel@tonic-gate extern uint64_t kmem_cache_stat(kmem_cache_t *, char *); 128789Sahrens extern void kmem_cache_reap_now(kmem_cache_t *); 1296712Stomee extern void kmem_cache_move_notify(kmem_cache_t *, void *); 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 /* _SYS_KMEM_H */ 138