xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/dmu_zfetch.h (revision 002c70ff32f5df6f93c15f88d351ce26443e6ee7)
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 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_DFETCH_H
27 #define	_DFETCH_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/zfs_context.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 extern uint64_t	zfetch_array_rd_sz;
38 
39 struct dnode;				/* so we can reference dnode */
40 
41 typedef enum zfetch_dirn {
42 	ZFETCH_FORWARD = 1,		/* prefetch increasing block numbers */
43 	ZFETCH_BACKWARD	= -1		/* prefetch decreasing block numbers */
44 } zfetch_dirn_t;
45 
46 typedef struct zstream {
47 	uint64_t	zst_offset;	/* offset of starting block in range */
48 	uint64_t	zst_len;	/* length of range, in blocks */
49 	zfetch_dirn_t	zst_direction;	/* direction of prefetch */
50 	uint64_t	zst_stride;	/* length of stride, in blocks */
51 	uint64_t	zst_ph_offset;	/* prefetch offset, in blocks */
52 	uint64_t	zst_cap;	/* prefetch limit (cap), in blocks */
53 	kmutex_t	zst_lock;	/* protects stream */
54 	clock_t		zst_last;	/* lbolt of last prefetch */
55 	avl_node_t	zst_node;	/* embed avl node here */
56 } zstream_t;
57 
58 typedef struct zfetch {
59 	krwlock_t	zf_rwlock;	/* protects zfetch structure */
60 	list_t		zf_stream;	/* AVL tree of zstream_t's */
61 	struct dnode	*zf_dnode;	/* dnode that owns this zfetch */
62 	uint32_t	zf_stream_cnt;	/* # of active streams */
63 	uint64_t	zf_alloc_fail;	/* # of failed attempts to alloc strm */
64 } zfetch_t;
65 
66 void		dmu_zfetch_init(zfetch_t *, struct dnode *);
67 void		dmu_zfetch_rele(zfetch_t *);
68 void		dmu_zfetch(zfetch_t *, uint64_t, uint64_t, int);
69 
70 
71 #ifdef	__cplusplus
72 }
73 #endif
74 
75 #endif	/* _DFETCH_H */
76