xref: /freebsd/sys/contrib/openzfs/include/sys/dmu_zfetch.h (revision b1c1ee4429fcca8f69873a8be66184e68e1b19d7)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or https://opensource.org/licenses/CDDL-1.0.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Copyright (c) 2014, 2017 by Delphix. All rights reserved.
29  */
30 
31 #ifndef	_DMU_ZFETCH_H
32 #define	_DMU_ZFETCH_H
33 
34 #include <sys/zfs_context.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 struct dnode;				/* so we can reference dnode */
41 
42 typedef struct zfetch {
43 	kmutex_t	zf_lock;	/* protects zfetch structure */
44 	list_t		zf_stream;	/* list of zstream_t's */
45 	struct dnode	*zf_dnode;	/* dnode that owns this zfetch */
46 	int		zf_numstreams;	/* number of zstream_t's */
47 } zfetch_t;
48 
49 typedef struct zsrange {
50 	uint16_t	start;
51 	uint16_t	end;
52 } zsrange_t;
53 
54 #define	ZFETCH_RANGES	9		/* Fits zstream_t into 128 bytes */
55 
56 typedef struct zstream {
57 	list_node_t	zs_node;	/* link for zf_stream */
58 	uint64_t	zs_blkid;	/* expect next access at this blkid */
59 	uint_t		zs_atime;	/* time last prefetch issued */
60 	zsrange_t	zs_ranges[ZFETCH_RANGES]; /* ranges from future */
61 	unsigned int	zs_pf_dist;	/* data prefetch distance in bytes */
62 	unsigned int	zs_ipf_dist;	/* L1 prefetch distance in bytes */
63 	uint64_t	zs_pf_start;	/* first data block to prefetch */
64 	uint64_t	zs_pf_end;	/* data block to prefetch up to */
65 	uint64_t	zs_ipf_start;	/* first data block to prefetch L1 */
66 	uint64_t	zs_ipf_end;	/* data block to prefetch L1 up to */
67 	boolean_t	zs_missed;	/* stream saw cache misses */
68 	boolean_t	zs_more;	/* need more distant prefetch */
69 	zfs_refcount_t	zs_callers;	/* number of pending callers */
70 	/*
71 	 * Number of stream references: dnode, callers and pending blocks.
72 	 * The stream memory is freed when the number returns to zero.
73 	 */
74 	zfs_refcount_t	zs_refs;
75 } zstream_t;
76 
77 void		zfetch_init(void);
78 void		zfetch_fini(void);
79 
80 void		dmu_zfetch_init(zfetch_t *, struct dnode *);
81 void		dmu_zfetch_fini(zfetch_t *);
82 zstream_t	*dmu_zfetch_prepare(zfetch_t *, uint64_t, uint64_t, boolean_t,
83     boolean_t);
84 void		dmu_zfetch_run(zfetch_t *, zstream_t *, boolean_t, boolean_t,
85     boolean_t);
86 void		dmu_zfetch(zfetch_t *, uint64_t, uint64_t, boolean_t, boolean_t,
87     boolean_t, boolean_t);
88 
89 
90 #ifdef	__cplusplus
91 }
92 #endif
93 
94 #endif	/* _DMU_ZFETCH_H */
95