]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/sys/arc_impl.h
Improve zfs send performance by bypassing the ARC
[FreeBSD/FreeBSD.git] / include / sys / arc_impl.h
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright (c) 2013 by Delphix. All rights reserved.
24  * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
25  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
26  */
27
28 #ifndef _SYS_ARC_IMPL_H
29 #define _SYS_ARC_IMPL_H
30
31 #include <sys/arc.h>
32 #include <sys/zio_crypt.h>
33 #include <sys/zthr.h>
34 #include <sys/aggsum.h>
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 /*
41  * Note that buffers can be in one of 6 states:
42  *      ARC_anon        - anonymous (discussed below)
43  *      ARC_mru         - recently used, currently cached
44  *      ARC_mru_ghost   - recently used, no longer in cache
45  *      ARC_mfu         - frequently used, currently cached
46  *      ARC_mfu_ghost   - frequently used, no longer in cache
47  *      ARC_l2c_only    - exists in L2ARC but not other states
48  * When there are no active references to the buffer, they are
49  * are linked onto a list in one of these arc states.  These are
50  * the only buffers that can be evicted or deleted.  Within each
51  * state there are multiple lists, one for meta-data and one for
52  * non-meta-data.  Meta-data (indirect blocks, blocks of dnodes,
53  * etc.) is tracked separately so that it can be managed more
54  * explicitly: favored over data, limited explicitly.
55  *
56  * Anonymous buffers are buffers that are not associated with
57  * a DVA.  These are buffers that hold dirty block copies
58  * before they are written to stable storage.  By definition,
59  * they are "ref'd" and are considered part of arc_mru
60  * that cannot be freed.  Generally, they will acquire a DVA
61  * as they are written and migrate onto the arc_mru list.
62  *
63  * The ARC_l2c_only state is for buffers that are in the second
64  * level ARC but no longer in any of the ARC_m* lists.  The second
65  * level ARC itself may also contain buffers that are in any of
66  * the ARC_m* states - meaning that a buffer can exist in two
67  * places.  The reason for the ARC_l2c_only state is to keep the
68  * buffer header in the hash table, so that reads that hit the
69  * second level ARC benefit from these fast lookups.
70  */
71
72 typedef struct arc_state {
73         /*
74          * list of evictable buffers
75          */
76         multilist_t *arcs_list[ARC_BUFC_NUMTYPES];
77         /*
78          * total amount of evictable data in this state
79          */
80         zfs_refcount_t arcs_esize[ARC_BUFC_NUMTYPES];
81         /*
82          * total amount of data in this state; this includes: evictable,
83          * non-evictable, ARC_BUFC_DATA, and ARC_BUFC_METADATA.
84          */
85         zfs_refcount_t arcs_size;
86         /*
87          * supports the "dbufs" kstat
88          */
89         arc_state_type_t arcs_state;
90 } arc_state_t;
91
92 typedef struct arc_callback arc_callback_t;
93
94 struct arc_callback {
95         void                    *acb_private;
96         arc_read_done_func_t    *acb_done;
97         arc_buf_t               *acb_buf;
98         boolean_t               acb_encrypted;
99         boolean_t               acb_compressed;
100         boolean_t               acb_noauth;
101         zbookmark_phys_t        acb_zb;
102         zio_t                   *acb_zio_dummy;
103         zio_t                   *acb_zio_head;
104         arc_callback_t          *acb_next;
105 };
106
107 typedef struct arc_write_callback arc_write_callback_t;
108
109 struct arc_write_callback {
110         void                    *awcb_private;
111         arc_write_done_func_t   *awcb_ready;
112         arc_write_done_func_t   *awcb_children_ready;
113         arc_write_done_func_t   *awcb_physdone;
114         arc_write_done_func_t   *awcb_done;
115         arc_buf_t               *awcb_buf;
116 };
117
118 /*
119  * ARC buffers are separated into multiple structs as a memory saving measure:
120  *   - Common fields struct, always defined, and embedded within it:
121  *       - L2-only fields, always allocated but undefined when not in L2ARC
122  *       - L1-only fields, only allocated when in L1ARC
123  *
124  *           Buffer in L1                     Buffer only in L2
125  *    +------------------------+          +------------------------+
126  *    | arc_buf_hdr_t          |          | arc_buf_hdr_t          |
127  *    |                        |          |                        |
128  *    |                        |          |                        |
129  *    |                        |          |                        |
130  *    +------------------------+          +------------------------+
131  *    | l2arc_buf_hdr_t        |          | l2arc_buf_hdr_t        |
132  *    | (undefined if L1-only) |          |                        |
133  *    +------------------------+          +------------------------+
134  *    | l1arc_buf_hdr_t        |
135  *    |                        |
136  *    |                        |
137  *    |                        |
138  *    |                        |
139  *    +------------------------+
140  *
141  * Because it's possible for the L2ARC to become extremely large, we can wind
142  * up eating a lot of memory in L2ARC buffer headers, so the size of a header
143  * is minimized by only allocating the fields necessary for an L1-cached buffer
144  * when a header is actually in the L1 cache. The sub-headers (l1arc_buf_hdr and
145  * l2arc_buf_hdr) are embedded rather than allocated separately to save a couple
146  * words in pointers. arc_hdr_realloc() is used to switch a header between
147  * these two allocation states.
148  */
149 typedef struct l1arc_buf_hdr {
150         kmutex_t                b_freeze_lock;
151         zio_cksum_t             *b_freeze_cksum;
152
153         arc_buf_t               *b_buf;
154         uint32_t                b_bufcnt;
155         /* for waiting on writes to complete */
156         kcondvar_t              b_cv;
157         uint8_t                 b_byteswap;
158
159
160         /* protected by arc state mutex */
161         arc_state_t             *b_state;
162         multilist_node_t        b_arc_node;
163
164         /* updated atomically */
165         clock_t                 b_arc_access;
166         uint32_t                b_mru_hits;
167         uint32_t                b_mru_ghost_hits;
168         uint32_t                b_mfu_hits;
169         uint32_t                b_mfu_ghost_hits;
170         uint32_t                b_l2_hits;
171
172         /* self protecting */
173         zfs_refcount_t          b_refcnt;
174
175         arc_callback_t          *b_acb;
176         abd_t                   *b_pabd;
177 } l1arc_buf_hdr_t;
178
179 /*
180  * Encrypted blocks will need to be stored encrypted on the L2ARC
181  * disk as they appear in the main pool. In order for this to work we
182  * need to pass around the encryption parameters so they can be used
183  * to write data to the L2ARC. This struct is only defined in the
184  * arc_buf_hdr_t if the L1 header is defined and has the ARC_FLAG_ENCRYPTED
185  * flag set.
186  */
187 typedef struct arc_buf_hdr_crypt {
188         abd_t                   *b_rabd;        /* raw encrypted data */
189         dmu_object_type_t       b_ot;           /* object type */
190         uint32_t                b_ebufcnt;      /* count of encrypted buffers */
191
192         /* dsobj for looking up encryption key for l2arc encryption */
193         uint64_t                b_dsobj;
194
195         /* encryption parameters */
196         uint8_t                 b_salt[ZIO_DATA_SALT_LEN];
197         uint8_t                 b_iv[ZIO_DATA_IV_LEN];
198
199         /*
200          * Technically this could be removed since we will always be able to
201          * get the mac from the bp when we need it. However, it is inconvenient
202          * for callers of arc code to have to pass a bp in all the time. This
203          * also allows us to assert that L2ARC data is properly encrypted to
204          * match the data in the main storage pool.
205          */
206         uint8_t                 b_mac[ZIO_DATA_MAC_LEN];
207 } arc_buf_hdr_crypt_t;
208
209 typedef struct l2arc_dev {
210         vdev_t                  *l2ad_vdev;     /* vdev */
211         spa_t                   *l2ad_spa;      /* spa */
212         uint64_t                l2ad_hand;      /* next write location */
213         uint64_t                l2ad_start;     /* first addr on device */
214         uint64_t                l2ad_end;       /* last addr on device */
215         boolean_t               l2ad_first;     /* first sweep through */
216         boolean_t               l2ad_writing;   /* currently writing */
217         kmutex_t                l2ad_mtx;       /* lock for buffer list */
218         list_t                  l2ad_buflist;   /* buffer list */
219         list_node_t             l2ad_node;      /* device list node */
220         zfs_refcount_t          l2ad_alloc;     /* allocated bytes */
221 } l2arc_dev_t;
222
223 typedef struct l2arc_buf_hdr {
224         /* protected by arc_buf_hdr mutex */
225         l2arc_dev_t             *b_dev;         /* L2ARC device */
226         uint64_t                b_daddr;        /* disk address, offset byte */
227         uint32_t                b_hits;
228
229         list_node_t             b_l2node;
230 } l2arc_buf_hdr_t;
231
232 typedef struct l2arc_write_callback {
233         l2arc_dev_t     *l2wcb_dev;             /* device info */
234         arc_buf_hdr_t   *l2wcb_head;            /* head of write buflist */
235 } l2arc_write_callback_t;
236
237 struct arc_buf_hdr {
238         /* protected by hash lock */
239         dva_t                   b_dva;
240         uint64_t                b_birth;
241
242         arc_buf_contents_t      b_type;
243         arc_buf_hdr_t           *b_hash_next;
244         arc_flags_t             b_flags;
245
246         /*
247          * This field stores the size of the data buffer after
248          * compression, and is set in the arc's zio completion handlers.
249          * It is in units of SPA_MINBLOCKSIZE (e.g. 1 == 512 bytes).
250          *
251          * While the block pointers can store up to 32MB in their psize
252          * field, we can only store up to 32MB minus 512B. This is due
253          * to the bp using a bias of 1, whereas we use a bias of 0 (i.e.
254          * a field of zeros represents 512B in the bp). We can't use a
255          * bias of 1 since we need to reserve a psize of zero, here, to
256          * represent holes and embedded blocks.
257          *
258          * This isn't a problem in practice, since the maximum size of a
259          * buffer is limited to 16MB, so we never need to store 32MB in
260          * this field. Even in the upstream illumos code base, the
261          * maximum size of a buffer is limited to 16MB.
262          */
263         uint16_t                b_psize;
264
265         /*
266          * This field stores the size of the data buffer before
267          * compression, and cannot change once set. It is in units
268          * of SPA_MINBLOCKSIZE (e.g. 2 == 1024 bytes)
269          */
270         uint16_t                b_lsize;        /* immutable */
271         uint64_t                b_spa;          /* immutable */
272
273         /* L2ARC fields. Undefined when not in L2ARC. */
274         l2arc_buf_hdr_t         b_l2hdr;
275         /* L1ARC fields. Undefined when in l2arc_only state */
276         l1arc_buf_hdr_t         b_l1hdr;
277         /*
278          * Encryption parameters. Defined only when ARC_FLAG_ENCRYPTED
279          * is set and the L1 header exists.
280          */
281         arc_buf_hdr_crypt_t b_crypt_hdr;
282 };
283
284 typedef struct arc_stats {
285         kstat_named_t arcstat_hits;
286         kstat_named_t arcstat_misses;
287         kstat_named_t arcstat_demand_data_hits;
288         kstat_named_t arcstat_demand_data_misses;
289         kstat_named_t arcstat_demand_metadata_hits;
290         kstat_named_t arcstat_demand_metadata_misses;
291         kstat_named_t arcstat_prefetch_data_hits;
292         kstat_named_t arcstat_prefetch_data_misses;
293         kstat_named_t arcstat_prefetch_metadata_hits;
294         kstat_named_t arcstat_prefetch_metadata_misses;
295         kstat_named_t arcstat_mru_hits;
296         kstat_named_t arcstat_mru_ghost_hits;
297         kstat_named_t arcstat_mfu_hits;
298         kstat_named_t arcstat_mfu_ghost_hits;
299         kstat_named_t arcstat_deleted;
300         /*
301          * Number of buffers that could not be evicted because the hash lock
302          * was held by another thread.  The lock may not necessarily be held
303          * by something using the same buffer, since hash locks are shared
304          * by multiple buffers.
305          */
306         kstat_named_t arcstat_mutex_miss;
307         /*
308          * Number of buffers skipped when updating the access state due to the
309          * header having already been released after acquiring the hash lock.
310          */
311         kstat_named_t arcstat_access_skip;
312         /*
313          * Number of buffers skipped because they have I/O in progress, are
314          * indirect prefetch buffers that have not lived long enough, or are
315          * not from the spa we're trying to evict from.
316          */
317         kstat_named_t arcstat_evict_skip;
318         /*
319          * Number of times arc_evict_state() was unable to evict enough
320          * buffers to reach its target amount.
321          */
322         kstat_named_t arcstat_evict_not_enough;
323         kstat_named_t arcstat_evict_l2_cached;
324         kstat_named_t arcstat_evict_l2_eligible;
325         kstat_named_t arcstat_evict_l2_ineligible;
326         kstat_named_t arcstat_evict_l2_skip;
327         kstat_named_t arcstat_hash_elements;
328         kstat_named_t arcstat_hash_elements_max;
329         kstat_named_t arcstat_hash_collisions;
330         kstat_named_t arcstat_hash_chains;
331         kstat_named_t arcstat_hash_chain_max;
332         kstat_named_t arcstat_p;
333         kstat_named_t arcstat_c;
334         kstat_named_t arcstat_c_min;
335         kstat_named_t arcstat_c_max;
336         /* Not updated directly; only synced in arc_kstat_update. */
337         kstat_named_t arcstat_size;
338         /*
339          * Number of compressed bytes stored in the arc_buf_hdr_t's b_pabd.
340          * Note that the compressed bytes may match the uncompressed bytes
341          * if the block is either not compressed or compressed arc is disabled.
342          */
343         kstat_named_t arcstat_compressed_size;
344         /*
345          * Uncompressed size of the data stored in b_pabd. If compressed
346          * arc is disabled then this value will be identical to the stat
347          * above.
348          */
349         kstat_named_t arcstat_uncompressed_size;
350         /*
351          * Number of bytes stored in all the arc_buf_t's. This is classified
352          * as "overhead" since this data is typically short-lived and will
353          * be evicted from the arc when it becomes unreferenced unless the
354          * zfs_keep_uncompressed_metadata or zfs_keep_uncompressed_level
355          * values have been set (see comment in dbuf.c for more information).
356          */
357         kstat_named_t arcstat_overhead_size;
358         /*
359          * Number of bytes consumed by internal ARC structures necessary
360          * for tracking purposes; these structures are not actually
361          * backed by ARC buffers. This includes arc_buf_hdr_t structures
362          * (allocated via arc_buf_hdr_t_full and arc_buf_hdr_t_l2only
363          * caches), and arc_buf_t structures (allocated via arc_buf_t
364          * cache).
365          * Not updated directly; only synced in arc_kstat_update.
366          */
367         kstat_named_t arcstat_hdr_size;
368         /*
369          * Number of bytes consumed by ARC buffers of type equal to
370          * ARC_BUFC_DATA. This is generally consumed by buffers backing
371          * on disk user data (e.g. plain file contents).
372          * Not updated directly; only synced in arc_kstat_update.
373          */
374         kstat_named_t arcstat_data_size;
375         /*
376          * Number of bytes consumed by ARC buffers of type equal to
377          * ARC_BUFC_METADATA. This is generally consumed by buffers
378          * backing on disk data that is used for internal ZFS
379          * structures (e.g. ZAP, dnode, indirect blocks, etc).
380          * Not updated directly; only synced in arc_kstat_update.
381          */
382         kstat_named_t arcstat_metadata_size;
383         /*
384          * Number of bytes consumed by dmu_buf_impl_t objects.
385          * Not updated directly; only synced in arc_kstat_update.
386          */
387         kstat_named_t arcstat_dbuf_size;
388         /*
389          * Number of bytes consumed by dnode_t objects.
390          * Not updated directly; only synced in arc_kstat_update.
391          */
392         kstat_named_t arcstat_dnode_size;
393         /*
394          * Number of bytes consumed by bonus buffers.
395          * Not updated directly; only synced in arc_kstat_update.
396          */
397         kstat_named_t arcstat_bonus_size;
398         /*
399          * Total number of bytes consumed by ARC buffers residing in the
400          * arc_anon state. This includes *all* buffers in the arc_anon
401          * state; e.g. data, metadata, evictable, and unevictable buffers
402          * are all included in this value.
403          * Not updated directly; only synced in arc_kstat_update.
404          */
405         kstat_named_t arcstat_anon_size;
406         /*
407          * Number of bytes consumed by ARC buffers that meet the
408          * following criteria: backing buffers of type ARC_BUFC_DATA,
409          * residing in the arc_anon state, and are eligible for eviction
410          * (e.g. have no outstanding holds on the buffer).
411          * Not updated directly; only synced in arc_kstat_update.
412          */
413         kstat_named_t arcstat_anon_evictable_data;
414         /*
415          * Number of bytes consumed by ARC buffers that meet the
416          * following criteria: backing buffers of type ARC_BUFC_METADATA,
417          * residing in the arc_anon state, and are eligible for eviction
418          * (e.g. have no outstanding holds on the buffer).
419          * Not updated directly; only synced in arc_kstat_update.
420          */
421         kstat_named_t arcstat_anon_evictable_metadata;
422         /*
423          * Total number of bytes consumed by ARC buffers residing in the
424          * arc_mru state. This includes *all* buffers in the arc_mru
425          * state; e.g. data, metadata, evictable, and unevictable buffers
426          * are all included in this value.
427          * Not updated directly; only synced in arc_kstat_update.
428          */
429         kstat_named_t arcstat_mru_size;
430         /*
431          * Number of bytes consumed by ARC buffers that meet the
432          * following criteria: backing buffers of type ARC_BUFC_DATA,
433          * residing in the arc_mru state, and are eligible for eviction
434          * (e.g. have no outstanding holds on the buffer).
435          * Not updated directly; only synced in arc_kstat_update.
436          */
437         kstat_named_t arcstat_mru_evictable_data;
438         /*
439          * Number of bytes consumed by ARC buffers that meet the
440          * following criteria: backing buffers of type ARC_BUFC_METADATA,
441          * residing in the arc_mru state, and are eligible for eviction
442          * (e.g. have no outstanding holds on the buffer).
443          * Not updated directly; only synced in arc_kstat_update.
444          */
445         kstat_named_t arcstat_mru_evictable_metadata;
446         /*
447          * Total number of bytes that *would have been* consumed by ARC
448          * buffers in the arc_mru_ghost state. The key thing to note
449          * here, is the fact that this size doesn't actually indicate
450          * RAM consumption. The ghost lists only consist of headers and
451          * don't actually have ARC buffers linked off of these headers.
452          * Thus, *if* the headers had associated ARC buffers, these
453          * buffers *would have* consumed this number of bytes.
454          * Not updated directly; only synced in arc_kstat_update.
455          */
456         kstat_named_t arcstat_mru_ghost_size;
457         /*
458          * Number of bytes that *would have been* consumed by ARC
459          * buffers that are eligible for eviction, of type
460          * ARC_BUFC_DATA, and linked off the arc_mru_ghost state.
461          * Not updated directly; only synced in arc_kstat_update.
462          */
463         kstat_named_t arcstat_mru_ghost_evictable_data;
464         /*
465          * Number of bytes that *would have been* consumed by ARC
466          * buffers that are eligible for eviction, of type
467          * ARC_BUFC_METADATA, and linked off the arc_mru_ghost state.
468          * Not updated directly; only synced in arc_kstat_update.
469          */
470         kstat_named_t arcstat_mru_ghost_evictable_metadata;
471         /*
472          * Total number of bytes consumed by ARC buffers residing in the
473          * arc_mfu state. This includes *all* buffers in the arc_mfu
474          * state; e.g. data, metadata, evictable, and unevictable buffers
475          * are all included in this value.
476          * Not updated directly; only synced in arc_kstat_update.
477          */
478         kstat_named_t arcstat_mfu_size;
479         /*
480          * Number of bytes consumed by ARC buffers that are eligible for
481          * eviction, of type ARC_BUFC_DATA, and reside in the arc_mfu
482          * state.
483          * Not updated directly; only synced in arc_kstat_update.
484          */
485         kstat_named_t arcstat_mfu_evictable_data;
486         /*
487          * Number of bytes consumed by ARC buffers that are eligible for
488          * eviction, of type ARC_BUFC_METADATA, and reside in the
489          * arc_mfu state.
490          * Not updated directly; only synced in arc_kstat_update.
491          */
492         kstat_named_t arcstat_mfu_evictable_metadata;
493         /*
494          * Total number of bytes that *would have been* consumed by ARC
495          * buffers in the arc_mfu_ghost state. See the comment above
496          * arcstat_mru_ghost_size for more details.
497          * Not updated directly; only synced in arc_kstat_update.
498          */
499         kstat_named_t arcstat_mfu_ghost_size;
500         /*
501          * Number of bytes that *would have been* consumed by ARC
502          * buffers that are eligible for eviction, of type
503          * ARC_BUFC_DATA, and linked off the arc_mfu_ghost state.
504          * Not updated directly; only synced in arc_kstat_update.
505          */
506         kstat_named_t arcstat_mfu_ghost_evictable_data;
507         /*
508          * Number of bytes that *would have been* consumed by ARC
509          * buffers that are eligible for eviction, of type
510          * ARC_BUFC_METADATA, and linked off the arc_mru_ghost state.
511          * Not updated directly; only synced in arc_kstat_update.
512          */
513         kstat_named_t arcstat_mfu_ghost_evictable_metadata;
514         kstat_named_t arcstat_l2_hits;
515         kstat_named_t arcstat_l2_misses;
516         kstat_named_t arcstat_l2_feeds;
517         kstat_named_t arcstat_l2_rw_clash;
518         kstat_named_t arcstat_l2_read_bytes;
519         kstat_named_t arcstat_l2_write_bytes;
520         kstat_named_t arcstat_l2_writes_sent;
521         kstat_named_t arcstat_l2_writes_done;
522         kstat_named_t arcstat_l2_writes_error;
523         kstat_named_t arcstat_l2_writes_lock_retry;
524         kstat_named_t arcstat_l2_evict_lock_retry;
525         kstat_named_t arcstat_l2_evict_reading;
526         kstat_named_t arcstat_l2_evict_l1cached;
527         kstat_named_t arcstat_l2_free_on_write;
528         kstat_named_t arcstat_l2_abort_lowmem;
529         kstat_named_t arcstat_l2_cksum_bad;
530         kstat_named_t arcstat_l2_io_error;
531         kstat_named_t arcstat_l2_lsize;
532         kstat_named_t arcstat_l2_psize;
533         /* Not updated directly; only synced in arc_kstat_update. */
534         kstat_named_t arcstat_l2_hdr_size;
535         kstat_named_t arcstat_memory_throttle_count;
536         kstat_named_t arcstat_memory_direct_count;
537         kstat_named_t arcstat_memory_indirect_count;
538         kstat_named_t arcstat_memory_all_bytes;
539         kstat_named_t arcstat_memory_free_bytes;
540         kstat_named_t arcstat_memory_available_bytes;
541         kstat_named_t arcstat_no_grow;
542         kstat_named_t arcstat_tempreserve;
543         kstat_named_t arcstat_loaned_bytes;
544         kstat_named_t arcstat_prune;
545         /* Not updated directly; only synced in arc_kstat_update. */
546         kstat_named_t arcstat_meta_used;
547         kstat_named_t arcstat_meta_limit;
548         kstat_named_t arcstat_dnode_limit;
549         kstat_named_t arcstat_meta_max;
550         kstat_named_t arcstat_meta_min;
551         kstat_named_t arcstat_async_upgrade_sync;
552         kstat_named_t arcstat_demand_hit_predictive_prefetch;
553         kstat_named_t arcstat_demand_hit_prescient_prefetch;
554         kstat_named_t arcstat_need_free;
555         kstat_named_t arcstat_sys_free;
556         kstat_named_t arcstat_raw_size;
557         kstat_named_t arcstat_cached_only_in_progress;
558 } arc_stats_t;
559
560 typedef enum free_memory_reason_t {
561         FMR_UNKNOWN,
562         FMR_NEEDFREE,
563         FMR_LOTSFREE,
564         FMR_SWAPFS_MINFREE,
565         FMR_PAGES_PP_MAXIMUM,
566         FMR_HEAP_ARENA,
567         FMR_ZIO_ARENA,
568 } free_memory_reason_t;
569
570 #define ARCSTAT(stat)   (arc_stats.stat.value.ui64)
571
572 #define ARCSTAT_INCR(stat, val) \
573         atomic_add_64(&arc_stats.stat.value.ui64, (val))
574
575 #define ARCSTAT_BUMP(stat)      ARCSTAT_INCR(stat, 1)
576 #define ARCSTAT_BUMPDOWN(stat)  ARCSTAT_INCR(stat, -1)
577
578 #define arc_no_grow     ARCSTAT(arcstat_no_grow) /* do not grow cache size */
579 #define arc_p           ARCSTAT(arcstat_p)      /* target size of MRU */
580 #define arc_c           ARCSTAT(arcstat_c)      /* target size of cache */
581 #define arc_c_min       ARCSTAT(arcstat_c_min)  /* min target cache size */
582 #define arc_c_max       ARCSTAT(arcstat_c_max)  /* max target cache size */
583 #define arc_sys_free    ARCSTAT(arcstat_sys_free) /* target system free bytes */
584 #define arc_need_free   ARCSTAT(arcstat_need_free) /* bytes to be freed */
585
586 extern int arc_zio_arena_free_shift;
587 extern taskq_t *arc_prune_taskq;
588 extern arc_stats_t arc_stats;
589 extern hrtime_t arc_growtime;
590 extern boolean_t arc_warm;
591 extern int arc_grow_retry;
592 extern int arc_shrink_shift;
593 extern zthr_t           *arc_adjust_zthr;
594 extern kmutex_t         arc_adjust_lock;
595 extern kcondvar_t       arc_adjust_waiters_cv;
596 extern boolean_t        arc_adjust_needed;
597 extern kmutex_t arc_prune_mtx;
598 extern list_t arc_prune_list;
599 extern aggsum_t arc_size;
600 extern arc_state_t      *arc_mfu;
601 extern arc_state_t      *arc_mru;
602 extern uint_t zfs_arc_pc_percent;
603 extern int arc_lotsfree_percent;
604
605 extern void arc_reduce_target_size(int64_t to_free);
606 extern boolean_t arc_reclaim_needed(void);
607 extern void arc_kmem_reap_soon(void);
608
609 extern void arc_lowmem_init(void);
610 extern void arc_lowmem_fini(void);
611 extern void arc_prune_async(int64_t);
612 extern int arc_memory_throttle(spa_t *spa, uint64_t reserve, uint64_t txg);
613 extern uint64_t arc_free_memory(void);
614 extern int64_t arc_available_memory(void);
615 extern void arc_tuning_update(void);
616
617 extern int param_set_arc_long(const char *buf, zfs_kernel_param_t *kp);
618 extern int param_set_arc_int(const char *buf, zfs_kernel_param_t *kp);
619
620 #ifdef __cplusplus
621 }
622 #endif
623
624 #endif /* _SYS_ARC_IMPL_H */