xref: /freebsd/sys/contrib/openzfs/include/sys/dmu_zfetch.h (revision 1719886f6d08408b834d270c59ffcfd821c8f63a)
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 https://opensource.org/licenses/CDDL-1.0.
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * Copyright (c) 2014, 2017 by Delphix. All rights reserved.
28  */
29 
30 #ifndef	_DMU_ZFETCH_H
31 #define	_DMU_ZFETCH_H
32 
33 #include <sys/zfs_context.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 struct dnode;				/* so we can reference dnode */
40 
41 typedef struct zfetch {
42 	kmutex_t	zf_lock;	/* protects zfetch structure */
43 	list_t		zf_stream;	/* list of zstream_t's */
44 	struct dnode	*zf_dnode;	/* dnode that owns this zfetch */
45 	int		zf_numstreams;	/* number of zstream_t's */
46 } zfetch_t;
47 
48 typedef struct zsrange {
49 	uint16_t	start;
50 	uint16_t	end;
51 } zsrange_t;
52 
53 #define	ZFETCH_RANGES	9		/* Fits zstream_t into 128 bytes */
54 
55 typedef struct zstream {
56 	list_node_t	zs_node;	/* link for zf_stream */
57 	uint64_t	zs_blkid;	/* expect next access at this blkid */
58 	uint_t		zs_atime;	/* time last prefetch issued */
59 	zsrange_t	zs_ranges[ZFETCH_RANGES]; /* ranges from future */
60 	unsigned int	zs_pf_dist;	/* data prefetch distance in bytes */
61 	unsigned int	zs_ipf_dist;	/* L1 prefetch distance in bytes */
62 	uint64_t	zs_pf_start;	/* first data block to prefetch */
63 	uint64_t	zs_pf_end;	/* data block to prefetch up to */
64 	uint64_t	zs_ipf_start;	/* first data block to prefetch L1 */
65 	uint64_t	zs_ipf_end;	/* data block to prefetch L1 up to */
66 	boolean_t	zs_missed;	/* stream saw cache misses */
67 	boolean_t	zs_more;	/* need more distant prefetch */
68 	zfs_refcount_t	zs_callers;	/* number of pending callers */
69 	/*
70 	 * Number of stream references: dnode, callers and pending blocks.
71 	 * The stream memory is freed when the number returns to zero.
72 	 */
73 	zfs_refcount_t	zs_refs;
74 } zstream_t;
75 
76 void		zfetch_init(void);
77 void		zfetch_fini(void);
78 
79 void		dmu_zfetch_init(zfetch_t *, struct dnode *);
80 void		dmu_zfetch_fini(zfetch_t *);
81 zstream_t	*dmu_zfetch_prepare(zfetch_t *, uint64_t, uint64_t, boolean_t,
82     boolean_t);
83 void		dmu_zfetch_run(zfetch_t *, zstream_t *, boolean_t, boolean_t);
84 void		dmu_zfetch(zfetch_t *, uint64_t, uint64_t, boolean_t, boolean_t,
85     boolean_t);
86 
87 
88 #ifdef	__cplusplus
89 }
90 #endif
91 
92 #endif	/* _DMU_ZFETCH_H */
93