1fa9e4066Sahrens /* 2fa9e4066Sahrens * CDDL HEADER START 3fa9e4066Sahrens * 4fa9e4066Sahrens * The contents of this file are subject to the terms of the 5ea8dc4b6Seschrock * Common Development and Distribution License (the "License"). 6ea8dc4b6Seschrock * You may not use this file except in compliance with the License. 7fa9e4066Sahrens * 8fa9e4066Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9fa9e4066Sahrens * or http://www.opensolaris.org/os/licensing. 10fa9e4066Sahrens * See the License for the specific language governing permissions 11fa9e4066Sahrens * and limitations under the License. 12fa9e4066Sahrens * 13fa9e4066Sahrens * When distributing Covered Code, include this CDDL HEADER in each 14fa9e4066Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15fa9e4066Sahrens * If applicable, add the following below this CDDL HEADER, with the 16fa9e4066Sahrens * fields enclosed by brackets "[]" replaced with your own identifying 17fa9e4066Sahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18fa9e4066Sahrens * 19fa9e4066Sahrens * CDDL HEADER END 20fa9e4066Sahrens */ 21fa9e4066Sahrens /* 223f9d6ad7SLin Ling * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 237802d7bfSMatthew Ahrens * Copyright (c) 2012, 2014 by Delphix. All rights reserved. 24aad02571SSaso Kiselkov * Copyright (c) 2013 by Saso Kiselkov. All rights reserved. 25fa9e4066Sahrens */ 26fa9e4066Sahrens 27fa9e4066Sahrens #ifndef _SYS_ARC_H 28fa9e4066Sahrens #define _SYS_ARC_H 29fa9e4066Sahrens 30fa9e4066Sahrens #include <sys/zfs_context.h> 31fa9e4066Sahrens 32fa9e4066Sahrens #ifdef __cplusplus 33fa9e4066Sahrens extern "C" { 34fa9e4066Sahrens #endif 35fa9e4066Sahrens 36fa9e4066Sahrens #include <sys/zio.h> 37e45ce728Sahrens #include <sys/dmu.h> 38fa94a07fSbrendan #include <sys/spa.h> 39fa9e4066Sahrens 40*244781f1SPrakash Surya /* 41*244781f1SPrakash Surya * Used by arc_flush() to inform arc_evict_state() that it should evict 42*244781f1SPrakash Surya * all available buffers from the arc state being passed in. 43*244781f1SPrakash Surya */ 44*244781f1SPrakash Surya #define ARC_EVICT_ALL -1ULL 45*244781f1SPrakash Surya 46fa9e4066Sahrens typedef struct arc_buf_hdr arc_buf_hdr_t; 47fa9e4066Sahrens typedef struct arc_buf arc_buf_t; 48fa9e4066Sahrens typedef void arc_done_func_t(zio_t *zio, arc_buf_t *buf, void *private); 49ea8dc4b6Seschrock typedef int arc_evict_func_t(void *private); 50fa9e4066Sahrens 51fa9e4066Sahrens /* generic arc_done_func_t's which you can use */ 52fa9e4066Sahrens arc_done_func_t arc_bcopy_func; 53fa9e4066Sahrens arc_done_func_t arc_getbuf_func; 54fa9e4066Sahrens 557adb730bSGeorge Wilson typedef enum arc_flags 567adb730bSGeorge Wilson { 577adb730bSGeorge Wilson /* 587adb730bSGeorge Wilson * Public flags that can be passed into the ARC by external consumers. 597adb730bSGeorge Wilson */ 607adb730bSGeorge Wilson ARC_FLAG_NONE = 1 << 0, /* No flags set */ 617adb730bSGeorge Wilson ARC_FLAG_WAIT = 1 << 1, /* perform sync I/O */ 627adb730bSGeorge Wilson ARC_FLAG_NOWAIT = 1 << 2, /* perform async I/O */ 637adb730bSGeorge Wilson ARC_FLAG_PREFETCH = 1 << 3, /* I/O is a prefetch */ 647adb730bSGeorge Wilson ARC_FLAG_CACHED = 1 << 4, /* I/O was in cache */ 657adb730bSGeorge Wilson ARC_FLAG_L2CACHE = 1 << 5, /* cache in L2ARC */ 667adb730bSGeorge Wilson ARC_FLAG_L2COMPRESS = 1 << 6, /* compress in L2ARC */ 677adb730bSGeorge Wilson 687adb730bSGeorge Wilson /* 697adb730bSGeorge Wilson * Private ARC flags. These flags are private ARC only flags that 707adb730bSGeorge Wilson * will show up in b_flags in the arc_hdr_buf_t. These flags should 717adb730bSGeorge Wilson * only be set by ARC code. 727adb730bSGeorge Wilson */ 737adb730bSGeorge Wilson ARC_FLAG_IN_HASH_TABLE = 1 << 7, /* buffer is hashed */ 747adb730bSGeorge Wilson ARC_FLAG_IO_IN_PROGRESS = 1 << 8, /* I/O in progress */ 757adb730bSGeorge Wilson ARC_FLAG_IO_ERROR = 1 << 9, /* I/O failed for buf */ 767adb730bSGeorge Wilson ARC_FLAG_FREED_IN_READ = 1 << 10, /* freed during read */ 777adb730bSGeorge Wilson ARC_FLAG_BUF_AVAILABLE = 1 << 11, /* block not in use */ 787adb730bSGeorge Wilson ARC_FLAG_INDIRECT = 1 << 12, /* indirect block */ 7989c86e32SChris Williamson ARC_FLAG_L2_WRITING = 1 << 13, /* write in progress */ 8089c86e32SChris Williamson ARC_FLAG_L2_EVICTED = 1 << 14, /* evicted during I/O */ 8189c86e32SChris Williamson ARC_FLAG_L2_WRITE_HEAD = 1 << 15, /* head of write list */ 8289c86e32SChris Williamson /* indicates that the buffer contains metadata (otherwise, data) */ 8389c86e32SChris Williamson ARC_FLAG_BUFC_METADATA = 1 << 16, 8489c86e32SChris Williamson 8589c86e32SChris Williamson /* Flags specifying whether optional hdr struct fields are defined */ 8689c86e32SChris Williamson ARC_FLAG_HAS_L1HDR = 1 << 17, 8789c86e32SChris Williamson ARC_FLAG_HAS_L2HDR = 1 << 18, 8889c86e32SChris Williamson 8989c86e32SChris Williamson /* 9089c86e32SChris Williamson * The arc buffer's compression mode is stored in the top 7 bits of the 9189c86e32SChris Williamson * flags field, so these dummy flags are included so that MDB can 9289c86e32SChris Williamson * interpret the enum properly. 9389c86e32SChris Williamson */ 9489c86e32SChris Williamson ARC_FLAG_COMPRESS_0 = 1 << 24, 9589c86e32SChris Williamson ARC_FLAG_COMPRESS_1 = 1 << 25, 9689c86e32SChris Williamson ARC_FLAG_COMPRESS_2 = 1 << 26, 9789c86e32SChris Williamson ARC_FLAG_COMPRESS_3 = 1 << 27, 9889c86e32SChris Williamson ARC_FLAG_COMPRESS_4 = 1 << 28, 9989c86e32SChris Williamson ARC_FLAG_COMPRESS_5 = 1 << 29, 10089c86e32SChris Williamson ARC_FLAG_COMPRESS_6 = 1 << 30 10189c86e32SChris Williamson 1027adb730bSGeorge Wilson } arc_flags_t; 1037adb730bSGeorge Wilson 104fa9e4066Sahrens struct arc_buf { 105fa9e4066Sahrens arc_buf_hdr_t *b_hdr; 106fa9e4066Sahrens arc_buf_t *b_next; 1073f9d6ad7SLin Ling kmutex_t b_evict_lock; 108fa9e4066Sahrens void *b_data; 109ea8dc4b6Seschrock arc_evict_func_t *b_efunc; 110ea8dc4b6Seschrock void *b_private; 111fa9e4066Sahrens }; 112fa9e4066Sahrens 113ad23a2dbSjohansen typedef enum arc_buf_contents { 114ad23a2dbSjohansen ARC_BUFC_DATA, /* buffer contains data */ 1150e8c6158Smaybee ARC_BUFC_METADATA, /* buffer contains metadata */ 1160e8c6158Smaybee ARC_BUFC_NUMTYPES 117ad23a2dbSjohansen } arc_buf_contents_t; 118fa9e4066Sahrens 1195a98e54bSBrendan Gregg - Sun Microsystems /* 1205a98e54bSBrendan Gregg - Sun Microsystems * The following breakdows of arc_size exist for kstat only. 1215a98e54bSBrendan Gregg - Sun Microsystems */ 1225a98e54bSBrendan Gregg - Sun Microsystems typedef enum arc_space_type { 1235a98e54bSBrendan Gregg - Sun Microsystems ARC_SPACE_DATA, 1244076b1bfSPrakash Surya ARC_SPACE_META, 1255a98e54bSBrendan Gregg - Sun Microsystems ARC_SPACE_HDRS, 1265a98e54bSBrendan Gregg - Sun Microsystems ARC_SPACE_L2HDRS, 1275a98e54bSBrendan Gregg - Sun Microsystems ARC_SPACE_OTHER, 1285a98e54bSBrendan Gregg - Sun Microsystems ARC_SPACE_NUMTYPES 1295a98e54bSBrendan Gregg - Sun Microsystems } arc_space_type_t; 1305a98e54bSBrendan Gregg - Sun Microsystems 1315a98e54bSBrendan Gregg - Sun Microsystems void arc_space_consume(uint64_t space, arc_space_type_t type); 1325a98e54bSBrendan Gregg - Sun Microsystems void arc_space_return(uint64_t space, arc_space_type_t type); 133ad23a2dbSjohansen arc_buf_t *arc_buf_alloc(spa_t *spa, int size, void *tag, 134ad23a2dbSjohansen arc_buf_contents_t type); 1352fdbea25SAleksandr Guzovskiy arc_buf_t *arc_loan_buf(spa_t *spa, int size); 1362fdbea25SAleksandr Guzovskiy void arc_return_buf(arc_buf_t *buf, void *tag); 137c242f9a0Schunli zhang - Sun Microsystems - Irvine United States void arc_loan_inuse_buf(arc_buf_t *buf, void *tag); 138ea8dc4b6Seschrock void arc_buf_add_ref(arc_buf_t *buf, void *tag); 1393b2aab18SMatthew Ahrens boolean_t arc_buf_remove_ref(arc_buf_t *buf, void *tag); 140fa9e4066Sahrens int arc_buf_size(arc_buf_t *buf); 141fa9e4066Sahrens void arc_release(arc_buf_t *buf, void *tag); 142fa9e4066Sahrens int arc_released(arc_buf_t *buf); 1436b4acc8bSahrens void arc_buf_freeze(arc_buf_t *buf); 1446b4acc8bSahrens void arc_buf_thaw(arc_buf_t *buf); 1459253d63dSGeorge Wilson boolean_t arc_buf_eviction_needed(arc_buf_t *buf); 146ea8dc4b6Seschrock #ifdef ZFS_DEBUG 147ea8dc4b6Seschrock int arc_referenced(arc_buf_t *buf); 148ea8dc4b6Seschrock #endif 149fa9e4066Sahrens 1501b912ec7SGeorge Wilson int arc_read(zio_t *pio, spa_t *spa, const blkptr_t *bp, 15169962b56SMatthew Ahrens arc_done_func_t *done, void *private, zio_priority_t priority, int flags, 1527adb730bSGeorge Wilson arc_flags_t *arc_flags, const zbookmark_phys_t *zb); 153b24ab676SJeff Bonwick zio_t *arc_write(zio_t *pio, spa_t *spa, uint64_t txg, 154aad02571SSaso Kiselkov blkptr_t *bp, arc_buf_t *buf, boolean_t l2arc, boolean_t l2arc_compress, 15569962b56SMatthew Ahrens const zio_prop_t *zp, arc_done_func_t *ready, arc_done_func_t *physdone, 15669962b56SMatthew Ahrens arc_done_func_t *done, void *private, zio_priority_t priority, 1577802d7bfSMatthew Ahrens int zio_flags, const zbookmark_phys_t *zb); 1586e6d5868SMatthew Ahrens void arc_freed(spa_t *spa, const blkptr_t *bp); 159fa9e4066Sahrens 160ea8dc4b6Seschrock void arc_set_callback(arc_buf_t *buf, arc_evict_func_t *func, void *private); 161bbfa8ea8SMatthew Ahrens boolean_t arc_clear_callback(arc_buf_t *buf); 162ea8dc4b6Seschrock 163*244781f1SPrakash Surya void arc_flush(spa_t *spa, boolean_t retry); 1641ab7f2deSmaybee void arc_tempreserve_clear(uint64_t reserve); 1651ab7f2deSmaybee int arc_tempreserve_space(uint64_t reserve, uint64_t txg); 166fa9e4066Sahrens 167fa9e4066Sahrens void arc_init(void); 168fa9e4066Sahrens void arc_fini(void); 169fa9e4066Sahrens 170fa94a07fSbrendan /* 171fa94a07fSbrendan * Level 2 ARC 172fa94a07fSbrendan */ 173fa94a07fSbrendan 174573ca77eSGeorge Wilson void l2arc_add_vdev(spa_t *spa, vdev_t *vd); 175fa94a07fSbrendan void l2arc_remove_vdev(vdev_t *vd); 176c5904d13Seschrock boolean_t l2arc_vdev_present(vdev_t *vd); 177fa94a07fSbrendan void l2arc_init(void); 178fa94a07fSbrendan void l2arc_fini(void); 179e14bb325SJeff Bonwick void l2arc_start(void); 180e14bb325SJeff Bonwick void l2arc_stop(void); 181fa94a07fSbrendan 182cd1c8b85SMatthew Ahrens #ifndef _KERNEL 183cd1c8b85SMatthew Ahrens extern boolean_t arc_watch; 184cd1c8b85SMatthew Ahrens extern int arc_procfd; 185cd1c8b85SMatthew Ahrens #endif 186cd1c8b85SMatthew Ahrens 187fa9e4066Sahrens #ifdef __cplusplus 188fa9e4066Sahrens } 189fa9e4066Sahrens #endif 190fa9e4066Sahrens 191fa9e4066Sahrens #endif /* _SYS_ARC_H */ 192