xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/arc.h (revision 8df0bcf0df7622a075cc6e52f659d2fcfdd08cdc)
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.
23*8df0bcf0SPaul Dagnelie  * Copyright (c) 2012, 2016 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 
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 */
67cf6106c8SMatthew Ahrens 	ARC_FLAG_PREDICTIVE_PREFETCH	= 1 << 7,	/* I/O from zfetch */
687adb730bSGeorge Wilson 
697adb730bSGeorge Wilson 	/*
707adb730bSGeorge Wilson 	 * Private ARC flags.  These flags are private ARC only flags that
717adb730bSGeorge Wilson 	 * will show up in b_flags in the arc_hdr_buf_t. These flags should
727adb730bSGeorge Wilson 	 * only be set by ARC code.
737adb730bSGeorge Wilson 	 */
74cf6106c8SMatthew Ahrens 	ARC_FLAG_IN_HASH_TABLE		= 1 << 8,	/* buffer is hashed */
75cf6106c8SMatthew Ahrens 	ARC_FLAG_IO_IN_PROGRESS		= 1 << 9,	/* I/O in progress */
76cf6106c8SMatthew Ahrens 	ARC_FLAG_IO_ERROR		= 1 << 10,	/* I/O failed for buf */
77cf6106c8SMatthew Ahrens 	ARC_FLAG_FREED_IN_READ		= 1 << 11,	/* freed during read */
78cf6106c8SMatthew Ahrens 	ARC_FLAG_BUF_AVAILABLE		= 1 << 12,	/* block not in use */
79cf6106c8SMatthew Ahrens 	ARC_FLAG_INDIRECT		= 1 << 13,	/* indirect block */
80cf6106c8SMatthew Ahrens 	/* Indicates that block was read with ASYNC priority. */
81cf6106c8SMatthew Ahrens 	ARC_FLAG_PRIO_ASYNC_READ	= 1 << 14,
82cf6106c8SMatthew Ahrens 	ARC_FLAG_L2_WRITING		= 1 << 15,	/* write in progress */
83cf6106c8SMatthew Ahrens 	ARC_FLAG_L2_EVICTED		= 1 << 16,	/* evicted during I/O */
84cf6106c8SMatthew Ahrens 	ARC_FLAG_L2_WRITE_HEAD		= 1 << 17,	/* head of write list */
8589c86e32SChris Williamson 	/* indicates that the buffer contains metadata (otherwise, data) */
86cf6106c8SMatthew Ahrens 	ARC_FLAG_BUFC_METADATA		= 1 << 18,
8789c86e32SChris Williamson 
8889c86e32SChris Williamson 	/* Flags specifying whether optional hdr struct fields are defined */
89cf6106c8SMatthew Ahrens 	ARC_FLAG_HAS_L1HDR		= 1 << 19,
90cf6106c8SMatthew Ahrens 	ARC_FLAG_HAS_L2HDR		= 1 << 20,
917adb730bSGeorge Wilson } arc_flags_t;
927adb730bSGeorge Wilson 
93fa9e4066Sahrens struct arc_buf {
94fa9e4066Sahrens 	arc_buf_hdr_t		*b_hdr;
95fa9e4066Sahrens 	arc_buf_t		*b_next;
963f9d6ad7SLin Ling 	kmutex_t		b_evict_lock;
97fa9e4066Sahrens 	void			*b_data;
98ea8dc4b6Seschrock 	arc_evict_func_t	*b_efunc;
99ea8dc4b6Seschrock 	void			*b_private;
100fa9e4066Sahrens };
101fa9e4066Sahrens 
102ad23a2dbSjohansen typedef enum arc_buf_contents {
103ad23a2dbSjohansen 	ARC_BUFC_DATA,				/* buffer contains data */
1040e8c6158Smaybee 	ARC_BUFC_METADATA,			/* buffer contains metadata */
1050e8c6158Smaybee 	ARC_BUFC_NUMTYPES
106ad23a2dbSjohansen } arc_buf_contents_t;
107fa9e4066Sahrens 
1085a98e54bSBrendan Gregg - Sun Microsystems /*
1095a98e54bSBrendan Gregg - Sun Microsystems  * The following breakdows of arc_size exist for kstat only.
1105a98e54bSBrendan Gregg - Sun Microsystems  */
1115a98e54bSBrendan Gregg - Sun Microsystems typedef enum arc_space_type {
1125a98e54bSBrendan Gregg - Sun Microsystems 	ARC_SPACE_DATA,
1134076b1bfSPrakash Surya 	ARC_SPACE_META,
1145a98e54bSBrendan Gregg - Sun Microsystems 	ARC_SPACE_HDRS,
1155a98e54bSBrendan Gregg - Sun Microsystems 	ARC_SPACE_L2HDRS,
1165a98e54bSBrendan Gregg - Sun Microsystems 	ARC_SPACE_OTHER,
1175a98e54bSBrendan Gregg - Sun Microsystems 	ARC_SPACE_NUMTYPES
1185a98e54bSBrendan Gregg - Sun Microsystems } arc_space_type_t;
1195a98e54bSBrendan Gregg - Sun Microsystems 
1205a98e54bSBrendan Gregg - Sun Microsystems void arc_space_consume(uint64_t space, arc_space_type_t type);
1215a98e54bSBrendan Gregg - Sun Microsystems void arc_space_return(uint64_t space, arc_space_type_t type);
122ad23a2dbSjohansen arc_buf_t *arc_buf_alloc(spa_t *spa, int size, void *tag,
123ad23a2dbSjohansen     arc_buf_contents_t type);
1242fdbea25SAleksandr Guzovskiy arc_buf_t *arc_loan_buf(spa_t *spa, int size);
1252fdbea25SAleksandr Guzovskiy void arc_return_buf(arc_buf_t *buf, void *tag);
126c242f9a0Schunli zhang - Sun Microsystems - Irvine United States void arc_loan_inuse_buf(arc_buf_t *buf, void *tag);
127ea8dc4b6Seschrock void arc_buf_add_ref(arc_buf_t *buf, void *tag);
1283b2aab18SMatthew Ahrens boolean_t arc_buf_remove_ref(arc_buf_t *buf, void *tag);
129fa9e4066Sahrens int arc_buf_size(arc_buf_t *buf);
130fa9e4066Sahrens void arc_release(arc_buf_t *buf, void *tag);
131fa9e4066Sahrens int arc_released(arc_buf_t *buf);
1326b4acc8bSahrens void arc_buf_freeze(arc_buf_t *buf);
1336b4acc8bSahrens void arc_buf_thaw(arc_buf_t *buf);
1349253d63dSGeorge Wilson boolean_t arc_buf_eviction_needed(arc_buf_t *buf);
135ea8dc4b6Seschrock #ifdef ZFS_DEBUG
136ea8dc4b6Seschrock int arc_referenced(arc_buf_t *buf);
137ea8dc4b6Seschrock #endif
138fa9e4066Sahrens 
1391b912ec7SGeorge Wilson int arc_read(zio_t *pio, spa_t *spa, const blkptr_t *bp,
14069962b56SMatthew Ahrens     arc_done_func_t *done, void *private, zio_priority_t priority, int flags,
1417adb730bSGeorge Wilson     arc_flags_t *arc_flags, const zbookmark_phys_t *zb);
142b24ab676SJeff Bonwick zio_t *arc_write(zio_t *pio, spa_t *spa, uint64_t txg,
143aad02571SSaso Kiselkov     blkptr_t *bp, arc_buf_t *buf, boolean_t l2arc, boolean_t l2arc_compress,
144*8df0bcf0SPaul Dagnelie     const zio_prop_t *zp,
145*8df0bcf0SPaul Dagnelie     arc_done_func_t *ready, arc_done_func_t *child_ready,
146*8df0bcf0SPaul Dagnelie     arc_done_func_t *physdone, arc_done_func_t *done,
147*8df0bcf0SPaul Dagnelie     void *private, zio_priority_t priority, int zio_flags,
148*8df0bcf0SPaul Dagnelie     const zbookmark_phys_t *zb);
1496e6d5868SMatthew Ahrens void arc_freed(spa_t *spa, const blkptr_t *bp);
150fa9e4066Sahrens 
151ea8dc4b6Seschrock void arc_set_callback(arc_buf_t *buf, arc_evict_func_t *func, void *private);
152bbfa8ea8SMatthew Ahrens boolean_t arc_clear_callback(arc_buf_t *buf);
153ea8dc4b6Seschrock 
154244781f1SPrakash Surya void arc_flush(spa_t *spa, boolean_t retry);
1551ab7f2deSmaybee void arc_tempreserve_clear(uint64_t reserve);
1561ab7f2deSmaybee int arc_tempreserve_space(uint64_t reserve, uint64_t txg);
157fa9e4066Sahrens 
158fa9e4066Sahrens void arc_init(void);
159fa9e4066Sahrens void arc_fini(void);
160fa9e4066Sahrens 
161fa94a07fSbrendan /*
162fa94a07fSbrendan  * Level 2 ARC
163fa94a07fSbrendan  */
164fa94a07fSbrendan 
165573ca77eSGeorge Wilson void l2arc_add_vdev(spa_t *spa, vdev_t *vd);
166fa94a07fSbrendan void l2arc_remove_vdev(vdev_t *vd);
167c5904d13Seschrock boolean_t l2arc_vdev_present(vdev_t *vd);
168fa94a07fSbrendan void l2arc_init(void);
169fa94a07fSbrendan void l2arc_fini(void);
170e14bb325SJeff Bonwick void l2arc_start(void);
171e14bb325SJeff Bonwick void l2arc_stop(void);
172fa94a07fSbrendan 
173cd1c8b85SMatthew Ahrens #ifndef _KERNEL
174cd1c8b85SMatthew Ahrens extern boolean_t arc_watch;
175cd1c8b85SMatthew Ahrens extern int arc_procfd;
176cd1c8b85SMatthew Ahrens #endif
177cd1c8b85SMatthew Ahrens 
178fa9e4066Sahrens #ifdef	__cplusplus
179fa9e4066Sahrens }
180fa9e4066Sahrens #endif
181fa9e4066Sahrens 
182fa9e4066Sahrens #endif /* _SYS_ARC_H */
183