xref: /titanic_44/usr/src/uts/common/fs/zfs/sys/arc.h (revision e071a2331d021444298a886d7eedd7140ff2433b)
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 
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 */
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,
887adb730bSGeorge Wilson } arc_flags_t;
897adb730bSGeorge Wilson 
90fa9e4066Sahrens struct arc_buf {
91fa9e4066Sahrens 	arc_buf_hdr_t		*b_hdr;
92fa9e4066Sahrens 	arc_buf_t		*b_next;
933f9d6ad7SLin Ling 	kmutex_t		b_evict_lock;
94fa9e4066Sahrens 	void			*b_data;
95ea8dc4b6Seschrock 	arc_evict_func_t	*b_efunc;
96ea8dc4b6Seschrock 	void			*b_private;
97fa9e4066Sahrens };
98fa9e4066Sahrens 
99ad23a2dbSjohansen typedef enum arc_buf_contents {
100ad23a2dbSjohansen 	ARC_BUFC_DATA,				/* buffer contains data */
1010e8c6158Smaybee 	ARC_BUFC_METADATA,			/* buffer contains metadata */
1020e8c6158Smaybee 	ARC_BUFC_NUMTYPES
103ad23a2dbSjohansen } arc_buf_contents_t;
104fa9e4066Sahrens 
1055a98e54bSBrendan Gregg - Sun Microsystems /*
1065a98e54bSBrendan Gregg - Sun Microsystems  * The following breakdows of arc_size exist for kstat only.
1075a98e54bSBrendan Gregg - Sun Microsystems  */
1085a98e54bSBrendan Gregg - Sun Microsystems typedef enum arc_space_type {
1095a98e54bSBrendan Gregg - Sun Microsystems 	ARC_SPACE_DATA,
1104076b1bfSPrakash Surya 	ARC_SPACE_META,
1115a98e54bSBrendan Gregg - Sun Microsystems 	ARC_SPACE_HDRS,
1125a98e54bSBrendan Gregg - Sun Microsystems 	ARC_SPACE_L2HDRS,
1135a98e54bSBrendan Gregg - Sun Microsystems 	ARC_SPACE_OTHER,
1145a98e54bSBrendan Gregg - Sun Microsystems 	ARC_SPACE_NUMTYPES
1155a98e54bSBrendan Gregg - Sun Microsystems } arc_space_type_t;
1165a98e54bSBrendan Gregg - Sun Microsystems 
1175a98e54bSBrendan Gregg - Sun Microsystems void arc_space_consume(uint64_t space, arc_space_type_t type);
1185a98e54bSBrendan Gregg - Sun Microsystems void arc_space_return(uint64_t space, arc_space_type_t type);
119ad23a2dbSjohansen arc_buf_t *arc_buf_alloc(spa_t *spa, int size, void *tag,
120ad23a2dbSjohansen     arc_buf_contents_t type);
1212fdbea25SAleksandr Guzovskiy arc_buf_t *arc_loan_buf(spa_t *spa, int size);
1222fdbea25SAleksandr Guzovskiy void arc_return_buf(arc_buf_t *buf, void *tag);
123c242f9a0Schunli zhang - Sun Microsystems - Irvine United States void arc_loan_inuse_buf(arc_buf_t *buf, void *tag);
124ea8dc4b6Seschrock void arc_buf_add_ref(arc_buf_t *buf, void *tag);
1253b2aab18SMatthew Ahrens boolean_t arc_buf_remove_ref(arc_buf_t *buf, void *tag);
126fa9e4066Sahrens int arc_buf_size(arc_buf_t *buf);
127fa9e4066Sahrens void arc_release(arc_buf_t *buf, void *tag);
128fa9e4066Sahrens int arc_released(arc_buf_t *buf);
1296b4acc8bSahrens void arc_buf_freeze(arc_buf_t *buf);
1306b4acc8bSahrens void arc_buf_thaw(arc_buf_t *buf);
1319253d63dSGeorge Wilson boolean_t arc_buf_eviction_needed(arc_buf_t *buf);
132ea8dc4b6Seschrock #ifdef ZFS_DEBUG
133ea8dc4b6Seschrock int arc_referenced(arc_buf_t *buf);
134ea8dc4b6Seschrock #endif
135fa9e4066Sahrens 
1361b912ec7SGeorge Wilson int arc_read(zio_t *pio, spa_t *spa, const blkptr_t *bp,
13769962b56SMatthew Ahrens     arc_done_func_t *done, void *private, zio_priority_t priority, int flags,
1387adb730bSGeorge Wilson     arc_flags_t *arc_flags, const zbookmark_phys_t *zb);
139b24ab676SJeff Bonwick zio_t *arc_write(zio_t *pio, spa_t *spa, uint64_t txg,
140aad02571SSaso Kiselkov     blkptr_t *bp, arc_buf_t *buf, boolean_t l2arc, boolean_t l2arc_compress,
14169962b56SMatthew Ahrens     const zio_prop_t *zp, arc_done_func_t *ready, arc_done_func_t *physdone,
14269962b56SMatthew Ahrens     arc_done_func_t *done, void *private, zio_priority_t priority,
1437802d7bfSMatthew Ahrens     int zio_flags, const zbookmark_phys_t *zb);
1446e6d5868SMatthew Ahrens void arc_freed(spa_t *spa, const blkptr_t *bp);
145fa9e4066Sahrens 
146ea8dc4b6Seschrock void arc_set_callback(arc_buf_t *buf, arc_evict_func_t *func, void *private);
147bbfa8ea8SMatthew Ahrens boolean_t arc_clear_callback(arc_buf_t *buf);
148ea8dc4b6Seschrock 
149244781f1SPrakash Surya void arc_flush(spa_t *spa, boolean_t retry);
1501ab7f2deSmaybee void arc_tempreserve_clear(uint64_t reserve);
1511ab7f2deSmaybee int arc_tempreserve_space(uint64_t reserve, uint64_t txg);
152fa9e4066Sahrens 
153fa9e4066Sahrens void arc_init(void);
154fa9e4066Sahrens void arc_fini(void);
155fa9e4066Sahrens 
156fa94a07fSbrendan /*
157fa94a07fSbrendan  * Level 2 ARC
158fa94a07fSbrendan  */
159fa94a07fSbrendan 
1602142e035SSaso Kiselkov void l2arc_add_vdev(spa_t *spa, vdev_t *vd, boolean_t rebuild);
161fa94a07fSbrendan void l2arc_remove_vdev(vdev_t *vd);
162c5904d13Seschrock boolean_t l2arc_vdev_present(vdev_t *vd);
163fa94a07fSbrendan void l2arc_init(void);
164fa94a07fSbrendan void l2arc_fini(void);
165e14bb325SJeff Bonwick void l2arc_start(void);
166e14bb325SJeff Bonwick void l2arc_stop(void);
1672142e035SSaso Kiselkov void l2arc_spa_rebuild_start(spa_t *spa);
168fa94a07fSbrendan 
169*e071a233SArne Jansen /*
170*e071a233SArne Jansen  * Inspection
171*e071a233SArne Jansen  */
172*e071a233SArne Jansen int arc_dump(int start_bucket, void *buf, size_t bufsize,
173*e071a233SArne Jansen     size_t *returned_bytes);
174*e071a233SArne Jansen 
175cd1c8b85SMatthew Ahrens #ifndef _KERNEL
176cd1c8b85SMatthew Ahrens extern boolean_t arc_watch;
177cd1c8b85SMatthew Ahrens extern int arc_procfd;
178cd1c8b85SMatthew Ahrens #endif
179cd1c8b85SMatthew Ahrens 
180fa9e4066Sahrens #ifdef	__cplusplus
181fa9e4066Sahrens }
182fa9e4066Sahrens #endif
183fa9e4066Sahrens 
184fa9e4066Sahrens #endif /* _SYS_ARC_H */
185