xref: /onnv-gate/usr/src/uts/common/fs/zfs/sys/arc.h (revision 12351:b2bf89333345)
1789Sahrens /*
2789Sahrens  * CDDL HEADER START
3789Sahrens  *
4789Sahrens  * The contents of this file are subject to the terms of the
51544Seschrock  * Common Development and Distribution License (the "License").
61544Seschrock  * You may not use this file except in compliance with the License.
7789Sahrens  *
8789Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9789Sahrens  * or http://www.opensolaris.org/os/licensing.
10789Sahrens  * See the License for the specific language governing permissions
11789Sahrens  * and limitations under the License.
12789Sahrens  *
13789Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14789Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15789Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16789Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17789Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18789Sahrens  *
19789Sahrens  * CDDL HEADER END
20789Sahrens  */
21789Sahrens /*
22*12296SLin.Ling@Sun.COM  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23789Sahrens  */
24789Sahrens 
25789Sahrens #ifndef	_SYS_ARC_H
26789Sahrens #define	_SYS_ARC_H
27789Sahrens 
28789Sahrens #include <sys/zfs_context.h>
29789Sahrens 
30789Sahrens #ifdef	__cplusplus
31789Sahrens extern "C" {
32789Sahrens #endif
33789Sahrens 
34789Sahrens #include <sys/zio.h>
354849Sahrens #include <sys/dmu.h>
365450Sbrendan #include <sys/spa.h>
37789Sahrens 
38789Sahrens typedef struct arc_buf_hdr arc_buf_hdr_t;
39789Sahrens typedef struct arc_buf arc_buf_t;
40789Sahrens typedef void arc_done_func_t(zio_t *zio, arc_buf_t *buf, void *private);
411544Seschrock typedef int arc_evict_func_t(void *private);
42789Sahrens 
43789Sahrens /* generic arc_done_func_t's which you can use */
44789Sahrens arc_done_func_t arc_bcopy_func;
45789Sahrens arc_done_func_t arc_getbuf_func;
46789Sahrens 
47789Sahrens struct arc_buf {
48789Sahrens 	arc_buf_hdr_t		*b_hdr;
49789Sahrens 	arc_buf_t		*b_next;
50*12296SLin.Ling@Sun.COM 	kmutex_t		b_evict_lock;
51*12296SLin.Ling@Sun.COM 	krwlock_t		b_data_lock;
52789Sahrens 	void			*b_data;
531544Seschrock 	arc_evict_func_t	*b_efunc;
541544Seschrock 	void			*b_private;
55789Sahrens };
56789Sahrens 
573290Sjohansen typedef enum arc_buf_contents {
583290Sjohansen 	ARC_BUFC_DATA,				/* buffer contains data */
594309Smaybee 	ARC_BUFC_METADATA,			/* buffer contains metadata */
604309Smaybee 	ARC_BUFC_NUMTYPES
613290Sjohansen } arc_buf_contents_t;
62789Sahrens /*
63789Sahrens  * These are the flags we pass into calls to the arc
64789Sahrens  */
65789Sahrens #define	ARC_WAIT	(1 << 1)	/* perform I/O synchronously */
66789Sahrens #define	ARC_NOWAIT	(1 << 2)	/* perform I/O asynchronously */
67789Sahrens #define	ARC_PREFETCH	(1 << 3)	/* I/O is a prefetch */
682391Smaybee #define	ARC_CACHED	(1 << 4)	/* I/O was already in cache */
697237Sek110237 #define	ARC_L2CACHE	(1 << 5)	/* cache in L2ARC */
70789Sahrens 
718582SBrendan.Gregg@Sun.COM /*
728582SBrendan.Gregg@Sun.COM  * The following breakdows of arc_size exist for kstat only.
738582SBrendan.Gregg@Sun.COM  */
748582SBrendan.Gregg@Sun.COM typedef enum arc_space_type {
758582SBrendan.Gregg@Sun.COM 	ARC_SPACE_DATA,
768582SBrendan.Gregg@Sun.COM 	ARC_SPACE_HDRS,
778582SBrendan.Gregg@Sun.COM 	ARC_SPACE_L2HDRS,
788582SBrendan.Gregg@Sun.COM 	ARC_SPACE_OTHER,
798582SBrendan.Gregg@Sun.COM 	ARC_SPACE_NUMTYPES
808582SBrendan.Gregg@Sun.COM } arc_space_type_t;
818582SBrendan.Gregg@Sun.COM 
828582SBrendan.Gregg@Sun.COM void arc_space_consume(uint64_t space, arc_space_type_t type);
838582SBrendan.Gregg@Sun.COM void arc_space_return(uint64_t space, arc_space_type_t type);
844309Smaybee void *arc_data_buf_alloc(uint64_t space);
854309Smaybee void arc_data_buf_free(void *buf, uint64_t space);
863290Sjohansen arc_buf_t *arc_buf_alloc(spa_t *spa, int size, void *tag,
873290Sjohansen     arc_buf_contents_t type);
889412SAleksandr.Guzovskiy@Sun.COM arc_buf_t *arc_loan_buf(spa_t *spa, int size);
899412SAleksandr.Guzovskiy@Sun.COM void arc_return_buf(arc_buf_t *buf, void *tag);
9011539SChunli.Zhang@Sun.COM void arc_loan_inuse_buf(arc_buf_t *buf, void *tag);
911544Seschrock void arc_buf_add_ref(arc_buf_t *buf, void *tag);
921544Seschrock int arc_buf_remove_ref(arc_buf_t *buf, void *tag);
93789Sahrens int arc_buf_size(arc_buf_t *buf);
94789Sahrens void arc_release(arc_buf_t *buf, void *tag);
95*12296SLin.Ling@Sun.COM int arc_release_bp(arc_buf_t *buf, void *tag, blkptr_t *bp, spa_t *spa,
96*12296SLin.Ling@Sun.COM     zbookmark_t *zb);
97789Sahrens int arc_released(arc_buf_t *buf);
981544Seschrock int arc_has_callback(arc_buf_t *buf);
993093Sahrens void arc_buf_freeze(arc_buf_t *buf);
1003093Sahrens void arc_buf_thaw(arc_buf_t *buf);
1011544Seschrock #ifdef ZFS_DEBUG
1021544Seschrock int arc_referenced(arc_buf_t *buf);
1031544Seschrock #endif
104789Sahrens 
10510922SJeff.Bonwick@Sun.COM int arc_read(zio_t *pio, spa_t *spa, const blkptr_t *bp, arc_buf_t *pbuf,
1067237Sek110237     arc_done_func_t *done, void *private, int priority, int zio_flags,
1077046Sahrens     uint32_t *arc_flags, const zbookmark_t *zb);
10810922SJeff.Bonwick@Sun.COM int arc_read_nolock(zio_t *pio, spa_t *spa, const blkptr_t *bp,
1097046Sahrens     arc_done_func_t *done, void *private, int priority, int flags,
1107046Sahrens     uint32_t *arc_flags, const zbookmark_t *zb);
11110922SJeff.Bonwick@Sun.COM zio_t *arc_write(zio_t *pio, spa_t *spa, uint64_t txg,
11210922SJeff.Bonwick@Sun.COM     blkptr_t *bp, arc_buf_t *buf, boolean_t l2arc, const zio_prop_t *zp,
11310922SJeff.Bonwick@Sun.COM     arc_done_func_t *ready, arc_done_func_t *done, void *private,
11410922SJeff.Bonwick@Sun.COM     int priority, int zio_flags, const zbookmark_t *zb);
115789Sahrens 
1161544Seschrock void arc_set_callback(arc_buf_t *buf, arc_evict_func_t *func, void *private);
1171544Seschrock int arc_buf_evict(arc_buf_t *buf);
1181544Seschrock 
1195642Smaybee void arc_flush(spa_t *spa);
1206245Smaybee void arc_tempreserve_clear(uint64_t reserve);
1216245Smaybee int arc_tempreserve_space(uint64_t reserve, uint64_t txg);
122789Sahrens 
123789Sahrens void arc_init(void);
124789Sahrens void arc_fini(void);
125789Sahrens 
1265450Sbrendan /*
1275450Sbrendan  * Level 2 ARC
1285450Sbrendan  */
1295450Sbrendan 
1309816SGeorge.Wilson@Sun.COM void l2arc_add_vdev(spa_t *spa, vdev_t *vd);
1315450Sbrendan void l2arc_remove_vdev(vdev_t *vd);
1326643Seschrock boolean_t l2arc_vdev_present(vdev_t *vd);
1335450Sbrendan void l2arc_init(void);
1345450Sbrendan void l2arc_fini(void);
1357754SJeff.Bonwick@Sun.COM void l2arc_start(void);
1367754SJeff.Bonwick@Sun.COM void l2arc_stop(void);
1375450Sbrendan 
138789Sahrens #ifdef	__cplusplus
139789Sahrens }
140789Sahrens #endif
141789Sahrens 
142789Sahrens #endif /* _SYS_ARC_H */
143