summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorAlexander Motin <[email protected]>2021-03-20 01:56:11 -0400
committerGitHub <[email protected]>2021-03-19 22:56:11 -0700
commit891568c9907b3631f99a1079344bddf62ca70f56 (patch)
tree2f7dedbade2632f79d08aa4e3433f9f8cda4642c /include
parent296a4a369bc1078a694f88570972330985b3b1b8 (diff)
Split dmu_zfetch() speculation and execution parts
To make better predictions on parallel workloads dmu_zfetch() should be called as early as possible to reduce possible request reordering. In particular, it should be called before dmu_buf_hold_array_by_dnode() calls dbuf_hold(), which may sleep waiting for indirect blocks, waking up multiple threads same time on completion, that can significantly reorder the requests, making the stream look like random. But we should not issue prefetch requests before the on-demand ones, since they may get to the disks first despite the I/O scheduler, increasing on-demand request latency. This patch splits dmu_zfetch() into two functions: dmu_zfetch_prepare() and dmu_zfetch_run(). The first can be executed as early as needed. It only updates statistics and makes predictions without issuing any I/Os. The I/O issuance is handled by dmu_zfetch_run(), which can be called later when all on-demand I/Os are already issued. It even tracks the activity of other concurrent threads, issuing the prefetch only when _all_ on-demand requests are issued. For many years it was a big problem for storage servers, handling deeper request queues from their clients, having to either serialize consequential reads to make ZFS prefetcher usable, or execute the incoming requests as-is and get almost no prefetch from ZFS, relying only on deep enough prefetch by the clients. Benefits of those ways varied, but neither was perfect. With this patch deeper queue sequential read benchmarks with CrystalDiskMark from Windows via iSCSI to FreeBSD target show me much better throughput with almost 100% prefetcher hit rate, comparing to almost zero before. While there, I also removed per-stream zs_lock as useless, completely covered by parent zf_lock. Also I reused zs_blocks refcount to track zf_stream linkage of the stream, since I believe previous zs_fetch == NULL check in dmu_zfetch_stream_done() was racy. Delete prefetch streams when they reach ends of files. It saves up to 1KB of RAM per file, plus reduces searches through the stream list. Block data prefetch (speculation and indirect block prefetch is still done since they are cheaper) if all dbufs of the stream are already in DMU cache. First cache miss immediately fires all the prefetch that would be done for the stream by that time. It saves some CPU time if same files within DMU cache capacity are read over and over. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Adam Moss <[email protected]> Reviewed-by: Matthew Ahrens <[email protected]> Signed-off-by: Alexander Motin <[email protected]> Sponsored-By: iXsystems, Inc. Closes #11652
Diffstat (limited to 'include')
-rw-r--r--include/sys/dmu_zfetch.h23
1 files changed, 16 insertions, 7 deletions
diff --git a/include/sys/dmu_zfetch.h b/include/sys/dmu_zfetch.h
index 34b711fc0..4c220b0c7 100644
--- a/include/sys/dmu_zfetch.h
+++ b/include/sys/dmu_zfetch.h
@@ -49,20 +49,26 @@ typedef struct zfetch {
typedef struct zstream {
uint64_t zs_blkid; /* expect next access at this blkid */
- uint64_t zs_pf_blkid; /* next block to prefetch */
+ uint64_t zs_pf_blkid1; /* first block to prefetch */
+ uint64_t zs_pf_blkid; /* block to prefetch up to */
/*
* We will next prefetch the L1 indirect block of this level-0
* block id.
*/
- uint64_t zs_ipf_blkid;
+ uint64_t zs_ipf_blkid1; /* first block to prefetch */
+ uint64_t zs_ipf_blkid; /* block to prefetch up to */
- kmutex_t zs_lock; /* protects stream */
- hrtime_t zs_atime; /* time last prefetch issued */
- hrtime_t zs_start_time; /* start of last prefetch */
list_node_t zs_node; /* link for zf_stream */
+ hrtime_t zs_atime; /* time last prefetch issued */
zfetch_t *zs_fetch; /* parent fetch */
- zfs_refcount_t zs_blocks; /* number of pending blocks in the stream */
+ boolean_t zs_missed; /* stream saw cache misses */
+ zfs_refcount_t zs_callers; /* number of pending callers */
+ /*
+ * Number of stream references: dnode, callers and pending blocks.
+ * The stream memory is freed when the number returns to zero.
+ */
+ zfs_refcount_t zs_refs;
} zstream_t;
void zfetch_init(void);
@@ -70,7 +76,10 @@ void zfetch_fini(void);
void dmu_zfetch_init(zfetch_t *, struct dnode *);
void dmu_zfetch_fini(zfetch_t *);
-void dmu_zfetch(zfetch_t *, uint64_t, uint64_t, boolean_t,
+zstream_t *dmu_zfetch_prepare(zfetch_t *, uint64_t, uint64_t, boolean_t,
+ boolean_t);
+void dmu_zfetch_run(zstream_t *, boolean_t, boolean_t);
+void dmu_zfetch(zfetch_t *, uint64_t, uint64_t, boolean_t, boolean_t,
boolean_t);