mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-12-26 19:19:32 +03:00
891568c990
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 <behlendorf1@llnl.gov> Reviewed-by: Adam Moss <c@yotes.com> Reviewed-by: Matthew Ahrens <mahrens@delphix.com> Signed-off-by: Alexander Motin <mav@FreeBSD.org> Sponsored-By: iXsystems, Inc. Closes #11652
91 lines
2.6 KiB
C
91 lines
2.6 KiB
C
/*
|
|
* CDDL HEADER START
|
|
*
|
|
* The contents of this file are subject to the terms of the
|
|
* Common Development and Distribution License (the "License").
|
|
* You may not use this file except in compliance with the License.
|
|
*
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
* or http://www.opensolaris.org/os/licensing.
|
|
* See the License for the specific language governing permissions
|
|
* and limitations under the License.
|
|
*
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
*
|
|
* CDDL HEADER END
|
|
*/
|
|
/*
|
|
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
|
|
* Use is subject to license terms.
|
|
*/
|
|
|
|
/*
|
|
* Copyright (c) 2014, 2017 by Delphix. All rights reserved.
|
|
*/
|
|
|
|
#ifndef _DMU_ZFETCH_H
|
|
#define _DMU_ZFETCH_H
|
|
|
|
#include <sys/zfs_context.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
extern unsigned long zfetch_array_rd_sz;
|
|
|
|
struct dnode; /* so we can reference dnode */
|
|
|
|
typedef struct zfetch {
|
|
kmutex_t zf_lock; /* protects zfetch structure */
|
|
list_t zf_stream; /* list of zstream_t's */
|
|
struct dnode *zf_dnode; /* dnode that owns this zfetch */
|
|
int zf_numstreams; /* number of zstream_t's */
|
|
} zfetch_t;
|
|
|
|
typedef struct zstream {
|
|
uint64_t zs_blkid; /* expect next access at this blkid */
|
|
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_blkid1; /* first block to prefetch */
|
|
uint64_t zs_ipf_blkid; /* block to prefetch up to */
|
|
|
|
list_node_t zs_node; /* link for zf_stream */
|
|
hrtime_t zs_atime; /* time last prefetch issued */
|
|
zfetch_t *zs_fetch; /* parent fetch */
|
|
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);
|
|
void zfetch_fini(void);
|
|
|
|
void dmu_zfetch_init(zfetch_t *, struct dnode *);
|
|
void dmu_zfetch_fini(zfetch_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);
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* _DMU_ZFETCH_H */
|