xref: /freebsd/sys/contrib/openzfs/module/zfs/dmu_zfetch.c (revision c8e7f78a3d28ff6e6223ed136ada8e1e2f34965e)
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) 2013, 2017 by Delphix. All rights reserved.
28  */
29 
30 #include <sys/zfs_context.h>
31 #include <sys/arc_impl.h>
32 #include <sys/dnode.h>
33 #include <sys/dmu_objset.h>
34 #include <sys/dmu_zfetch.h>
35 #include <sys/dmu.h>
36 #include <sys/dbuf.h>
37 #include <sys/kstat.h>
38 #include <sys/wmsum.h>
39 
40 /*
41  * This tunable disables predictive prefetch.  Note that it leaves "prescient"
42  * prefetch (e.g. prefetch for zfs send) intact.  Unlike predictive prefetch,
43  * prescient prefetch never issues i/os that end up not being needed,
44  * so it can't hurt performance.
45  */
46 
47 static int zfs_prefetch_disable = B_FALSE;
48 
49 /* max # of streams per zfetch */
50 static unsigned int	zfetch_max_streams = 8;
51 /* min time before stream reclaim */
52 static unsigned int	zfetch_min_sec_reap = 1;
53 /* max time before stream delete */
54 static unsigned int	zfetch_max_sec_reap = 2;
55 #ifdef _ILP32
56 /* min bytes to prefetch per stream (default 2MB) */
57 static unsigned int	zfetch_min_distance = 2 * 1024 * 1024;
58 /* max bytes to prefetch per stream (default 8MB) */
59 unsigned int	zfetch_max_distance = 8 * 1024 * 1024;
60 #else
61 /* min bytes to prefetch per stream (default 4MB) */
62 static unsigned int	zfetch_min_distance = 4 * 1024 * 1024;
63 /* max bytes to prefetch per stream (default 64MB) */
64 unsigned int	zfetch_max_distance = 64 * 1024 * 1024;
65 #endif
66 /* max bytes to prefetch indirects for per stream (default 64MB) */
67 unsigned int	zfetch_max_idistance = 64 * 1024 * 1024;
68 
69 typedef struct zfetch_stats {
70 	kstat_named_t zfetchstat_hits;
71 	kstat_named_t zfetchstat_misses;
72 	kstat_named_t zfetchstat_max_streams;
73 	kstat_named_t zfetchstat_io_issued;
74 	kstat_named_t zfetchstat_io_active;
75 } zfetch_stats_t;
76 
77 static zfetch_stats_t zfetch_stats = {
78 	{ "hits",			KSTAT_DATA_UINT64 },
79 	{ "misses",			KSTAT_DATA_UINT64 },
80 	{ "max_streams",		KSTAT_DATA_UINT64 },
81 	{ "io_issued",			KSTAT_DATA_UINT64 },
82 	{ "io_active",			KSTAT_DATA_UINT64 },
83 };
84 
85 struct {
86 	wmsum_t zfetchstat_hits;
87 	wmsum_t zfetchstat_misses;
88 	wmsum_t zfetchstat_max_streams;
89 	wmsum_t zfetchstat_io_issued;
90 	aggsum_t zfetchstat_io_active;
91 } zfetch_sums;
92 
93 #define	ZFETCHSTAT_BUMP(stat)					\
94 	wmsum_add(&zfetch_sums.stat, 1)
95 #define	ZFETCHSTAT_ADD(stat, val)				\
96 	wmsum_add(&zfetch_sums.stat, val)
97 
98 
99 static kstat_t		*zfetch_ksp;
100 
101 static int
102 zfetch_kstats_update(kstat_t *ksp, int rw)
103 {
104 	zfetch_stats_t *zs = ksp->ks_data;
105 
106 	if (rw == KSTAT_WRITE)
107 		return (EACCES);
108 	zs->zfetchstat_hits.value.ui64 =
109 	    wmsum_value(&zfetch_sums.zfetchstat_hits);
110 	zs->zfetchstat_misses.value.ui64 =
111 	    wmsum_value(&zfetch_sums.zfetchstat_misses);
112 	zs->zfetchstat_max_streams.value.ui64 =
113 	    wmsum_value(&zfetch_sums.zfetchstat_max_streams);
114 	zs->zfetchstat_io_issued.value.ui64 =
115 	    wmsum_value(&zfetch_sums.zfetchstat_io_issued);
116 	zs->zfetchstat_io_active.value.ui64 =
117 	    aggsum_value(&zfetch_sums.zfetchstat_io_active);
118 	return (0);
119 }
120 
121 void
122 zfetch_init(void)
123 {
124 	wmsum_init(&zfetch_sums.zfetchstat_hits, 0);
125 	wmsum_init(&zfetch_sums.zfetchstat_misses, 0);
126 	wmsum_init(&zfetch_sums.zfetchstat_max_streams, 0);
127 	wmsum_init(&zfetch_sums.zfetchstat_io_issued, 0);
128 	aggsum_init(&zfetch_sums.zfetchstat_io_active, 0);
129 
130 	zfetch_ksp = kstat_create("zfs", 0, "zfetchstats", "misc",
131 	    KSTAT_TYPE_NAMED, sizeof (zfetch_stats) / sizeof (kstat_named_t),
132 	    KSTAT_FLAG_VIRTUAL);
133 
134 	if (zfetch_ksp != NULL) {
135 		zfetch_ksp->ks_data = &zfetch_stats;
136 		zfetch_ksp->ks_update = zfetch_kstats_update;
137 		kstat_install(zfetch_ksp);
138 	}
139 }
140 
141 void
142 zfetch_fini(void)
143 {
144 	if (zfetch_ksp != NULL) {
145 		kstat_delete(zfetch_ksp);
146 		zfetch_ksp = NULL;
147 	}
148 
149 	wmsum_fini(&zfetch_sums.zfetchstat_hits);
150 	wmsum_fini(&zfetch_sums.zfetchstat_misses);
151 	wmsum_fini(&zfetch_sums.zfetchstat_max_streams);
152 	wmsum_fini(&zfetch_sums.zfetchstat_io_issued);
153 	ASSERT0(aggsum_value(&zfetch_sums.zfetchstat_io_active));
154 	aggsum_fini(&zfetch_sums.zfetchstat_io_active);
155 }
156 
157 /*
158  * This takes a pointer to a zfetch structure and a dnode.  It performs the
159  * necessary setup for the zfetch structure, grokking data from the
160  * associated dnode.
161  */
162 void
163 dmu_zfetch_init(zfetch_t *zf, dnode_t *dno)
164 {
165 	if (zf == NULL)
166 		return;
167 	zf->zf_dnode = dno;
168 	zf->zf_numstreams = 0;
169 
170 	list_create(&zf->zf_stream, sizeof (zstream_t),
171 	    offsetof(zstream_t, zs_node));
172 
173 	mutex_init(&zf->zf_lock, NULL, MUTEX_DEFAULT, NULL);
174 }
175 
176 static void
177 dmu_zfetch_stream_fini(zstream_t *zs)
178 {
179 	ASSERT(!list_link_active(&zs->zs_node));
180 	zfs_refcount_destroy(&zs->zs_callers);
181 	zfs_refcount_destroy(&zs->zs_refs);
182 	kmem_free(zs, sizeof (*zs));
183 }
184 
185 static void
186 dmu_zfetch_stream_remove(zfetch_t *zf, zstream_t *zs)
187 {
188 	ASSERT(MUTEX_HELD(&zf->zf_lock));
189 	list_remove(&zf->zf_stream, zs);
190 	zf->zf_numstreams--;
191 	membar_producer();
192 	if (zfs_refcount_remove(&zs->zs_refs, NULL) == 0)
193 		dmu_zfetch_stream_fini(zs);
194 }
195 
196 /*
197  * Clean-up state associated with a zfetch structure (e.g. destroy the
198  * streams).  This doesn't free the zfetch_t itself, that's left to the caller.
199  */
200 void
201 dmu_zfetch_fini(zfetch_t *zf)
202 {
203 	zstream_t *zs;
204 
205 	mutex_enter(&zf->zf_lock);
206 	while ((zs = list_head(&zf->zf_stream)) != NULL)
207 		dmu_zfetch_stream_remove(zf, zs);
208 	mutex_exit(&zf->zf_lock);
209 	list_destroy(&zf->zf_stream);
210 	mutex_destroy(&zf->zf_lock);
211 
212 	zf->zf_dnode = NULL;
213 }
214 
215 /*
216  * If there aren't too many active streams already, create one more.
217  * In process delete/reuse all streams without hits for zfetch_max_sec_reap.
218  * If needed, reuse oldest stream without hits for zfetch_min_sec_reap or ever.
219  * The "blkid" argument is the next block that we expect this stream to access.
220  */
221 static void
222 dmu_zfetch_stream_create(zfetch_t *zf, uint64_t blkid)
223 {
224 	zstream_t *zs, *zs_next, *zs_old = NULL;
225 	hrtime_t now = gethrtime(), t;
226 
227 	ASSERT(MUTEX_HELD(&zf->zf_lock));
228 
229 	/*
230 	 * Delete too old streams, reusing the first found one.
231 	 */
232 	t = now - SEC2NSEC(zfetch_max_sec_reap);
233 	for (zs = list_head(&zf->zf_stream); zs != NULL; zs = zs_next) {
234 		zs_next = list_next(&zf->zf_stream, zs);
235 		/*
236 		 * Skip if still active.  1 -- zf_stream reference.
237 		 */
238 		if (zfs_refcount_count(&zs->zs_refs) != 1)
239 			continue;
240 		if (zs->zs_atime > t)
241 			continue;
242 		if (zs_old)
243 			dmu_zfetch_stream_remove(zf, zs);
244 		else
245 			zs_old = zs;
246 	}
247 	if (zs_old) {
248 		zs = zs_old;
249 		goto reuse;
250 	}
251 
252 	/*
253 	 * The maximum number of streams is normally zfetch_max_streams,
254 	 * but for small files we lower it such that it's at least possible
255 	 * for all the streams to be non-overlapping.
256 	 */
257 	uint32_t max_streams = MAX(1, MIN(zfetch_max_streams,
258 	    zf->zf_dnode->dn_maxblkid * zf->zf_dnode->dn_datablksz /
259 	    zfetch_max_distance));
260 	if (zf->zf_numstreams >= max_streams) {
261 		t = now - SEC2NSEC(zfetch_min_sec_reap);
262 		for (zs = list_head(&zf->zf_stream); zs != NULL;
263 		    zs = list_next(&zf->zf_stream, zs)) {
264 			if (zfs_refcount_count(&zs->zs_refs) != 1)
265 				continue;
266 			if (zs->zs_atime > t)
267 				continue;
268 			if (zs_old == NULL || zs->zs_atime < zs_old->zs_atime)
269 				zs_old = zs;
270 		}
271 		if (zs_old) {
272 			zs = zs_old;
273 			goto reuse;
274 		}
275 		ZFETCHSTAT_BUMP(zfetchstat_max_streams);
276 		return;
277 	}
278 
279 	zs = kmem_zalloc(sizeof (*zs), KM_SLEEP);
280 	zs->zs_fetch = zf;
281 	zfs_refcount_create(&zs->zs_callers);
282 	zfs_refcount_create(&zs->zs_refs);
283 	/* One reference for zf_stream. */
284 	zfs_refcount_add(&zs->zs_refs, NULL);
285 	zf->zf_numstreams++;
286 	list_insert_head(&zf->zf_stream, zs);
287 
288 reuse:
289 	zs->zs_blkid = blkid;
290 	zs->zs_pf_dist = 0;
291 	zs->zs_pf_start = blkid;
292 	zs->zs_pf_end = blkid;
293 	zs->zs_ipf_dist = 0;
294 	zs->zs_ipf_start = blkid;
295 	zs->zs_ipf_end = blkid;
296 	/* Allow immediate stream reuse until first hit. */
297 	zs->zs_atime = now - SEC2NSEC(zfetch_min_sec_reap);
298 	zs->zs_missed = B_FALSE;
299 	zs->zs_more = B_FALSE;
300 }
301 
302 static void
303 dmu_zfetch_done(void *arg, uint64_t level, uint64_t blkid, boolean_t io_issued)
304 {
305 	zstream_t *zs = arg;
306 
307 	if (io_issued && level == 0 && blkid < zs->zs_blkid)
308 		zs->zs_more = B_TRUE;
309 	if (zfs_refcount_remove(&zs->zs_refs, NULL) == 0)
310 		dmu_zfetch_stream_fini(zs);
311 	aggsum_add(&zfetch_sums.zfetchstat_io_active, -1);
312 }
313 
314 /*
315  * This is the predictive prefetch entry point.  dmu_zfetch_prepare()
316  * associates dnode access specified with blkid and nblks arguments with
317  * prefetch stream, predicts further accesses based on that stats and returns
318  * the stream pointer on success.  That pointer must later be passed to
319  * dmu_zfetch_run() to initiate the speculative prefetch for the stream and
320  * release it.  dmu_zfetch() is a wrapper for simple cases when window between
321  * prediction and prefetch initiation is not needed.
322  * fetch_data argument specifies whether actual data blocks should be fetched:
323  *   FALSE -- prefetch only indirect blocks for predicted data blocks;
324  *   TRUE -- prefetch predicted data blocks plus following indirect blocks.
325  */
326 zstream_t *
327 dmu_zfetch_prepare(zfetch_t *zf, uint64_t blkid, uint64_t nblks,
328     boolean_t fetch_data, boolean_t have_lock)
329 {
330 	zstream_t *zs;
331 	spa_t *spa = zf->zf_dnode->dn_objset->os_spa;
332 	zfs_prefetch_type_t os_prefetch = zf->zf_dnode->dn_objset->os_prefetch;
333 
334 	if (zfs_prefetch_disable || os_prefetch == ZFS_PREFETCH_NONE)
335 		return (NULL);
336 
337 	if (os_prefetch == ZFS_PREFETCH_METADATA)
338 		fetch_data = B_FALSE;
339 
340 	/*
341 	 * If we haven't yet loaded the indirect vdevs' mappings, we
342 	 * can only read from blocks that we carefully ensure are on
343 	 * concrete vdevs (or previously-loaded indirect vdevs).  So we
344 	 * can't allow the predictive prefetcher to attempt reads of other
345 	 * blocks (e.g. of the MOS's dnode object).
346 	 */
347 	if (!spa_indirect_vdevs_loaded(spa))
348 		return (NULL);
349 
350 	/*
351 	 * As a fast path for small (single-block) files, ignore access
352 	 * to the first block.
353 	 */
354 	if (!have_lock && blkid == 0)
355 		return (NULL);
356 
357 	if (!have_lock)
358 		rw_enter(&zf->zf_dnode->dn_struct_rwlock, RW_READER);
359 
360 	/*
361 	 * A fast path for small files for which no prefetch will
362 	 * happen.
363 	 */
364 	uint64_t maxblkid = zf->zf_dnode->dn_maxblkid;
365 	if (maxblkid < 2) {
366 		if (!have_lock)
367 			rw_exit(&zf->zf_dnode->dn_struct_rwlock);
368 		return (NULL);
369 	}
370 	mutex_enter(&zf->zf_lock);
371 
372 	/*
373 	 * Find matching prefetch stream.  Depending on whether the accesses
374 	 * are block-aligned, first block of the new access may either follow
375 	 * the last block of the previous access, or be equal to it.
376 	 */
377 	for (zs = list_head(&zf->zf_stream); zs != NULL;
378 	    zs = list_next(&zf->zf_stream, zs)) {
379 		if (blkid == zs->zs_blkid) {
380 			break;
381 		} else if (blkid + 1 == zs->zs_blkid) {
382 			blkid++;
383 			nblks--;
384 			break;
385 		}
386 	}
387 
388 	/*
389 	 * If the file is ending, remove the matching stream if found.
390 	 * If not found then it is too late to create a new one now.
391 	 */
392 	uint64_t end_of_access_blkid = blkid + nblks;
393 	if (end_of_access_blkid >= maxblkid) {
394 		if (zs != NULL)
395 			dmu_zfetch_stream_remove(zf, zs);
396 		mutex_exit(&zf->zf_lock);
397 		if (!have_lock)
398 			rw_exit(&zf->zf_dnode->dn_struct_rwlock);
399 		return (NULL);
400 	}
401 
402 	/* Exit if we already prefetched this block before. */
403 	if (nblks == 0) {
404 		mutex_exit(&zf->zf_lock);
405 		if (!have_lock)
406 			rw_exit(&zf->zf_dnode->dn_struct_rwlock);
407 		return (NULL);
408 	}
409 
410 	if (zs == NULL) {
411 		/*
412 		 * This access is not part of any existing stream.  Create
413 		 * a new stream for it.
414 		 */
415 		dmu_zfetch_stream_create(zf, end_of_access_blkid);
416 		mutex_exit(&zf->zf_lock);
417 		if (!have_lock)
418 			rw_exit(&zf->zf_dnode->dn_struct_rwlock);
419 		ZFETCHSTAT_BUMP(zfetchstat_misses);
420 		return (NULL);
421 	}
422 
423 	/*
424 	 * This access was to a block that we issued a prefetch for on
425 	 * behalf of this stream.  Calculate further prefetch distances.
426 	 *
427 	 * Start prefetch from the demand access size (nblks).  Double the
428 	 * distance every access up to zfetch_min_distance.  After that only
429 	 * if needed increase the distance by 1/8 up to zfetch_max_distance.
430 	 *
431 	 * Don't double the distance beyond single block if we have more
432 	 * than ~6% of ARC held by active prefetches.  It should help with
433 	 * getting out of RAM on some badly mispredicted read patterns.
434 	 */
435 	unsigned int dbs = zf->zf_dnode->dn_datablkshift;
436 	unsigned int nbytes = nblks << dbs;
437 	unsigned int pf_nblks;
438 	if (fetch_data) {
439 		if (unlikely(zs->zs_pf_dist < nbytes))
440 			zs->zs_pf_dist = nbytes;
441 		else if (zs->zs_pf_dist < zfetch_min_distance &&
442 		    (zs->zs_pf_dist < (1 << dbs) ||
443 		    aggsum_compare(&zfetch_sums.zfetchstat_io_active,
444 		    arc_c_max >> (4 + dbs)) < 0))
445 			zs->zs_pf_dist *= 2;
446 		else if (zs->zs_more)
447 			zs->zs_pf_dist += zs->zs_pf_dist / 8;
448 		zs->zs_more = B_FALSE;
449 		if (zs->zs_pf_dist > zfetch_max_distance)
450 			zs->zs_pf_dist = zfetch_max_distance;
451 		pf_nblks = zs->zs_pf_dist >> dbs;
452 	} else {
453 		pf_nblks = 0;
454 	}
455 	if (zs->zs_pf_start < end_of_access_blkid)
456 		zs->zs_pf_start = end_of_access_blkid;
457 	if (zs->zs_pf_end < end_of_access_blkid + pf_nblks)
458 		zs->zs_pf_end = end_of_access_blkid + pf_nblks;
459 
460 	/*
461 	 * Do the same for indirects, starting where we will stop reading
462 	 * data blocks (and the indirects that point to them).
463 	 */
464 	if (unlikely(zs->zs_ipf_dist < nbytes))
465 		zs->zs_ipf_dist = nbytes;
466 	else
467 		zs->zs_ipf_dist *= 2;
468 	if (zs->zs_ipf_dist > zfetch_max_idistance)
469 		zs->zs_ipf_dist = zfetch_max_idistance;
470 	pf_nblks = zs->zs_ipf_dist >> dbs;
471 	if (zs->zs_ipf_start < zs->zs_pf_end)
472 		zs->zs_ipf_start = zs->zs_pf_end;
473 	if (zs->zs_ipf_end < zs->zs_pf_end + pf_nblks)
474 		zs->zs_ipf_end = zs->zs_pf_end + pf_nblks;
475 
476 	zs->zs_blkid = end_of_access_blkid;
477 	/* Protect the stream from reclamation. */
478 	zs->zs_atime = gethrtime();
479 	zfs_refcount_add(&zs->zs_refs, NULL);
480 	/* Count concurrent callers. */
481 	zfs_refcount_add(&zs->zs_callers, NULL);
482 	mutex_exit(&zf->zf_lock);
483 
484 	if (!have_lock)
485 		rw_exit(&zf->zf_dnode->dn_struct_rwlock);
486 
487 	ZFETCHSTAT_BUMP(zfetchstat_hits);
488 	return (zs);
489 }
490 
491 void
492 dmu_zfetch_run(zstream_t *zs, boolean_t missed, boolean_t have_lock)
493 {
494 	zfetch_t *zf = zs->zs_fetch;
495 	int64_t pf_start, pf_end, ipf_start, ipf_end;
496 	int epbs, issued;
497 
498 	if (missed)
499 		zs->zs_missed = missed;
500 
501 	/*
502 	 * Postpone the prefetch if there are more concurrent callers.
503 	 * It happens when multiple requests are waiting for the same
504 	 * indirect block.  The last one will run the prefetch for all.
505 	 */
506 	if (zfs_refcount_remove(&zs->zs_callers, NULL) != 0) {
507 		/* Drop reference taken in dmu_zfetch_prepare(). */
508 		if (zfs_refcount_remove(&zs->zs_refs, NULL) == 0)
509 			dmu_zfetch_stream_fini(zs);
510 		return;
511 	}
512 
513 	mutex_enter(&zf->zf_lock);
514 	if (zs->zs_missed) {
515 		pf_start = zs->zs_pf_start;
516 		pf_end = zs->zs_pf_start = zs->zs_pf_end;
517 	} else {
518 		pf_start = pf_end = 0;
519 	}
520 	ipf_start = zs->zs_ipf_start;
521 	ipf_end = zs->zs_ipf_start = zs->zs_ipf_end;
522 	mutex_exit(&zf->zf_lock);
523 	ASSERT3S(pf_start, <=, pf_end);
524 	ASSERT3S(ipf_start, <=, ipf_end);
525 
526 	epbs = zf->zf_dnode->dn_indblkshift - SPA_BLKPTRSHIFT;
527 	ipf_start = P2ROUNDUP(ipf_start, 1 << epbs) >> epbs;
528 	ipf_end = P2ROUNDUP(ipf_end, 1 << epbs) >> epbs;
529 	ASSERT3S(ipf_start, <=, ipf_end);
530 	issued = pf_end - pf_start + ipf_end - ipf_start;
531 	if (issued > 1) {
532 		/* More references on top of taken in dmu_zfetch_prepare(). */
533 		zfs_refcount_add_few(&zs->zs_refs, issued - 1, NULL);
534 	} else if (issued == 0) {
535 		/* Some other thread has done our work, so drop the ref. */
536 		if (zfs_refcount_remove(&zs->zs_refs, NULL) == 0)
537 			dmu_zfetch_stream_fini(zs);
538 		return;
539 	}
540 	aggsum_add(&zfetch_sums.zfetchstat_io_active, issued);
541 
542 	if (!have_lock)
543 		rw_enter(&zf->zf_dnode->dn_struct_rwlock, RW_READER);
544 
545 	issued = 0;
546 	for (int64_t blk = pf_start; blk < pf_end; blk++) {
547 		issued += dbuf_prefetch_impl(zf->zf_dnode, 0, blk,
548 		    ZIO_PRIORITY_ASYNC_READ, 0, dmu_zfetch_done, zs);
549 	}
550 	for (int64_t iblk = ipf_start; iblk < ipf_end; iblk++) {
551 		issued += dbuf_prefetch_impl(zf->zf_dnode, 1, iblk,
552 		    ZIO_PRIORITY_ASYNC_READ, 0, dmu_zfetch_done, zs);
553 	}
554 
555 	if (!have_lock)
556 		rw_exit(&zf->zf_dnode->dn_struct_rwlock);
557 
558 	if (issued)
559 		ZFETCHSTAT_ADD(zfetchstat_io_issued, issued);
560 }
561 
562 void
563 dmu_zfetch(zfetch_t *zf, uint64_t blkid, uint64_t nblks, boolean_t fetch_data,
564     boolean_t missed, boolean_t have_lock)
565 {
566 	zstream_t *zs;
567 
568 	zs = dmu_zfetch_prepare(zf, blkid, nblks, fetch_data, have_lock);
569 	if (zs)
570 		dmu_zfetch_run(zs, missed, have_lock);
571 }
572 
573 ZFS_MODULE_PARAM(zfs_prefetch, zfs_prefetch_, disable, INT, ZMOD_RW,
574 	"Disable all ZFS prefetching");
575 
576 ZFS_MODULE_PARAM(zfs_prefetch, zfetch_, max_streams, UINT, ZMOD_RW,
577 	"Max number of streams per zfetch");
578 
579 ZFS_MODULE_PARAM(zfs_prefetch, zfetch_, min_sec_reap, UINT, ZMOD_RW,
580 	"Min time before stream reclaim");
581 
582 ZFS_MODULE_PARAM(zfs_prefetch, zfetch_, max_sec_reap, UINT, ZMOD_RW,
583 	"Max time before stream delete");
584 
585 ZFS_MODULE_PARAM(zfs_prefetch, zfetch_, min_distance, UINT, ZMOD_RW,
586 	"Min bytes to prefetch per stream");
587 
588 ZFS_MODULE_PARAM(zfs_prefetch, zfetch_, max_distance, UINT, ZMOD_RW,
589 	"Max bytes to prefetch per stream");
590 
591 ZFS_MODULE_PARAM(zfs_prefetch, zfetch_, max_idistance, UINT, ZMOD_RW,
592 	"Max bytes to prefetch indirects for per stream");
593