1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
513506d1eSmaybee  * Common Development and Distribution License (the "License").
613506d1eSmaybee  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21fa9e4066Sahrens /*
227cbf8b43SRich Morris  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23fa9e4066Sahrens  * Use is subject to license terms.
24fa9e4066Sahrens  */
25fa9e4066Sahrens 
26cf6106c8SMatthew Ahrens /*
279704bf7fSPaul Dagnelie  * Copyright (c) 2014, 2017 by Delphix. All rights reserved.
28cf6106c8SMatthew Ahrens  */
29cf6106c8SMatthew Ahrens 
30cf6106c8SMatthew Ahrens #ifndef	_DMU_ZFETCH_H
31cf6106c8SMatthew Ahrens #define	_DMU_ZFETCH_H
32fa9e4066Sahrens 
33fa9e4066Sahrens #include <sys/zfs_context.h>
34fa9e4066Sahrens 
35fa9e4066Sahrens #ifdef	__cplusplus
36fa9e4066Sahrens extern "C" {
37fa9e4066Sahrens #endif
38fa9e4066Sahrens 
39fa9e4066Sahrens extern uint64_t	zfetch_array_rd_sz;
40fa9e4066Sahrens 
41fa9e4066Sahrens struct dnode;				/* so we can reference dnode */
42fa9e4066Sahrens 
43*9e3493cbSJason King typedef struct zfetch {
44*9e3493cbSJason King 	krwlock_t	zf_rwlock;	/* protects zfetch structure */
45*9e3493cbSJason King 	list_t		zf_stream;	/* list of zstream_t's */
46*9e3493cbSJason King 	struct dnode	*zf_dnode;	/* dnode that owns this zfetch */
47*9e3493cbSJason King 	int		zf_numstreams;	/* number of zstream_t's */
48*9e3493cbSJason King } zfetch_t;
49*9e3493cbSJason King 
50fa9e4066Sahrens typedef struct zstream {
51cf6106c8SMatthew Ahrens 	uint64_t	zs_blkid;	/* expect next access at this blkid */
52cf6106c8SMatthew Ahrens 	uint64_t	zs_pf_blkid;	/* next block to prefetch */
53cb92f413SAlexander Motin 
54cb92f413SAlexander Motin 	/*
55cb92f413SAlexander Motin 	 * We will next prefetch the L1 indirect block of this level-0
56cb92f413SAlexander Motin 	 * block id.
57cb92f413SAlexander Motin 	 */
58cb92f413SAlexander Motin 	uint64_t	zs_ipf_blkid;
59cb92f413SAlexander Motin 
60cf6106c8SMatthew Ahrens 	kmutex_t	zs_lock;	/* protects stream */
61cf6106c8SMatthew Ahrens 	hrtime_t	zs_atime;	/* time last prefetch issued */
62*9e3493cbSJason King 	hrtime_t	zs_start_time;	/* start of last prefetch */
63cf6106c8SMatthew Ahrens 	list_node_t	zs_node;	/* link for zf_stream */
64*9e3493cbSJason King 	zfetch_t	*zs_fetch;	/* parent fetch */
65*9e3493cbSJason King 	zfs_refcount_t	zs_blocks; /* number of pending blocks in the stream */
66fa9e4066Sahrens } zstream_t;
67fa9e4066Sahrens 
687cbf8b43SRich Morris void		zfetch_init(void);
697cbf8b43SRich Morris void		zfetch_fini(void);
707cbf8b43SRich Morris 
71fa9e4066Sahrens void		dmu_zfetch_init(zfetch_t *, struct dnode *);
72cf6106c8SMatthew Ahrens void		dmu_zfetch_fini(zfetch_t *);
739704bf7fSPaul Dagnelie void		dmu_zfetch(zfetch_t *, uint64_t, uint64_t, boolean_t,
749704bf7fSPaul Dagnelie     boolean_t);
75fa9e4066Sahrens 
76fa9e4066Sahrens 
77fa9e4066Sahrens #ifdef	__cplusplus
78fa9e4066Sahrens }
79fa9e4066Sahrens #endif
80fa9e4066Sahrens 
81cf6106c8SMatthew Ahrens #endif	/* _DMU_ZFETCH_H */
82