xref: /freebsd/sys/contrib/openzfs/include/sys/arc_impl.h (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or https://opensource.org/licenses/CDDL-1.0.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright (c) 2013, Delphix. All rights reserved.
25  * Copyright (c) 2013, Saso Kiselkov. All rights reserved.
26  * Copyright (c) 2013, Nexenta Systems, Inc.  All rights reserved.
27  * Copyright (c) 2020, George Amanakis. All rights reserved.
28  */
29 
30 #ifndef _SYS_ARC_IMPL_H
31 #define	_SYS_ARC_IMPL_H
32 
33 #include <sys/arc.h>
34 #include <sys/multilist.h>
35 #include <sys/zio_crypt.h>
36 #include <sys/zthr.h>
37 #include <sys/aggsum.h>
38 #include <sys/wmsum.h>
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 /*
45  * Note that buffers can be in one of 6 states:
46  *	ARC_anon	- anonymous (discussed below)
47  *	ARC_mru		- recently used, currently cached
48  *	ARC_mru_ghost	- recently used, no longer in cache
49  *	ARC_mfu		- frequently used, currently cached
50  *	ARC_mfu_ghost	- frequently used, no longer in cache
51  *	ARC_uncached	- uncacheable prefetch, to be evicted
52  *	ARC_l2c_only	- exists in L2ARC but not other states
53  * When there are no active references to the buffer, they are
54  * are linked onto a list in one of these arc states.  These are
55  * the only buffers that can be evicted or deleted.  Within each
56  * state there are multiple lists, one for meta-data and one for
57  * non-meta-data.  Meta-data (indirect blocks, blocks of dnodes,
58  * etc.) is tracked separately so that it can be managed more
59  * explicitly: favored over data, limited explicitly.
60  *
61  * Anonymous buffers are buffers that are not associated with
62  * a DVA.  These are buffers that hold dirty block copies
63  * before they are written to stable storage.  By definition,
64  * they are "ref'd" and are considered part of arc_mru
65  * that cannot be freed.  Generally, they will acquire a DVA
66  * as they are written and migrate onto the arc_mru list.
67  *
68  * The ARC_l2c_only state is for buffers that are in the second
69  * level ARC but no longer in any of the ARC_m* lists.  The second
70  * level ARC itself may also contain buffers that are in any of
71  * the ARC_m* states - meaning that a buffer can exist in two
72  * places.  The reason for the ARC_l2c_only state is to keep the
73  * buffer header in the hash table, so that reads that hit the
74  * second level ARC benefit from these fast lookups.
75  */
76 
77 typedef struct arc_state {
78 	/*
79 	 * list of evictable buffers
80 	 */
81 	multilist_t arcs_list[ARC_BUFC_NUMTYPES];
82 	/*
83 	 * supports the "dbufs" kstat
84 	 */
85 	arc_state_type_t arcs_state;
86 	/*
87 	 * total amount of data in this state.
88 	 */
89 	zfs_refcount_t arcs_size[ARC_BUFC_NUMTYPES] ____cacheline_aligned;
90 	/*
91 	 * total amount of evictable data in this state
92 	 */
93 	zfs_refcount_t arcs_esize[ARC_BUFC_NUMTYPES];
94 	/*
95 	 * amount of hit bytes for this state (counted only for ghost states)
96 	 */
97 	wmsum_t arcs_hits[ARC_BUFC_NUMTYPES];
98 } arc_state_t;
99 
100 typedef struct arc_callback arc_callback_t;
101 
102 struct arc_callback {
103 	void			*acb_private;
104 	arc_read_done_func_t	*acb_done;
105 	arc_buf_t		*acb_buf;
106 	boolean_t		acb_encrypted;
107 	boolean_t		acb_compressed;
108 	boolean_t		acb_noauth;
109 	boolean_t		acb_nobuf;
110 	boolean_t		acb_wait;
111 	int			acb_wait_error;
112 	kmutex_t		acb_wait_lock;
113 	kcondvar_t		acb_wait_cv;
114 	zbookmark_phys_t	acb_zb;
115 	zio_t			*acb_zio_dummy;
116 	zio_t			*acb_zio_head;
117 	arc_callback_t		*acb_prev;
118 	arc_callback_t		*acb_next;
119 };
120 
121 typedef struct arc_write_callback arc_write_callback_t;
122 
123 struct arc_write_callback {
124 	void			*awcb_private;
125 	arc_write_done_func_t	*awcb_ready;
126 	arc_write_done_func_t	*awcb_children_ready;
127 	arc_write_done_func_t	*awcb_done;
128 	arc_buf_t		*awcb_buf;
129 };
130 
131 /*
132  * ARC buffers are separated into multiple structs as a memory saving measure:
133  *   - Common fields struct, always defined, and embedded within it:
134  *       - L2-only fields, always allocated but undefined when not in L2ARC
135  *       - L1-only fields, only allocated when in L1ARC
136  *
137  *           Buffer in L1                     Buffer only in L2
138  *    +------------------------+          +------------------------+
139  *    | arc_buf_hdr_t          |          | arc_buf_hdr_t          |
140  *    |                        |          |                        |
141  *    |                        |          |                        |
142  *    |                        |          |                        |
143  *    +------------------------+          +------------------------+
144  *    | l2arc_buf_hdr_t        |          | l2arc_buf_hdr_t        |
145  *    | (undefined if L1-only) |          |                        |
146  *    +------------------------+          +------------------------+
147  *    | l1arc_buf_hdr_t        |
148  *    |                        |
149  *    |                        |
150  *    |                        |
151  *    |                        |
152  *    +------------------------+
153  *
154  * Because it's possible for the L2ARC to become extremely large, we can wind
155  * up eating a lot of memory in L2ARC buffer headers, so the size of a header
156  * is minimized by only allocating the fields necessary for an L1-cached buffer
157  * when a header is actually in the L1 cache. The sub-headers (l1arc_buf_hdr and
158  * l2arc_buf_hdr) are embedded rather than allocated separately to save a couple
159  * words in pointers. arc_hdr_realloc() is used to switch a header between
160  * these two allocation states.
161  */
162 typedef struct l1arc_buf_hdr {
163 	/* protected by arc state mutex */
164 	arc_state_t		*b_state;
165 	multilist_node_t	b_arc_node;
166 
167 	/* protected by hash lock */
168 	clock_t			b_arc_access;
169 	uint32_t		b_mru_hits;
170 	uint32_t		b_mru_ghost_hits;
171 	uint32_t		b_mfu_hits;
172 	uint32_t		b_mfu_ghost_hits;
173 	uint8_t			b_byteswap;
174 	arc_buf_t		*b_buf;
175 
176 	/* self protecting */
177 	zfs_refcount_t		b_refcnt;
178 
179 	arc_callback_t		*b_acb;
180 	abd_t			*b_pabd;
181 
182 #ifdef ZFS_DEBUG
183 	zio_cksum_t		*b_freeze_cksum;
184 	kmutex_t		b_freeze_lock;
185 #endif
186 } l1arc_buf_hdr_t;
187 
188 typedef enum l2arc_dev_hdr_flags_t {
189 	L2ARC_DEV_HDR_EVICT_FIRST = (1 << 0)	/* mirror of l2ad_first */
190 } l2arc_dev_hdr_flags_t;
191 
192 /*
193  * Pointer used in persistent L2ARC (for pointing to log blocks).
194  */
195 typedef struct l2arc_log_blkptr {
196 	/*
197 	 * Offset of log block within the device, in bytes
198 	 */
199 	uint64_t	lbp_daddr;
200 	/*
201 	 * Aligned payload size (in bytes) of the log block
202 	 */
203 	uint64_t	lbp_payload_asize;
204 	/*
205 	 * Offset in bytes of the first buffer in the payload
206 	 */
207 	uint64_t	lbp_payload_start;
208 	/*
209 	 * lbp_prop has the following format:
210 	 *	* logical size (in bytes)
211 	 *	* aligned (after compression) size (in bytes)
212 	 *	* compression algorithm (we always LZ4-compress l2arc logs)
213 	 *	* checksum algorithm (used for lbp_cksum)
214 	 */
215 	uint64_t	lbp_prop;
216 	zio_cksum_t	lbp_cksum;	/* checksum of log */
217 } l2arc_log_blkptr_t;
218 
219 /*
220  * The persistent L2ARC device header.
221  * Byte order of magic determines whether 64-bit bswap of fields is necessary.
222  */
223 typedef struct l2arc_dev_hdr_phys {
224 	uint64_t	dh_magic;	/* L2ARC_DEV_HDR_MAGIC */
225 	uint64_t	dh_version;	/* Persistent L2ARC version */
226 
227 	/*
228 	 * Global L2ARC device state and metadata.
229 	 */
230 	uint64_t	dh_spa_guid;
231 	uint64_t	dh_vdev_guid;
232 	uint64_t	dh_log_entries;		/* mirror of l2ad_log_entries */
233 	uint64_t	dh_evict;		/* evicted offset in bytes */
234 	uint64_t	dh_flags;		/* l2arc_dev_hdr_flags_t */
235 	/*
236 	 * Used in zdb.c for determining if a log block is valid, in the same
237 	 * way that l2arc_rebuild() does.
238 	 */
239 	uint64_t	dh_start;		/* mirror of l2ad_start */
240 	uint64_t	dh_end;			/* mirror of l2ad_end */
241 	/*
242 	 * Start of log block chain. [0] -> newest log, [1] -> one older (used
243 	 * for initiating prefetch).
244 	 */
245 	l2arc_log_blkptr_t	dh_start_lbps[2];
246 	/*
247 	 * Aligned size of all log blocks as accounted by vdev_space_update().
248 	 */
249 	uint64_t	dh_lb_asize;		/* mirror of l2ad_lb_asize */
250 	uint64_t	dh_lb_count;		/* mirror of l2ad_lb_count */
251 	/*
252 	 * Mirrors of vdev_trim_action_time and vdev_trim_state, used to
253 	 * display when the cache device was fully trimmed for the last
254 	 * time.
255 	 */
256 	uint64_t		dh_trim_action_time;
257 	uint64_t		dh_trim_state;
258 	const uint64_t		dh_pad[30];	/* pad to 512 bytes */
259 	zio_eck_t		dh_tail;
260 } l2arc_dev_hdr_phys_t;
261 _Static_assert(sizeof (l2arc_dev_hdr_phys_t) == SPA_MINBLOCKSIZE,
262 	"l2arc_dev_hdr_phys_t wrong size");
263 
264 /*
265  * A single ARC buffer header entry in a l2arc_log_blk_phys_t.
266  */
267 typedef struct l2arc_log_ent_phys {
268 	dva_t			le_dva;		/* dva of buffer */
269 	uint64_t		le_birth;	/* birth txg of buffer */
270 	/*
271 	 * le_prop has the following format:
272 	 *	* logical size (in bytes)
273 	 *	* physical (compressed) size (in bytes)
274 	 *	* compression algorithm
275 	 *	* object type (used to restore arc_buf_contents_t)
276 	 *	* protected status (used for encryption)
277 	 *	* prefetch status (used in l2arc_read_done())
278 	 */
279 	uint64_t		le_prop;
280 	uint64_t		le_daddr;	/* buf location on l2dev */
281 	uint64_t		le_complevel;
282 	/*
283 	 * We pad the size of each entry to a power of 2 so that the size of
284 	 * l2arc_log_blk_phys_t is power-of-2 aligned with SPA_MINBLOCKSHIFT,
285 	 * because of the L2ARC_SET_*SIZE macros.
286 	 */
287 	const uint64_t		le_pad[2];	/* pad to 64 bytes	 */
288 } l2arc_log_ent_phys_t;
289 
290 #define	L2ARC_LOG_BLK_MAX_ENTRIES	(1022)
291 
292 /*
293  * A log block of up to 1022 ARC buffer log entries, chained into the
294  * persistent L2ARC metadata linked list. Byte order of magic determines
295  * whether 64-bit bswap of fields is necessary.
296  */
297 typedef struct l2arc_log_blk_phys {
298 	uint64_t		lb_magic;	/* L2ARC_LOG_BLK_MAGIC */
299 	/*
300 	 * There are 2 chains (headed by dh_start_lbps[2]), and this field
301 	 * points back to the previous block in this chain. We alternate
302 	 * which chain we append to, so they are time-wise and offset-wise
303 	 * interleaved, but that is an optimization rather than for
304 	 * correctness.
305 	 */
306 	l2arc_log_blkptr_t	lb_prev_lbp;	/* pointer to prev log block */
307 	/*
308 	 * Pad header section to 128 bytes
309 	 */
310 	uint64_t		lb_pad[7];
311 	/* Payload */
312 	l2arc_log_ent_phys_t	lb_entries[L2ARC_LOG_BLK_MAX_ENTRIES];
313 } l2arc_log_blk_phys_t;				/* 64K total */
314 
315 /*
316  * The size of l2arc_log_blk_phys_t has to be power-of-2 aligned with
317  * SPA_MINBLOCKSHIFT because of L2BLK_SET_*SIZE macros.
318  */
319 _Static_assert(IS_P2ALIGNED(sizeof (l2arc_log_blk_phys_t),
320     1ULL << SPA_MINBLOCKSHIFT), "l2arc_log_blk_phys_t misaligned");
321 _Static_assert(sizeof (l2arc_log_blk_phys_t) >= SPA_MINBLOCKSIZE,
322 	"l2arc_log_blk_phys_t too small");
323 _Static_assert(sizeof (l2arc_log_blk_phys_t) <= SPA_MAXBLOCKSIZE,
324 	"l2arc_log_blk_phys_t too big");
325 
326 /*
327  * These structures hold in-flight abd buffers for log blocks as they're being
328  * written to the L2ARC device.
329  */
330 typedef struct l2arc_lb_abd_buf {
331 	abd_t		*abd;
332 	list_node_t	node;
333 } l2arc_lb_abd_buf_t;
334 
335 /*
336  * These structures hold pointers to log blocks present on the L2ARC device.
337  */
338 typedef struct l2arc_lb_ptr_buf {
339 	l2arc_log_blkptr_t	*lb_ptr;
340 	list_node_t		node;
341 } l2arc_lb_ptr_buf_t;
342 
343 /* Macros for setting fields in le_prop and lbp_prop */
344 #define	L2BLK_GET_LSIZE(field)	\
345 	BF64_GET_SB((field), 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1)
346 #define	L2BLK_SET_LSIZE(field, x)	\
347 	BF64_SET_SB((field), 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1, x)
348 #define	L2BLK_GET_PSIZE(field)	\
349 	BF64_GET_SB((field), 16, SPA_PSIZEBITS, SPA_MINBLOCKSHIFT, 1)
350 #define	L2BLK_SET_PSIZE(field, x)	\
351 	BF64_SET_SB((field), 16, SPA_PSIZEBITS, SPA_MINBLOCKSHIFT, 1, x)
352 #define	L2BLK_GET_COMPRESS(field)	\
353 	BF64_GET((field), 32, SPA_COMPRESSBITS)
354 #define	L2BLK_SET_COMPRESS(field, x)	\
355 	BF64_SET((field), 32, SPA_COMPRESSBITS, x)
356 #define	L2BLK_GET_PREFETCH(field)	BF64_GET((field), 39, 1)
357 #define	L2BLK_SET_PREFETCH(field, x)	BF64_SET((field), 39, 1, x)
358 #define	L2BLK_GET_CHECKSUM(field)	BF64_GET((field), 40, 8)
359 #define	L2BLK_SET_CHECKSUM(field, x)	BF64_SET((field), 40, 8, x)
360 /* +/- 1 here are to keep compatibility after ARC_BUFC_INVALID removal. */
361 #define	L2BLK_GET_TYPE(field)		(BF64_GET((field), 48, 8) - 1)
362 #define	L2BLK_SET_TYPE(field, x)	BF64_SET((field), 48, 8, (x) + 1)
363 #define	L2BLK_GET_PROTECTED(field)	BF64_GET((field), 56, 1)
364 #define	L2BLK_SET_PROTECTED(field, x)	BF64_SET((field), 56, 1, x)
365 #define	L2BLK_GET_STATE(field)		BF64_GET((field), 57, 4)
366 #define	L2BLK_SET_STATE(field, x)	BF64_SET((field), 57, 4, x)
367 
368 #define	PTR_SWAP(x, y)		\
369 	do {			\
370 		void *tmp = (x);\
371 		x = y;		\
372 		y = tmp;	\
373 	} while (0)
374 
375 #define	L2ARC_DEV_HDR_MAGIC	0x5a46534341434845LLU	/* ASCII: "ZFSCACHE" */
376 #define	L2ARC_LOG_BLK_MAGIC	0x4c4f47424c4b4844LLU	/* ASCII: "LOGBLKHD" */
377 
378 /*
379  * L2ARC Internals
380  */
381 typedef struct l2arc_dev {
382 	vdev_t			*l2ad_vdev;	/* can be NULL during remove */
383 	spa_t			*l2ad_spa;	/* can be NULL during remove */
384 	uint64_t		l2ad_hand;	/* next write location */
385 	uint64_t		l2ad_start;	/* first addr on device */
386 	uint64_t		l2ad_end;	/* last addr on device */
387 	boolean_t		l2ad_first;	/* first sweep through */
388 	boolean_t		l2ad_writing;	/* currently writing */
389 	kmutex_t		l2ad_mtx;	/* lock for buffer list */
390 	list_t			l2ad_buflist;	/* buffer list */
391 	list_node_t		l2ad_node;	/* device list node */
392 	zfs_refcount_t		l2ad_alloc;	/* allocated bytes */
393 	/*
394 	 * Persistence-related stuff
395 	 */
396 	l2arc_dev_hdr_phys_t	*l2ad_dev_hdr;	/* persistent device header */
397 	uint64_t		l2ad_dev_hdr_asize; /* aligned hdr size */
398 	l2arc_log_blk_phys_t	l2ad_log_blk;	/* currently open log block */
399 	int			l2ad_log_ent_idx; /* index into cur log blk */
400 	/* Number of bytes in current log block's payload */
401 	uint64_t		l2ad_log_blk_payload_asize;
402 	/*
403 	 * Offset (in bytes) of the first buffer in current log block's
404 	 * payload.
405 	 */
406 	uint64_t		l2ad_log_blk_payload_start;
407 	/* Flag indicating whether a rebuild is scheduled or is going on */
408 	boolean_t		l2ad_rebuild;
409 	boolean_t		l2ad_rebuild_cancel;
410 	boolean_t		l2ad_rebuild_began;
411 	uint64_t		l2ad_log_entries;   /* entries per log blk  */
412 	uint64_t		l2ad_evict;	 /* evicted offset in bytes */
413 	/* List of pointers to log blocks present in the L2ARC device */
414 	list_t			l2ad_lbptr_list;
415 	/*
416 	 * Aligned size of all log blocks as accounted by vdev_space_update().
417 	 */
418 	zfs_refcount_t		l2ad_lb_asize;
419 	/*
420 	 * Number of log blocks present on the device.
421 	 */
422 	zfs_refcount_t		l2ad_lb_count;
423 	boolean_t		l2ad_trim_all; /* TRIM whole device */
424 } l2arc_dev_t;
425 
426 /*
427  * Encrypted blocks will need to be stored encrypted on the L2ARC
428  * disk as they appear in the main pool. In order for this to work we
429  * need to pass around the encryption parameters so they can be used
430  * to write data to the L2ARC. This struct is only defined in the
431  * arc_buf_hdr_t if the L1 header is defined and has the ARC_FLAG_ENCRYPTED
432  * flag set.
433  */
434 typedef struct arc_buf_hdr_crypt {
435 	abd_t			*b_rabd;	/* raw encrypted data */
436 
437 	/* dsobj for looking up encryption key for l2arc encryption */
438 	uint64_t		b_dsobj;
439 
440 	dmu_object_type_t	b_ot;		/* object type */
441 
442 	/* encryption parameters */
443 	uint8_t			b_salt[ZIO_DATA_SALT_LEN];
444 	uint8_t			b_iv[ZIO_DATA_IV_LEN];
445 
446 	/*
447 	 * Technically this could be removed since we will always be able to
448 	 * get the mac from the bp when we need it. However, it is inconvenient
449 	 * for callers of arc code to have to pass a bp in all the time. This
450 	 * also allows us to assert that L2ARC data is properly encrypted to
451 	 * match the data in the main storage pool.
452 	 */
453 	uint8_t			b_mac[ZIO_DATA_MAC_LEN];
454 } arc_buf_hdr_crypt_t;
455 
456 typedef struct l2arc_buf_hdr {
457 	/* protected by arc_buf_hdr mutex */
458 	l2arc_dev_t		*b_dev;		/* L2ARC device */
459 	uint64_t		b_daddr;	/* disk address, offset byte */
460 	uint32_t		b_hits;
461 	arc_state_type_t	b_arcs_state;
462 	list_node_t		b_l2node;
463 } l2arc_buf_hdr_t;
464 
465 typedef struct l2arc_write_callback {
466 	l2arc_dev_t	*l2wcb_dev;		/* device info */
467 	arc_buf_hdr_t	*l2wcb_head;		/* head of write buflist */
468 	/* in-flight list of log blocks */
469 	list_t		l2wcb_abd_list;
470 } l2arc_write_callback_t;
471 
472 struct arc_buf_hdr {
473 	/* protected by hash lock */
474 	dva_t			b_dva;
475 	uint64_t		b_birth;
476 
477 	arc_buf_contents_t	b_type;
478 	uint8_t			b_complevel;
479 	uint8_t			b_reserved1;	/* used for 4 byte alignment */
480 	uint16_t		b_l2size;	/* alignment or L2-only size */
481 	arc_buf_hdr_t		*b_hash_next;
482 	arc_flags_t		b_flags;
483 
484 	/*
485 	 * This field stores the size of the data buffer after
486 	 * compression, and is set in the arc's zio completion handlers.
487 	 * It is in units of SPA_MINBLOCKSIZE (e.g. 1 == 512 bytes).
488 	 *
489 	 * While the block pointers can store up to 32MB in their psize
490 	 * field, we can only store up to 32MB minus 512B. This is due
491 	 * to the bp using a bias of 1, whereas we use a bias of 0 (i.e.
492 	 * a field of zeros represents 512B in the bp). We can't use a
493 	 * bias of 1 since we need to reserve a psize of zero, here, to
494 	 * represent holes and embedded blocks.
495 	 *
496 	 * This isn't a problem in practice, since the maximum size of a
497 	 * buffer is limited to 16MB, so we never need to store 32MB in
498 	 * this field. Even in the upstream illumos code base, the
499 	 * maximum size of a buffer is limited to 16MB.
500 	 */
501 	uint16_t		b_psize;
502 
503 	/*
504 	 * This field stores the size of the data buffer before
505 	 * compression, and cannot change once set. It is in units
506 	 * of SPA_MINBLOCKSIZE (e.g. 2 == 1024 bytes)
507 	 */
508 	uint16_t		b_lsize;	/* immutable */
509 	uint64_t		b_spa;		/* immutable */
510 
511 	/* L2ARC fields. Undefined when not in L2ARC. */
512 	l2arc_buf_hdr_t		b_l2hdr;
513 	/* L1ARC fields. Undefined when in l2arc_only state */
514 	l1arc_buf_hdr_t		b_l1hdr;
515 	/*
516 	 * Encryption parameters. Defined only when ARC_FLAG_ENCRYPTED
517 	 * is set and the L1 header exists.
518 	 */
519 	arc_buf_hdr_crypt_t b_crypt_hdr;
520 };
521 
522 typedef struct arc_stats {
523 	/* Number of requests that were satisfied without I/O. */
524 	kstat_named_t arcstat_hits;
525 	/* Number of requests for which I/O was already running. */
526 	kstat_named_t arcstat_iohits;
527 	/* Number of requests for which I/O has to be issued. */
528 	kstat_named_t arcstat_misses;
529 	/* Same three, but specifically for demand data. */
530 	kstat_named_t arcstat_demand_data_hits;
531 	kstat_named_t arcstat_demand_data_iohits;
532 	kstat_named_t arcstat_demand_data_misses;
533 	/* Same three, but specifically for demand metadata. */
534 	kstat_named_t arcstat_demand_metadata_hits;
535 	kstat_named_t arcstat_demand_metadata_iohits;
536 	kstat_named_t arcstat_demand_metadata_misses;
537 	/* Same three, but specifically for prefetch data. */
538 	kstat_named_t arcstat_prefetch_data_hits;
539 	kstat_named_t arcstat_prefetch_data_iohits;
540 	kstat_named_t arcstat_prefetch_data_misses;
541 	/* Same three, but specifically for prefetch metadata. */
542 	kstat_named_t arcstat_prefetch_metadata_hits;
543 	kstat_named_t arcstat_prefetch_metadata_iohits;
544 	kstat_named_t arcstat_prefetch_metadata_misses;
545 	kstat_named_t arcstat_mru_hits;
546 	kstat_named_t arcstat_mru_ghost_hits;
547 	kstat_named_t arcstat_mfu_hits;
548 	kstat_named_t arcstat_mfu_ghost_hits;
549 	kstat_named_t arcstat_uncached_hits;
550 	kstat_named_t arcstat_deleted;
551 	/*
552 	 * Number of buffers that could not be evicted because the hash lock
553 	 * was held by another thread.  The lock may not necessarily be held
554 	 * by something using the same buffer, since hash locks are shared
555 	 * by multiple buffers.
556 	 */
557 	kstat_named_t arcstat_mutex_miss;
558 	/*
559 	 * Number of buffers skipped when updating the access state due to the
560 	 * header having already been released after acquiring the hash lock.
561 	 */
562 	kstat_named_t arcstat_access_skip;
563 	/*
564 	 * Number of buffers skipped because they have I/O in progress, are
565 	 * indirect prefetch buffers that have not lived long enough, or are
566 	 * not from the spa we're trying to evict from.
567 	 */
568 	kstat_named_t arcstat_evict_skip;
569 	/*
570 	 * Number of times arc_evict_state() was unable to evict enough
571 	 * buffers to reach its target amount.
572 	 */
573 	kstat_named_t arcstat_evict_not_enough;
574 	kstat_named_t arcstat_evict_l2_cached;
575 	kstat_named_t arcstat_evict_l2_eligible;
576 	kstat_named_t arcstat_evict_l2_eligible_mfu;
577 	kstat_named_t arcstat_evict_l2_eligible_mru;
578 	kstat_named_t arcstat_evict_l2_ineligible;
579 	kstat_named_t arcstat_evict_l2_skip;
580 	kstat_named_t arcstat_hash_elements;
581 	kstat_named_t arcstat_hash_elements_max;
582 	kstat_named_t arcstat_hash_collisions;
583 	kstat_named_t arcstat_hash_chains;
584 	kstat_named_t arcstat_hash_chain_max;
585 	kstat_named_t arcstat_meta;
586 	kstat_named_t arcstat_pd;
587 	kstat_named_t arcstat_pm;
588 	kstat_named_t arcstat_c;
589 	kstat_named_t arcstat_c_min;
590 	kstat_named_t arcstat_c_max;
591 	kstat_named_t arcstat_size;
592 	/*
593 	 * Number of compressed bytes stored in the arc_buf_hdr_t's b_pabd.
594 	 * Note that the compressed bytes may match the uncompressed bytes
595 	 * if the block is either not compressed or compressed arc is disabled.
596 	 */
597 	kstat_named_t arcstat_compressed_size;
598 	/*
599 	 * Uncompressed size of the data stored in b_pabd. If compressed
600 	 * arc is disabled then this value will be identical to the stat
601 	 * above.
602 	 */
603 	kstat_named_t arcstat_uncompressed_size;
604 	/*
605 	 * Number of bytes stored in all the arc_buf_t's. This is classified
606 	 * as "overhead" since this data is typically short-lived and will
607 	 * be evicted from the arc when it becomes unreferenced unless the
608 	 * zfs_keep_uncompressed_metadata or zfs_keep_uncompressed_level
609 	 * values have been set (see comment in dbuf.c for more information).
610 	 */
611 	kstat_named_t arcstat_overhead_size;
612 	/*
613 	 * Number of bytes consumed by internal ARC structures necessary
614 	 * for tracking purposes; these structures are not actually
615 	 * backed by ARC buffers. This includes arc_buf_hdr_t structures
616 	 * (allocated via arc_buf_hdr_t_full and arc_buf_hdr_t_l2only
617 	 * caches), and arc_buf_t structures (allocated via arc_buf_t
618 	 * cache).
619 	 */
620 	kstat_named_t arcstat_hdr_size;
621 	/*
622 	 * Number of bytes consumed by ARC buffers of type equal to
623 	 * ARC_BUFC_DATA. This is generally consumed by buffers backing
624 	 * on disk user data (e.g. plain file contents).
625 	 */
626 	kstat_named_t arcstat_data_size;
627 	/*
628 	 * Number of bytes consumed by ARC buffers of type equal to
629 	 * ARC_BUFC_METADATA. This is generally consumed by buffers
630 	 * backing on disk data that is used for internal ZFS
631 	 * structures (e.g. ZAP, dnode, indirect blocks, etc).
632 	 */
633 	kstat_named_t arcstat_metadata_size;
634 	/*
635 	 * Number of bytes consumed by dmu_buf_impl_t objects.
636 	 */
637 	kstat_named_t arcstat_dbuf_size;
638 	/*
639 	 * Number of bytes consumed by dnode_t objects.
640 	 */
641 	kstat_named_t arcstat_dnode_size;
642 	/*
643 	 * Number of bytes consumed by bonus buffers.
644 	 */
645 	kstat_named_t arcstat_bonus_size;
646 #if defined(COMPAT_FREEBSD11)
647 	/*
648 	 * Sum of the previous three counters, provided for compatibility.
649 	 */
650 	kstat_named_t arcstat_other_size;
651 #endif
652 
653 	/*
654 	 * Total number of bytes consumed by ARC buffers residing in the
655 	 * arc_anon state. This includes *all* buffers in the arc_anon
656 	 * state; e.g. data, metadata, evictable, and unevictable buffers
657 	 * are all included in this value.
658 	 */
659 	kstat_named_t arcstat_anon_size;
660 	kstat_named_t arcstat_anon_data;
661 	kstat_named_t arcstat_anon_metadata;
662 	/*
663 	 * Number of bytes consumed by ARC buffers that meet the
664 	 * following criteria: backing buffers of type ARC_BUFC_DATA,
665 	 * residing in the arc_anon state, and are eligible for eviction
666 	 * (e.g. have no outstanding holds on the buffer).
667 	 */
668 	kstat_named_t arcstat_anon_evictable_data;
669 	/*
670 	 * Number of bytes consumed by ARC buffers that meet the
671 	 * following criteria: backing buffers of type ARC_BUFC_METADATA,
672 	 * residing in the arc_anon state, and are eligible for eviction
673 	 * (e.g. have no outstanding holds on the buffer).
674 	 */
675 	kstat_named_t arcstat_anon_evictable_metadata;
676 	/*
677 	 * Total number of bytes consumed by ARC buffers residing in the
678 	 * arc_mru state. This includes *all* buffers in the arc_mru
679 	 * state; e.g. data, metadata, evictable, and unevictable buffers
680 	 * are all included in this value.
681 	 */
682 	kstat_named_t arcstat_mru_size;
683 	kstat_named_t arcstat_mru_data;
684 	kstat_named_t arcstat_mru_metadata;
685 	/*
686 	 * Number of bytes consumed by ARC buffers that meet the
687 	 * following criteria: backing buffers of type ARC_BUFC_DATA,
688 	 * residing in the arc_mru state, and are eligible for eviction
689 	 * (e.g. have no outstanding holds on the buffer).
690 	 */
691 	kstat_named_t arcstat_mru_evictable_data;
692 	/*
693 	 * Number of bytes consumed by ARC buffers that meet the
694 	 * following criteria: backing buffers of type ARC_BUFC_METADATA,
695 	 * residing in the arc_mru state, and are eligible for eviction
696 	 * (e.g. have no outstanding holds on the buffer).
697 	 */
698 	kstat_named_t arcstat_mru_evictable_metadata;
699 	/*
700 	 * Total number of bytes that *would have been* consumed by ARC
701 	 * buffers in the arc_mru_ghost state. The key thing to note
702 	 * here, is the fact that this size doesn't actually indicate
703 	 * RAM consumption. The ghost lists only consist of headers and
704 	 * don't actually have ARC buffers linked off of these headers.
705 	 * Thus, *if* the headers had associated ARC buffers, these
706 	 * buffers *would have* consumed this number of bytes.
707 	 */
708 	kstat_named_t arcstat_mru_ghost_size;
709 	kstat_named_t arcstat_mru_ghost_data;
710 	kstat_named_t arcstat_mru_ghost_metadata;
711 	/*
712 	 * Number of bytes that *would have been* consumed by ARC
713 	 * buffers that are eligible for eviction, of type
714 	 * ARC_BUFC_DATA, and linked off the arc_mru_ghost state.
715 	 */
716 	kstat_named_t arcstat_mru_ghost_evictable_data;
717 	/*
718 	 * Number of bytes that *would have been* consumed by ARC
719 	 * buffers that are eligible for eviction, of type
720 	 * ARC_BUFC_METADATA, and linked off the arc_mru_ghost state.
721 	 */
722 	kstat_named_t arcstat_mru_ghost_evictable_metadata;
723 	/*
724 	 * Total number of bytes consumed by ARC buffers residing in the
725 	 * arc_mfu state. This includes *all* buffers in the arc_mfu
726 	 * state; e.g. data, metadata, evictable, and unevictable buffers
727 	 * are all included in this value.
728 	 */
729 	kstat_named_t arcstat_mfu_size;
730 	kstat_named_t arcstat_mfu_data;
731 	kstat_named_t arcstat_mfu_metadata;
732 	/*
733 	 * Number of bytes consumed by ARC buffers that are eligible for
734 	 * eviction, of type ARC_BUFC_DATA, and reside in the arc_mfu
735 	 * state.
736 	 */
737 	kstat_named_t arcstat_mfu_evictable_data;
738 	/*
739 	 * Number of bytes consumed by ARC buffers that are eligible for
740 	 * eviction, of type ARC_BUFC_METADATA, and reside in the
741 	 * arc_mfu state.
742 	 */
743 	kstat_named_t arcstat_mfu_evictable_metadata;
744 	/*
745 	 * Total number of bytes that *would have been* consumed by ARC
746 	 * buffers in the arc_mfu_ghost state. See the comment above
747 	 * arcstat_mru_ghost_size for more details.
748 	 */
749 	kstat_named_t arcstat_mfu_ghost_size;
750 	kstat_named_t arcstat_mfu_ghost_data;
751 	kstat_named_t arcstat_mfu_ghost_metadata;
752 	/*
753 	 * Number of bytes that *would have been* consumed by ARC
754 	 * buffers that are eligible for eviction, of type
755 	 * ARC_BUFC_DATA, and linked off the arc_mfu_ghost state.
756 	 */
757 	kstat_named_t arcstat_mfu_ghost_evictable_data;
758 	/*
759 	 * Number of bytes that *would have been* consumed by ARC
760 	 * buffers that are eligible for eviction, of type
761 	 * ARC_BUFC_METADATA, and linked off the arc_mru_ghost state.
762 	 */
763 	kstat_named_t arcstat_mfu_ghost_evictable_metadata;
764 	/*
765 	 * Total number of bytes that are going to be evicted from ARC due to
766 	 * ARC_FLAG_UNCACHED being set.
767 	 */
768 	kstat_named_t arcstat_uncached_size;
769 	kstat_named_t arcstat_uncached_data;
770 	kstat_named_t arcstat_uncached_metadata;
771 	/*
772 	 * Number of data bytes that are going to be evicted from ARC due to
773 	 * ARC_FLAG_UNCACHED being set.
774 	 */
775 	kstat_named_t arcstat_uncached_evictable_data;
776 	/*
777 	 * Number of metadata bytes that that are going to be evicted from ARC
778 	 * due to ARC_FLAG_UNCACHED being set.
779 	 */
780 	kstat_named_t arcstat_uncached_evictable_metadata;
781 	kstat_named_t arcstat_l2_hits;
782 	kstat_named_t arcstat_l2_misses;
783 	/*
784 	 * Allocated size (in bytes) of L2ARC cached buffers by ARC state.
785 	 */
786 	kstat_named_t arcstat_l2_prefetch_asize;
787 	kstat_named_t arcstat_l2_mru_asize;
788 	kstat_named_t arcstat_l2_mfu_asize;
789 	/*
790 	 * Allocated size (in bytes) of L2ARC cached buffers by buffer content
791 	 * type.
792 	 */
793 	kstat_named_t arcstat_l2_bufc_data_asize;
794 	kstat_named_t arcstat_l2_bufc_metadata_asize;
795 	kstat_named_t arcstat_l2_feeds;
796 	kstat_named_t arcstat_l2_rw_clash;
797 	kstat_named_t arcstat_l2_read_bytes;
798 	kstat_named_t arcstat_l2_write_bytes;
799 	kstat_named_t arcstat_l2_writes_sent;
800 	kstat_named_t arcstat_l2_writes_done;
801 	kstat_named_t arcstat_l2_writes_error;
802 	kstat_named_t arcstat_l2_writes_lock_retry;
803 	kstat_named_t arcstat_l2_evict_lock_retry;
804 	kstat_named_t arcstat_l2_evict_reading;
805 	kstat_named_t arcstat_l2_evict_l1cached;
806 	kstat_named_t arcstat_l2_free_on_write;
807 	kstat_named_t arcstat_l2_abort_lowmem;
808 	kstat_named_t arcstat_l2_cksum_bad;
809 	kstat_named_t arcstat_l2_io_error;
810 	kstat_named_t arcstat_l2_lsize;
811 	kstat_named_t arcstat_l2_psize;
812 	kstat_named_t arcstat_l2_hdr_size;
813 	/*
814 	 * Number of L2ARC log blocks written. These are used for restoring the
815 	 * L2ARC. Updated during writing of L2ARC log blocks.
816 	 */
817 	kstat_named_t arcstat_l2_log_blk_writes;
818 	/*
819 	 * Moving average of the aligned size of the L2ARC log blocks, in
820 	 * bytes. Updated during L2ARC rebuild and during writing of L2ARC
821 	 * log blocks.
822 	 */
823 	kstat_named_t arcstat_l2_log_blk_avg_asize;
824 	/* Aligned size of L2ARC log blocks on L2ARC devices. */
825 	kstat_named_t arcstat_l2_log_blk_asize;
826 	/* Number of L2ARC log blocks present on L2ARC devices. */
827 	kstat_named_t arcstat_l2_log_blk_count;
828 	/*
829 	 * Moving average of the aligned size of L2ARC restored data, in bytes,
830 	 * to the aligned size of their metadata in L2ARC, in bytes.
831 	 * Updated during L2ARC rebuild and during writing of L2ARC log blocks.
832 	 */
833 	kstat_named_t arcstat_l2_data_to_meta_ratio;
834 	/*
835 	 * Number of times the L2ARC rebuild was successful for an L2ARC device.
836 	 */
837 	kstat_named_t arcstat_l2_rebuild_success;
838 	/*
839 	 * Number of times the L2ARC rebuild failed because the device header
840 	 * was in an unsupported format or corrupted.
841 	 */
842 	kstat_named_t arcstat_l2_rebuild_abort_unsupported;
843 	/*
844 	 * Number of times the L2ARC rebuild failed because of IO errors
845 	 * while reading a log block.
846 	 */
847 	kstat_named_t arcstat_l2_rebuild_abort_io_errors;
848 	/*
849 	 * Number of times the L2ARC rebuild failed because of IO errors when
850 	 * reading the device header.
851 	 */
852 	kstat_named_t arcstat_l2_rebuild_abort_dh_errors;
853 	/*
854 	 * Number of L2ARC log blocks which failed to be restored due to
855 	 * checksum errors.
856 	 */
857 	kstat_named_t arcstat_l2_rebuild_abort_cksum_lb_errors;
858 	/*
859 	 * Number of times the L2ARC rebuild was aborted due to low system
860 	 * memory.
861 	 */
862 	kstat_named_t arcstat_l2_rebuild_abort_lowmem;
863 	/* Logical size of L2ARC restored data, in bytes. */
864 	kstat_named_t arcstat_l2_rebuild_size;
865 	/* Aligned size of L2ARC restored data, in bytes. */
866 	kstat_named_t arcstat_l2_rebuild_asize;
867 	/*
868 	 * Number of L2ARC log entries (buffers) that were successfully
869 	 * restored in ARC.
870 	 */
871 	kstat_named_t arcstat_l2_rebuild_bufs;
872 	/*
873 	 * Number of L2ARC log entries (buffers) already cached in ARC. These
874 	 * were not restored again.
875 	 */
876 	kstat_named_t arcstat_l2_rebuild_bufs_precached;
877 	/*
878 	 * Number of L2ARC log blocks that were restored successfully. Each
879 	 * log block may hold up to L2ARC_LOG_BLK_MAX_ENTRIES buffers.
880 	 */
881 	kstat_named_t arcstat_l2_rebuild_log_blks;
882 	kstat_named_t arcstat_memory_throttle_count;
883 	kstat_named_t arcstat_memory_direct_count;
884 	kstat_named_t arcstat_memory_indirect_count;
885 	kstat_named_t arcstat_memory_all_bytes;
886 	kstat_named_t arcstat_memory_free_bytes;
887 	kstat_named_t arcstat_memory_available_bytes;
888 	kstat_named_t arcstat_no_grow;
889 	kstat_named_t arcstat_tempreserve;
890 	kstat_named_t arcstat_loaned_bytes;
891 	kstat_named_t arcstat_prune;
892 	kstat_named_t arcstat_meta_used;
893 	kstat_named_t arcstat_dnode_limit;
894 	kstat_named_t arcstat_async_upgrade_sync;
895 	/* Number of predictive prefetch requests. */
896 	kstat_named_t arcstat_predictive_prefetch;
897 	/* Number of requests for which predictive prefetch has completed. */
898 	kstat_named_t arcstat_demand_hit_predictive_prefetch;
899 	/* Number of requests for which predictive prefetch was running. */
900 	kstat_named_t arcstat_demand_iohit_predictive_prefetch;
901 	/* Number of prescient prefetch requests. */
902 	kstat_named_t arcstat_prescient_prefetch;
903 	/* Number of requests for which prescient prefetch has completed. */
904 	kstat_named_t arcstat_demand_hit_prescient_prefetch;
905 	/* Number of requests for which prescient prefetch was running. */
906 	kstat_named_t arcstat_demand_iohit_prescient_prefetch;
907 	kstat_named_t arcstat_need_free;
908 	kstat_named_t arcstat_sys_free;
909 	kstat_named_t arcstat_raw_size;
910 	kstat_named_t arcstat_cached_only_in_progress;
911 	kstat_named_t arcstat_abd_chunk_waste_size;
912 } arc_stats_t;
913 
914 typedef struct arc_sums {
915 	wmsum_t arcstat_hits;
916 	wmsum_t arcstat_iohits;
917 	wmsum_t arcstat_misses;
918 	wmsum_t arcstat_demand_data_hits;
919 	wmsum_t arcstat_demand_data_iohits;
920 	wmsum_t arcstat_demand_data_misses;
921 	wmsum_t arcstat_demand_metadata_hits;
922 	wmsum_t arcstat_demand_metadata_iohits;
923 	wmsum_t arcstat_demand_metadata_misses;
924 	wmsum_t arcstat_prefetch_data_hits;
925 	wmsum_t arcstat_prefetch_data_iohits;
926 	wmsum_t arcstat_prefetch_data_misses;
927 	wmsum_t arcstat_prefetch_metadata_hits;
928 	wmsum_t arcstat_prefetch_metadata_iohits;
929 	wmsum_t arcstat_prefetch_metadata_misses;
930 	wmsum_t arcstat_mru_hits;
931 	wmsum_t arcstat_mru_ghost_hits;
932 	wmsum_t arcstat_mfu_hits;
933 	wmsum_t arcstat_mfu_ghost_hits;
934 	wmsum_t arcstat_uncached_hits;
935 	wmsum_t arcstat_deleted;
936 	wmsum_t arcstat_mutex_miss;
937 	wmsum_t arcstat_access_skip;
938 	wmsum_t arcstat_evict_skip;
939 	wmsum_t arcstat_evict_not_enough;
940 	wmsum_t arcstat_evict_l2_cached;
941 	wmsum_t arcstat_evict_l2_eligible;
942 	wmsum_t arcstat_evict_l2_eligible_mfu;
943 	wmsum_t arcstat_evict_l2_eligible_mru;
944 	wmsum_t arcstat_evict_l2_ineligible;
945 	wmsum_t arcstat_evict_l2_skip;
946 	wmsum_t arcstat_hash_elements;
947 	wmsum_t arcstat_hash_collisions;
948 	wmsum_t arcstat_hash_chains;
949 	aggsum_t arcstat_size;
950 	wmsum_t arcstat_compressed_size;
951 	wmsum_t arcstat_uncompressed_size;
952 	wmsum_t arcstat_overhead_size;
953 	wmsum_t arcstat_hdr_size;
954 	wmsum_t arcstat_data_size;
955 	wmsum_t arcstat_metadata_size;
956 	wmsum_t arcstat_dbuf_size;
957 	wmsum_t arcstat_dnode_size;
958 	wmsum_t arcstat_bonus_size;
959 	wmsum_t arcstat_l2_hits;
960 	wmsum_t arcstat_l2_misses;
961 	wmsum_t arcstat_l2_prefetch_asize;
962 	wmsum_t arcstat_l2_mru_asize;
963 	wmsum_t arcstat_l2_mfu_asize;
964 	wmsum_t arcstat_l2_bufc_data_asize;
965 	wmsum_t arcstat_l2_bufc_metadata_asize;
966 	wmsum_t arcstat_l2_feeds;
967 	wmsum_t arcstat_l2_rw_clash;
968 	wmsum_t arcstat_l2_read_bytes;
969 	wmsum_t arcstat_l2_write_bytes;
970 	wmsum_t arcstat_l2_writes_sent;
971 	wmsum_t arcstat_l2_writes_done;
972 	wmsum_t arcstat_l2_writes_error;
973 	wmsum_t arcstat_l2_writes_lock_retry;
974 	wmsum_t arcstat_l2_evict_lock_retry;
975 	wmsum_t arcstat_l2_evict_reading;
976 	wmsum_t arcstat_l2_evict_l1cached;
977 	wmsum_t arcstat_l2_free_on_write;
978 	wmsum_t arcstat_l2_abort_lowmem;
979 	wmsum_t arcstat_l2_cksum_bad;
980 	wmsum_t arcstat_l2_io_error;
981 	wmsum_t arcstat_l2_lsize;
982 	wmsum_t arcstat_l2_psize;
983 	aggsum_t arcstat_l2_hdr_size;
984 	wmsum_t arcstat_l2_log_blk_writes;
985 	wmsum_t arcstat_l2_log_blk_asize;
986 	wmsum_t arcstat_l2_log_blk_count;
987 	wmsum_t arcstat_l2_rebuild_success;
988 	wmsum_t arcstat_l2_rebuild_abort_unsupported;
989 	wmsum_t arcstat_l2_rebuild_abort_io_errors;
990 	wmsum_t arcstat_l2_rebuild_abort_dh_errors;
991 	wmsum_t arcstat_l2_rebuild_abort_cksum_lb_errors;
992 	wmsum_t arcstat_l2_rebuild_abort_lowmem;
993 	wmsum_t arcstat_l2_rebuild_size;
994 	wmsum_t arcstat_l2_rebuild_asize;
995 	wmsum_t arcstat_l2_rebuild_bufs;
996 	wmsum_t arcstat_l2_rebuild_bufs_precached;
997 	wmsum_t arcstat_l2_rebuild_log_blks;
998 	wmsum_t arcstat_memory_throttle_count;
999 	wmsum_t arcstat_memory_direct_count;
1000 	wmsum_t arcstat_memory_indirect_count;
1001 	wmsum_t arcstat_prune;
1002 	wmsum_t arcstat_meta_used;
1003 	wmsum_t arcstat_async_upgrade_sync;
1004 	wmsum_t arcstat_predictive_prefetch;
1005 	wmsum_t arcstat_demand_hit_predictive_prefetch;
1006 	wmsum_t arcstat_demand_iohit_predictive_prefetch;
1007 	wmsum_t arcstat_prescient_prefetch;
1008 	wmsum_t arcstat_demand_hit_prescient_prefetch;
1009 	wmsum_t arcstat_demand_iohit_prescient_prefetch;
1010 	wmsum_t arcstat_raw_size;
1011 	wmsum_t arcstat_cached_only_in_progress;
1012 	wmsum_t arcstat_abd_chunk_waste_size;
1013 } arc_sums_t;
1014 
1015 typedef struct arc_evict_waiter {
1016 	list_node_t aew_node;
1017 	kcondvar_t aew_cv;
1018 	uint64_t aew_count;
1019 } arc_evict_waiter_t;
1020 
1021 #define	ARCSTAT(stat)	(arc_stats.stat.value.ui64)
1022 
1023 #define	ARCSTAT_INCR(stat, val) \
1024 	wmsum_add(&arc_sums.stat, (val))
1025 
1026 #define	ARCSTAT_BUMP(stat)	ARCSTAT_INCR(stat, 1)
1027 #define	ARCSTAT_BUMPDOWN(stat)	ARCSTAT_INCR(stat, -1)
1028 
1029 #define	arc_no_grow	ARCSTAT(arcstat_no_grow) /* do not grow cache size */
1030 #define	arc_meta	ARCSTAT(arcstat_meta)	/* target frac of metadata */
1031 #define	arc_pd		ARCSTAT(arcstat_pd)	/* target frac of data MRU */
1032 #define	arc_pm		ARCSTAT(arcstat_pm)	/* target frac of meta MRU */
1033 #define	arc_c		ARCSTAT(arcstat_c)	/* target size of cache */
1034 #define	arc_c_min	ARCSTAT(arcstat_c_min)	/* min target cache size */
1035 #define	arc_c_max	ARCSTAT(arcstat_c_max)	/* max target cache size */
1036 #define	arc_sys_free	ARCSTAT(arcstat_sys_free) /* target system free bytes */
1037 
1038 #define	arc_anon	(&ARC_anon)
1039 #define	arc_mru		(&ARC_mru)
1040 #define	arc_mru_ghost	(&ARC_mru_ghost)
1041 #define	arc_mfu		(&ARC_mfu)
1042 #define	arc_mfu_ghost	(&ARC_mfu_ghost)
1043 #define	arc_l2c_only	(&ARC_l2c_only)
1044 #define	arc_uncached	(&ARC_uncached)
1045 
1046 extern taskq_t *arc_prune_taskq;
1047 extern arc_stats_t arc_stats;
1048 extern arc_sums_t arc_sums;
1049 extern hrtime_t arc_growtime;
1050 extern boolean_t arc_warm;
1051 extern uint_t arc_grow_retry;
1052 extern uint_t arc_no_grow_shift;
1053 extern uint_t arc_shrink_shift;
1054 extern kmutex_t arc_prune_mtx;
1055 extern list_t arc_prune_list;
1056 extern arc_state_t	ARC_mfu;
1057 extern arc_state_t	ARC_mru;
1058 extern uint_t zfs_arc_pc_percent;
1059 extern uint_t arc_lotsfree_percent;
1060 extern uint64_t zfs_arc_min;
1061 extern uint64_t zfs_arc_max;
1062 
1063 extern uint64_t arc_reduce_target_size(uint64_t to_free);
1064 extern boolean_t arc_reclaim_needed(void);
1065 extern void arc_kmem_reap_soon(void);
1066 extern void arc_wait_for_eviction(uint64_t, boolean_t, boolean_t);
1067 
1068 extern void arc_lowmem_init(void);
1069 extern void arc_lowmem_fini(void);
1070 extern int arc_memory_throttle(spa_t *spa, uint64_t reserve, uint64_t txg);
1071 extern uint64_t arc_free_memory(void);
1072 extern int64_t arc_available_memory(void);
1073 extern void arc_tuning_update(boolean_t);
1074 extern void arc_register_hotplug(void);
1075 extern void arc_unregister_hotplug(void);
1076 
1077 extern int param_set_arc_u64(ZFS_MODULE_PARAM_ARGS);
1078 extern int param_set_arc_int(ZFS_MODULE_PARAM_ARGS);
1079 extern int param_set_arc_min(ZFS_MODULE_PARAM_ARGS);
1080 extern int param_set_arc_max(ZFS_MODULE_PARAM_ARGS);
1081 
1082 /* used in zdb.c */
1083 boolean_t l2arc_log_blkptr_valid(l2arc_dev_t *dev,
1084     const l2arc_log_blkptr_t *lbp);
1085 
1086 /* used in vdev_trim.c */
1087 void l2arc_dev_hdr_update(l2arc_dev_t *dev);
1088 l2arc_dev_t *l2arc_vdev_get(vdev_t *vd);
1089 
1090 #ifdef __cplusplus
1091 }
1092 #endif
1093 
1094 #endif /* _SYS_ARC_IMPL_H */
1095