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. 2310fbdecbSMatthew Ahrens * Copyright (c) 2012, 2017 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 40244781f1SPrakash Surya /* 41244781f1SPrakash Surya * Used by arc_flush() to inform arc_evict_state() that it should evict 42244781f1SPrakash Surya * all available buffers from the arc state being passed in. 43244781f1SPrakash Surya */ 44244781f1SPrakash Surya #define ARC_EVICT_ALL -1ULL 45244781f1SPrakash Surya 46dcbf3bd6SGeorge Wilson #define HDR_SET_LSIZE(hdr, x) do { \ 47dcbf3bd6SGeorge Wilson ASSERT(IS_P2ALIGNED(x, 1U << SPA_MINBLOCKSHIFT)); \ 48dcbf3bd6SGeorge Wilson (hdr)->b_lsize = ((x) >> SPA_MINBLOCKSHIFT); \ 49dcbf3bd6SGeorge Wilson _NOTE(CONSTCOND) } while (0) 50dcbf3bd6SGeorge Wilson 51dcbf3bd6SGeorge Wilson #define HDR_SET_PSIZE(hdr, x) do { \ 52dcbf3bd6SGeorge Wilson ASSERT(IS_P2ALIGNED((x), 1U << SPA_MINBLOCKSHIFT)); \ 53dcbf3bd6SGeorge Wilson (hdr)->b_psize = ((x) >> SPA_MINBLOCKSHIFT); \ 54dcbf3bd6SGeorge Wilson _NOTE(CONSTCOND) } while (0) 55dcbf3bd6SGeorge Wilson 56dcbf3bd6SGeorge Wilson #define HDR_GET_LSIZE(hdr) ((hdr)->b_lsize << SPA_MINBLOCKSHIFT) 57dcbf3bd6SGeorge Wilson #define HDR_GET_PSIZE(hdr) ((hdr)->b_psize << SPA_MINBLOCKSHIFT) 58dcbf3bd6SGeorge Wilson 59fa9e4066Sahrens typedef struct arc_buf_hdr arc_buf_hdr_t; 60fa9e4066Sahrens typedef struct arc_buf arc_buf_t; 61fa9e4066Sahrens typedef void arc_done_func_t(zio_t *zio, arc_buf_t *buf, void *private); 62fa9e4066Sahrens 63fa9e4066Sahrens /* generic arc_done_func_t's which you can use */ 64fa9e4066Sahrens arc_done_func_t arc_bcopy_func; 65fa9e4066Sahrens arc_done_func_t arc_getbuf_func; 66fa9e4066Sahrens 677adb730bSGeorge Wilson typedef enum arc_flags 687adb730bSGeorge Wilson { 697adb730bSGeorge Wilson /* 707adb730bSGeorge Wilson * Public flags that can be passed into the ARC by external consumers. 717adb730bSGeorge Wilson */ 72dcbf3bd6SGeorge Wilson ARC_FLAG_WAIT = 1 << 0, /* perform sync I/O */ 73dcbf3bd6SGeorge Wilson ARC_FLAG_NOWAIT = 1 << 1, /* perform async I/O */ 74dcbf3bd6SGeorge Wilson ARC_FLAG_PREFETCH = 1 << 2, /* I/O is a prefetch */ 75dcbf3bd6SGeorge Wilson ARC_FLAG_CACHED = 1 << 3, /* I/O was in cache */ 76dcbf3bd6SGeorge Wilson ARC_FLAG_L2CACHE = 1 << 4, /* cache in L2ARC */ 77dcbf3bd6SGeorge Wilson ARC_FLAG_PREDICTIVE_PREFETCH = 1 << 5, /* I/O from zfetch */ 787adb730bSGeorge Wilson 797adb730bSGeorge Wilson /* 807adb730bSGeorge Wilson * Private ARC flags. These flags are private ARC only flags that 817adb730bSGeorge Wilson * will show up in b_flags in the arc_hdr_buf_t. These flags should 827adb730bSGeorge Wilson * only be set by ARC code. 837adb730bSGeorge Wilson */ 84dcbf3bd6SGeorge Wilson ARC_FLAG_IN_HASH_TABLE = 1 << 6, /* buffer is hashed */ 85dcbf3bd6SGeorge Wilson ARC_FLAG_IO_IN_PROGRESS = 1 << 7, /* I/O in progress */ 86dcbf3bd6SGeorge Wilson ARC_FLAG_IO_ERROR = 1 << 8, /* I/O failed for buf */ 87dcbf3bd6SGeorge Wilson ARC_FLAG_INDIRECT = 1 << 9, /* indirect block */ 88cf6106c8SMatthew Ahrens /* Indicates that block was read with ASYNC priority. */ 89dcbf3bd6SGeorge Wilson ARC_FLAG_PRIO_ASYNC_READ = 1 << 10, 90dcbf3bd6SGeorge Wilson ARC_FLAG_L2_WRITING = 1 << 11, /* write in progress */ 91dcbf3bd6SGeorge Wilson ARC_FLAG_L2_EVICTED = 1 << 12, /* evicted during I/O */ 92dcbf3bd6SGeorge Wilson ARC_FLAG_L2_WRITE_HEAD = 1 << 13, /* head of write list */ 9389c86e32SChris Williamson /* indicates that the buffer contains metadata (otherwise, data) */ 94dcbf3bd6SGeorge Wilson ARC_FLAG_BUFC_METADATA = 1 << 14, 9589c86e32SChris Williamson 9689c86e32SChris Williamson /* Flags specifying whether optional hdr struct fields are defined */ 97dcbf3bd6SGeorge Wilson ARC_FLAG_HAS_L1HDR = 1 << 15, 98dcbf3bd6SGeorge Wilson ARC_FLAG_HAS_L2HDR = 1 << 16, 99dcbf3bd6SGeorge Wilson 100dcbf3bd6SGeorge Wilson /* 101dcbf3bd6SGeorge Wilson * Indicates the arc_buf_hdr_t's b_pdata matches the on-disk data. 102dcbf3bd6SGeorge Wilson * This allows the l2arc to use the blkptr's checksum to verify 103dcbf3bd6SGeorge Wilson * the data without having to store the checksum in the hdr. 104dcbf3bd6SGeorge Wilson */ 105dcbf3bd6SGeorge Wilson ARC_FLAG_COMPRESSED_ARC = 1 << 17, 106dcbf3bd6SGeorge Wilson ARC_FLAG_SHARED_DATA = 1 << 18, 107dcbf3bd6SGeorge Wilson 108dcbf3bd6SGeorge Wilson /* 109dcbf3bd6SGeorge Wilson * The arc buffer's compression mode is stored in the top 7 bits of the 110dcbf3bd6SGeorge Wilson * flags field, so these dummy flags are included so that MDB can 111dcbf3bd6SGeorge Wilson * interpret the enum properly. 112dcbf3bd6SGeorge Wilson */ 113dcbf3bd6SGeorge Wilson ARC_FLAG_COMPRESS_0 = 1 << 24, 114dcbf3bd6SGeorge Wilson ARC_FLAG_COMPRESS_1 = 1 << 25, 115dcbf3bd6SGeorge Wilson ARC_FLAG_COMPRESS_2 = 1 << 26, 116dcbf3bd6SGeorge Wilson ARC_FLAG_COMPRESS_3 = 1 << 27, 117dcbf3bd6SGeorge Wilson ARC_FLAG_COMPRESS_4 = 1 << 28, 118dcbf3bd6SGeorge Wilson ARC_FLAG_COMPRESS_5 = 1 << 29, 119dcbf3bd6SGeorge Wilson ARC_FLAG_COMPRESS_6 = 1 << 30 120dcbf3bd6SGeorge Wilson 1217adb730bSGeorge Wilson } arc_flags_t; 1227adb730bSGeorge Wilson 1235602294fSDan Kimmel typedef enum arc_buf_flags { 1245602294fSDan Kimmel ARC_BUF_FLAG_SHARED = 1 << 0, 1255602294fSDan Kimmel ARC_BUF_FLAG_COMPRESSED = 1 << 1 1265602294fSDan Kimmel } arc_buf_flags_t; 1275602294fSDan Kimmel 128fa9e4066Sahrens struct arc_buf { 129fa9e4066Sahrens arc_buf_hdr_t *b_hdr; 130fa9e4066Sahrens arc_buf_t *b_next; 1313f9d6ad7SLin Ling kmutex_t b_evict_lock; 132fa9e4066Sahrens void *b_data; 1335602294fSDan Kimmel arc_buf_flags_t b_flags; 134fa9e4066Sahrens }; 135fa9e4066Sahrens 136ad23a2dbSjohansen typedef enum arc_buf_contents { 137dcbf3bd6SGeorge Wilson ARC_BUFC_INVALID, /* invalid type */ 138ad23a2dbSjohansen ARC_BUFC_DATA, /* buffer contains data */ 1390e8c6158Smaybee ARC_BUFC_METADATA, /* buffer contains metadata */ 1400e8c6158Smaybee ARC_BUFC_NUMTYPES 141ad23a2dbSjohansen } arc_buf_contents_t; 142fa9e4066Sahrens 1435a98e54bSBrendan Gregg - Sun Microsystems /* 1445a98e54bSBrendan Gregg - Sun Microsystems * The following breakdows of arc_size exist for kstat only. 1455a98e54bSBrendan Gregg - Sun Microsystems */ 1465a98e54bSBrendan Gregg - Sun Microsystems typedef enum arc_space_type { 1475a98e54bSBrendan Gregg - Sun Microsystems ARC_SPACE_DATA, 1484076b1bfSPrakash Surya ARC_SPACE_META, 1495a98e54bSBrendan Gregg - Sun Microsystems ARC_SPACE_HDRS, 1505a98e54bSBrendan Gregg - Sun Microsystems ARC_SPACE_L2HDRS, 1515a98e54bSBrendan Gregg - Sun Microsystems ARC_SPACE_OTHER, 15254811da5SToomas Soome ARC_SPACE_BONUS, 1535a98e54bSBrendan Gregg - Sun Microsystems ARC_SPACE_NUMTYPES 1545a98e54bSBrendan Gregg - Sun Microsystems } arc_space_type_t; 1555a98e54bSBrendan Gregg - Sun Microsystems 1565a98e54bSBrendan Gregg - Sun Microsystems void arc_space_consume(uint64_t space, arc_space_type_t type); 1575a98e54bSBrendan Gregg - Sun Microsystems void arc_space_return(uint64_t space, arc_space_type_t type); 1585602294fSDan Kimmel boolean_t arc_is_metadata(arc_buf_t *buf); 1595602294fSDan Kimmel enum zio_compress arc_get_compression(arc_buf_t *buf); 1605602294fSDan Kimmel int arc_decompress(arc_buf_t *buf); 1615602294fSDan Kimmel arc_buf_t *arc_alloc_buf(spa_t *spa, void *tag, arc_buf_contents_t type, 1625602294fSDan Kimmel int32_t size); 1635602294fSDan Kimmel arc_buf_t *arc_alloc_compressed_buf(spa_t *spa, void *tag, 1645602294fSDan Kimmel uint64_t psize, uint64_t lsize, enum zio_compress compression_type); 1655602294fSDan Kimmel arc_buf_t *arc_loan_buf(spa_t *spa, boolean_t is_metadata, int size); 1665602294fSDan Kimmel arc_buf_t *arc_loan_compressed_buf(spa_t *spa, uint64_t psize, uint64_t lsize, 1675602294fSDan Kimmel enum zio_compress compression_type); 1682fdbea25SAleksandr Guzovskiy void arc_return_buf(arc_buf_t *buf, void *tag); 169c242f9a0Schunli zhang - Sun Microsystems - Irvine United States void arc_loan_inuse_buf(arc_buf_t *buf, void *tag); 170dcbf3bd6SGeorge Wilson void arc_buf_destroy(arc_buf_t *buf, void *tag); 171fa9e4066Sahrens int arc_buf_size(arc_buf_t *buf); 1725602294fSDan Kimmel int arc_buf_lsize(arc_buf_t *buf); 173*7b38fab6SAlexander Motin void arc_buf_access(arc_buf_t *buf); 174fa9e4066Sahrens void arc_release(arc_buf_t *buf, void *tag); 175fa9e4066Sahrens int arc_released(arc_buf_t *buf); 1766b4acc8bSahrens void arc_buf_freeze(arc_buf_t *buf); 1776b4acc8bSahrens void arc_buf_thaw(arc_buf_t *buf); 178ea8dc4b6Seschrock #ifdef ZFS_DEBUG 179ea8dc4b6Seschrock int arc_referenced(arc_buf_t *buf); 180ea8dc4b6Seschrock #endif 181fa9e4066Sahrens 1821b912ec7SGeorge Wilson int arc_read(zio_t *pio, spa_t *spa, const blkptr_t *bp, 18369962b56SMatthew Ahrens arc_done_func_t *done, void *private, zio_priority_t priority, int flags, 1847adb730bSGeorge Wilson arc_flags_t *arc_flags, const zbookmark_phys_t *zb); 185b24ab676SJeff Bonwick zio_t *arc_write(zio_t *pio, spa_t *spa, uint64_t txg, 186dcbf3bd6SGeorge Wilson blkptr_t *bp, arc_buf_t *buf, boolean_t l2arc, const zio_prop_t *zp, 1878df0bcf0SPaul Dagnelie arc_done_func_t *ready, arc_done_func_t *child_ready, 1888df0bcf0SPaul Dagnelie arc_done_func_t *physdone, arc_done_func_t *done, 1898df0bcf0SPaul Dagnelie void *private, zio_priority_t priority, int zio_flags, 1908df0bcf0SPaul Dagnelie const zbookmark_phys_t *zb); 1916e6d5868SMatthew Ahrens void arc_freed(spa_t *spa, const blkptr_t *bp); 192fa9e4066Sahrens 193244781f1SPrakash Surya void arc_flush(spa_t *spa, boolean_t retry); 1941ab7f2deSmaybee void arc_tempreserve_clear(uint64_t reserve); 195abe1fd01SDon Brady int arc_tempreserve_space(spa_t *spa, uint64_t reserve, uint64_t txg); 196fa9e4066Sahrens 197dcbf3bd6SGeorge Wilson uint64_t arc_max_bytes(void); 198fa9e4066Sahrens void arc_init(void); 199fa9e4066Sahrens void arc_fini(void); 200fa9e4066Sahrens 201fa94a07fSbrendan /* 202fa94a07fSbrendan * Level 2 ARC 203fa94a07fSbrendan */ 204fa94a07fSbrendan 205573ca77eSGeorge Wilson void l2arc_add_vdev(spa_t *spa, vdev_t *vd); 206fa94a07fSbrendan void l2arc_remove_vdev(vdev_t *vd); 207c5904d13Seschrock boolean_t l2arc_vdev_present(vdev_t *vd); 208fa94a07fSbrendan void l2arc_init(void); 209fa94a07fSbrendan void l2arc_fini(void); 210e14bb325SJeff Bonwick void l2arc_start(void); 211e14bb325SJeff Bonwick void l2arc_stop(void); 212fa94a07fSbrendan 213cd1c8b85SMatthew Ahrens #ifndef _KERNEL 214cd1c8b85SMatthew Ahrens extern boolean_t arc_watch; 215cd1c8b85SMatthew Ahrens extern int arc_procfd; 216cd1c8b85SMatthew Ahrens #endif 217cd1c8b85SMatthew Ahrens 218fa9e4066Sahrens #ifdef __cplusplus 219fa9e4066Sahrens } 220fa9e4066Sahrens #endif 221fa9e4066Sahrens 222fa9e4066Sahrens #endif /* _SYS_ARC_H */ 223