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