1 // SPDX-License-Identifier: CDDL-1.0 2 /* 3 * This file and its contents are supplied under the terms of the 4 * Common Development and Distribution License ("CDDL"), version 1.0. 5 * You may only use this file in accordance with the terms of version 6 * 1.0 of the CDDL. 7 * 8 * A full copy of the text of the CDDL should have accompanied this 9 * source. A copy of the CDDL is also available via the Internet at 10 * https://opensource.org/license/CDDL-1.0. 11 */ 12 /* 13 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 14 * Use is subject to license terms. 15 */ 16 17 /* 18 * Copyright (c) 2014, 2017 by Delphix. All rights reserved. 19 */ 20 21 #ifndef _DMU_ZFETCH_H 22 #define _DMU_ZFETCH_H 23 24 #include <sys/zfs_context.h> 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 struct dnode; /* so we can reference dnode */ 31 32 typedef struct zfetch { 33 kmutex_t zf_lock; /* protects zfetch structure */ 34 list_t zf_stream; /* list of zstream_t's */ 35 struct dnode *zf_dnode; /* dnode that owns this zfetch */ 36 int zf_numstreams; /* number of zstream_t's */ 37 } zfetch_t; 38 39 typedef struct zsrange { 40 uint16_t start; 41 uint16_t end; 42 } zsrange_t; 43 44 #define ZFETCH_RANGES 9 /* Fits zstream_t into 128 bytes */ 45 46 typedef struct zstream { 47 list_node_t zs_node; /* link for zf_stream */ 48 uint64_t zs_blkid; /* expect next access at this blkid */ 49 uint_t zs_atime; /* time last prefetch issued */ 50 zsrange_t zs_ranges[ZFETCH_RANGES]; /* ranges from future */ 51 unsigned int zs_pf_dist; /* data prefetch distance in bytes */ 52 unsigned int zs_ipf_dist; /* L1 prefetch distance in bytes */ 53 uint64_t zs_pf_start; /* first data block to prefetch */ 54 uint64_t zs_pf_end; /* data block to prefetch up to */ 55 uint64_t zs_ipf_start; /* first data block to prefetch L1 */ 56 uint64_t zs_ipf_end; /* data block to prefetch L1 up to */ 57 boolean_t zs_missed; /* stream saw cache misses */ 58 boolean_t zs_more; /* need more distant prefetch */ 59 zfs_refcount_t zs_callers; /* number of pending callers */ 60 /* 61 * Number of stream references: dnode, callers and pending blocks. 62 * The stream memory is freed when the number returns to zero. 63 */ 64 zfs_refcount_t zs_refs; 65 } zstream_t; 66 67 void zfetch_init(void); 68 void zfetch_fini(void); 69 70 void dmu_zfetch_init(zfetch_t *, struct dnode *); 71 void dmu_zfetch_fini(zfetch_t *); 72 boolean_t dmu_zfetch_prime(zfetch_t *, uint64_t, uint64_t); 73 zstream_t *dmu_zfetch_prepare(zfetch_t *, uint64_t, uint64_t, boolean_t, 74 boolean_t); 75 void dmu_zfetch_run(zfetch_t *, zstream_t *, boolean_t, boolean_t, 76 boolean_t); 77 void dmu_zfetch(zfetch_t *, uint64_t, uint64_t, boolean_t, boolean_t, 78 boolean_t, boolean_t); 79 80 81 #ifdef __cplusplus 82 } 83 #endif 84 85 #endif /* _DMU_ZFETCH_H */ 86