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 5b5fca8f8Stomee * Common Development and Distribution License (the "License"). 6b5fca8f8Stomee * 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 */ 21b5fca8f8Stomee 227c478bd9Sstevel@tonic-gate /* 23*9dd77bc8SDave Plauger * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #ifndef _SYS_KMEM_H 317c478bd9Sstevel@tonic-gate #define _SYS_KMEM_H 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <sys/types.h> 347c478bd9Sstevel@tonic-gate #include <sys/vmem.h> 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #ifdef __cplusplus 377c478bd9Sstevel@tonic-gate extern "C" { 387c478bd9Sstevel@tonic-gate #endif 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* 417c478bd9Sstevel@tonic-gate * Kernel memory allocator: DDI interfaces. 427c478bd9Sstevel@tonic-gate * See kmem_alloc(9F) for details. 437c478bd9Sstevel@tonic-gate */ 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate #define KM_SLEEP 0x0000 /* can block for memory; success guaranteed */ 467c478bd9Sstevel@tonic-gate #define KM_NOSLEEP 0x0001 /* cannot block for memory; may fail */ 477c478bd9Sstevel@tonic-gate #define KM_PANIC 0x0002 /* if memory cannot be allocated, panic */ 487c478bd9Sstevel@tonic-gate #define KM_PUSHPAGE 0x0004 /* can block for memory; may use reserve */ 497c478bd9Sstevel@tonic-gate #define KM_VMFLAGS 0x00ff /* flags that must match VM_* flags */ 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #define KM_FLAGS 0xffff /* all settable kmem flags */ 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate #ifdef _KERNEL 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate extern void *kmem_alloc(size_t size, int kmflags); 567c478bd9Sstevel@tonic-gate extern void *kmem_zalloc(size_t size, int kmflags); 577c478bd9Sstevel@tonic-gate extern void kmem_free(void *buf, size_t size); 587c478bd9Sstevel@tonic-gate extern void *kmem_alloc_tryhard(size_t size, size_t *alloc_size, int kmflags); 59*9dd77bc8SDave Plauger extern void kmem_dump_init(size_t); 60*9dd77bc8SDave Plauger extern void kmem_dump_begin(void); 61*9dd77bc8SDave Plauger extern size_t kmem_dump_finish(char *buf, size_t size); 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate /* 667c478bd9Sstevel@tonic-gate * Kernel memory allocator: private interfaces. 677c478bd9Sstevel@tonic-gate * These interfaces are still evolving. 687c478bd9Sstevel@tonic-gate * Do not use them in unbundled drivers. 697c478bd9Sstevel@tonic-gate */ 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate /* 727c478bd9Sstevel@tonic-gate * Flags for kmem_cache_create() 737c478bd9Sstevel@tonic-gate */ 747c478bd9Sstevel@tonic-gate #define KMC_NOTOUCH 0x00010000 757c478bd9Sstevel@tonic-gate #define KMC_NODEBUG 0x00020000 767c478bd9Sstevel@tonic-gate #define KMC_NOMAGAZINE 0x00040000 777c478bd9Sstevel@tonic-gate #define KMC_NOHASH 0x00080000 787c478bd9Sstevel@tonic-gate #define KMC_QCACHE 0x00100000 797c478bd9Sstevel@tonic-gate #define KMC_KMEM_ALLOC 0x00200000 /* internal use only */ 807c478bd9Sstevel@tonic-gate #define KMC_IDENTIFIER 0x00400000 /* internal use only */ 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate struct kmem_cache; /* cache structure is opaque to kmem clients */ 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate typedef struct kmem_cache kmem_cache_t; 857c478bd9Sstevel@tonic-gate 86b5fca8f8Stomee /* Client response to kmem move callback */ 87b5fca8f8Stomee typedef enum kmem_cbrc { 88b5fca8f8Stomee KMEM_CBRC_YES, 89b5fca8f8Stomee KMEM_CBRC_NO, 90b5fca8f8Stomee KMEM_CBRC_LATER, 91b5fca8f8Stomee KMEM_CBRC_DONT_NEED, 92b5fca8f8Stomee KMEM_CBRC_DONT_KNOW 93b5fca8f8Stomee } kmem_cbrc_t; 94b5fca8f8Stomee 957c478bd9Sstevel@tonic-gate #ifdef _KERNEL 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate extern int kmem_ready; 987c478bd9Sstevel@tonic-gate extern pgcnt_t kmem_reapahead; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate extern void kmem_init(void); 1017c478bd9Sstevel@tonic-gate extern void kmem_thread_init(void); 1027c478bd9Sstevel@tonic-gate extern void kmem_mp_init(void); 1037c478bd9Sstevel@tonic-gate extern void kmem_reap(void); 1047c478bd9Sstevel@tonic-gate extern void kmem_reap_idspace(void); 105fa9e4066Sahrens extern int kmem_debugging(void); 1067c478bd9Sstevel@tonic-gate extern size_t kmem_avail(void); 1077c478bd9Sstevel@tonic-gate extern size_t kmem_maxavail(void); 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate extern kmem_cache_t *kmem_cache_create(char *, size_t, size_t, 1107c478bd9Sstevel@tonic-gate int (*)(void *, void *, int), void (*)(void *, void *), 1117c478bd9Sstevel@tonic-gate void (*)(void *), void *, vmem_t *, int); 112b5fca8f8Stomee extern void kmem_cache_set_move(kmem_cache_t *, 113b5fca8f8Stomee kmem_cbrc_t (*)(void *, void *, size_t, void *)); 1147c478bd9Sstevel@tonic-gate extern void kmem_cache_destroy(kmem_cache_t *); 1157c478bd9Sstevel@tonic-gate extern void *kmem_cache_alloc(kmem_cache_t *, int); 1167c478bd9Sstevel@tonic-gate extern void kmem_cache_free(kmem_cache_t *, void *); 1177c478bd9Sstevel@tonic-gate extern uint64_t kmem_cache_stat(kmem_cache_t *, char *); 118fa9e4066Sahrens extern void kmem_cache_reap_now(kmem_cache_t *); 119b5fca8f8Stomee extern void kmem_cache_move_notify(kmem_cache_t *, void *); 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1247c478bd9Sstevel@tonic-gate } 1257c478bd9Sstevel@tonic-gate #endif 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate #endif /* _SYS_KMEM_H */ 128