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 5*b5fca8f8Stomee * Common Development and Distribution License (the "License"). 6*b5fca8f8Stomee * 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 */ 21*b5fca8f8Stomee 227c478bd9Sstevel@tonic-gate /* 23*b5fca8f8Stomee * Copyright 2008 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 #pragma ident "%Z%%M% %I% %E% SMI" 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #include <sys/types.h> 367c478bd9Sstevel@tonic-gate #include <sys/vmem.h> 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #ifdef __cplusplus 397c478bd9Sstevel@tonic-gate extern "C" { 407c478bd9Sstevel@tonic-gate #endif 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate /* 437c478bd9Sstevel@tonic-gate * Kernel memory allocator: DDI interfaces. 447c478bd9Sstevel@tonic-gate * See kmem_alloc(9F) for details. 457c478bd9Sstevel@tonic-gate */ 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #define KM_SLEEP 0x0000 /* can block for memory; success guaranteed */ 487c478bd9Sstevel@tonic-gate #define KM_NOSLEEP 0x0001 /* cannot block for memory; may fail */ 497c478bd9Sstevel@tonic-gate #define KM_PANIC 0x0002 /* if memory cannot be allocated, panic */ 507c478bd9Sstevel@tonic-gate #define KM_PUSHPAGE 0x0004 /* can block for memory; may use reserve */ 517c478bd9Sstevel@tonic-gate #define KM_VMFLAGS 0x00ff /* flags that must match VM_* flags */ 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate #define KM_FLAGS 0xffff /* all settable kmem flags */ 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate #ifdef _KERNEL 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate extern void *kmem_alloc(size_t size, int kmflags); 587c478bd9Sstevel@tonic-gate extern void *kmem_zalloc(size_t size, int kmflags); 597c478bd9Sstevel@tonic-gate extern void kmem_free(void *buf, size_t size); 607c478bd9Sstevel@tonic-gate extern void *kmem_alloc_tryhard(size_t size, size_t *alloc_size, int kmflags); 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate /* 657c478bd9Sstevel@tonic-gate * Kernel memory allocator: private interfaces. 667c478bd9Sstevel@tonic-gate * These interfaces are still evolving. 677c478bd9Sstevel@tonic-gate * Do not use them in unbundled drivers. 687c478bd9Sstevel@tonic-gate */ 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate /* 717c478bd9Sstevel@tonic-gate * Flags for kmem_cache_create() 727c478bd9Sstevel@tonic-gate */ 737c478bd9Sstevel@tonic-gate #define KMC_NOTOUCH 0x00010000 747c478bd9Sstevel@tonic-gate #define KMC_NODEBUG 0x00020000 757c478bd9Sstevel@tonic-gate #define KMC_NOMAGAZINE 0x00040000 767c478bd9Sstevel@tonic-gate #define KMC_NOHASH 0x00080000 777c478bd9Sstevel@tonic-gate #define KMC_QCACHE 0x00100000 787c478bd9Sstevel@tonic-gate #define KMC_KMEM_ALLOC 0x00200000 /* internal use only */ 797c478bd9Sstevel@tonic-gate #define KMC_IDENTIFIER 0x00400000 /* internal use only */ 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate struct kmem_cache; /* cache structure is opaque to kmem clients */ 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate typedef struct kmem_cache kmem_cache_t; 847c478bd9Sstevel@tonic-gate 85*b5fca8f8Stomee /* Client response to kmem move callback */ 86*b5fca8f8Stomee typedef enum kmem_cbrc { 87*b5fca8f8Stomee KMEM_CBRC_YES, 88*b5fca8f8Stomee KMEM_CBRC_NO, 89*b5fca8f8Stomee KMEM_CBRC_LATER, 90*b5fca8f8Stomee KMEM_CBRC_DONT_NEED, 91*b5fca8f8Stomee KMEM_CBRC_DONT_KNOW 92*b5fca8f8Stomee } kmem_cbrc_t; 93*b5fca8f8Stomee 947c478bd9Sstevel@tonic-gate #ifdef _KERNEL 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate extern int kmem_ready; 977c478bd9Sstevel@tonic-gate extern pgcnt_t kmem_reapahead; 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate extern void kmem_init(void); 1007c478bd9Sstevel@tonic-gate extern void kmem_thread_init(void); 1017c478bd9Sstevel@tonic-gate extern void kmem_mp_init(void); 1027c478bd9Sstevel@tonic-gate extern void kmem_reap(void); 1037c478bd9Sstevel@tonic-gate extern void kmem_reap_idspace(void); 104fa9e4066Sahrens extern int kmem_debugging(void); 1057c478bd9Sstevel@tonic-gate extern size_t kmem_avail(void); 1067c478bd9Sstevel@tonic-gate extern size_t kmem_maxavail(void); 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate extern kmem_cache_t *kmem_cache_create(char *, size_t, size_t, 1097c478bd9Sstevel@tonic-gate int (*)(void *, void *, int), void (*)(void *, void *), 1107c478bd9Sstevel@tonic-gate void (*)(void *), void *, vmem_t *, int); 111*b5fca8f8Stomee extern void kmem_cache_set_move(kmem_cache_t *, 112*b5fca8f8Stomee kmem_cbrc_t (*)(void *, void *, size_t, void *)); 1137c478bd9Sstevel@tonic-gate extern void kmem_cache_destroy(kmem_cache_t *); 1147c478bd9Sstevel@tonic-gate extern void *kmem_cache_alloc(kmem_cache_t *, int); 1157c478bd9Sstevel@tonic-gate extern void kmem_cache_free(kmem_cache_t *, void *); 1167c478bd9Sstevel@tonic-gate extern uint64_t kmem_cache_stat(kmem_cache_t *, char *); 117fa9e4066Sahrens extern void kmem_cache_reap_now(kmem_cache_t *); 118*b5fca8f8Stomee extern void kmem_cache_move_notify(kmem_cache_t *, void *); 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1237c478bd9Sstevel@tonic-gate } 1247c478bd9Sstevel@tonic-gate #endif 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate #endif /* _SYS_KMEM_H */ 127