xref: /onnv-gate/usr/src/uts/common/fs/zfs/sys/dmu_zfetch.h (revision 10474:0e96dd3b905a)
1789Sahrens /*
2789Sahrens  * CDDL HEADER START
3789Sahrens  *
4789Sahrens  * The contents of this file are subject to the terms of the
52391Smaybee  * Common Development and Distribution License (the "License").
62391Smaybee  * 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*10474SRichard.Morris@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23789Sahrens  * Use is subject to license terms.
24789Sahrens  */
25789Sahrens 
26789Sahrens #ifndef	_DFETCH_H
27789Sahrens #define	_DFETCH_H
28789Sahrens 
29789Sahrens #include <sys/zfs_context.h>
30789Sahrens 
31789Sahrens #ifdef	__cplusplus
32789Sahrens extern "C" {
33789Sahrens #endif
34789Sahrens 
35789Sahrens extern uint64_t	zfetch_array_rd_sz;
36789Sahrens 
37789Sahrens struct dnode;				/* so we can reference dnode */
38789Sahrens 
39789Sahrens typedef enum zfetch_dirn {
40789Sahrens 	ZFETCH_FORWARD = 1,		/* prefetch increasing block numbers */
41789Sahrens 	ZFETCH_BACKWARD	= -1		/* prefetch decreasing block numbers */
42789Sahrens } zfetch_dirn_t;
43789Sahrens 
44789Sahrens typedef struct zstream {
45789Sahrens 	uint64_t	zst_offset;	/* offset of starting block in range */
46789Sahrens 	uint64_t	zst_len;	/* length of range, in blocks */
47789Sahrens 	zfetch_dirn_t	zst_direction;	/* direction of prefetch */
48789Sahrens 	uint64_t	zst_stride;	/* length of stride, in blocks */
49789Sahrens 	uint64_t	zst_ph_offset;	/* prefetch offset, in blocks */
50789Sahrens 	uint64_t	zst_cap;	/* prefetch limit (cap), in blocks */
51789Sahrens 	kmutex_t	zst_lock;	/* protects stream */
52789Sahrens 	clock_t		zst_last;	/* lbolt of last prefetch */
53789Sahrens 	avl_node_t	zst_node;	/* embed avl node here */
54789Sahrens } zstream_t;
55789Sahrens 
56789Sahrens typedef struct zfetch {
57789Sahrens 	krwlock_t	zf_rwlock;	/* protects zfetch structure */
58789Sahrens 	list_t		zf_stream;	/* AVL tree of zstream_t's */
59789Sahrens 	struct dnode	*zf_dnode;	/* dnode that owns this zfetch */
60789Sahrens 	uint32_t	zf_stream_cnt;	/* # of active streams */
61789Sahrens 	uint64_t	zf_alloc_fail;	/* # of failed attempts to alloc strm */
62789Sahrens } zfetch_t;
63789Sahrens 
64*10474SRichard.Morris@Sun.COM void		zfetch_init(void);
65*10474SRichard.Morris@Sun.COM void		zfetch_fini(void);
66*10474SRichard.Morris@Sun.COM 
67789Sahrens void		dmu_zfetch_init(zfetch_t *, struct dnode *);
68789Sahrens void		dmu_zfetch_rele(zfetch_t *);
692391Smaybee void		dmu_zfetch(zfetch_t *, uint64_t, uint64_t, int);
70789Sahrens 
71789Sahrens 
72789Sahrens #ifdef	__cplusplus
73789Sahrens }
74789Sahrens #endif
75789Sahrens 
76789Sahrens #endif	/* _DFETCH_H */
77