From 2ceafb776e4d7fc5c46ce3ba67f37ba3e419c04b Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Thu, 30 Nov 2017 20:36:29 +0000 Subject: [PATCH] Update gmirror metadata less frequently when synchronizing. We periodically record synchronization progress in the metadata block of the disk being synchronized; this allows an interrupted synchronization to be resumed. However, the frequency of these updates heavily pessimized synchronization time on some media. This change modifies gmirror to update metadata based on a time period, and adds a sysctl to control that period. The default value results in a much lower update frequency and increases the completion time for an interrupted rebuild only marginally. Reported by: Andre Albsmeier MFC after: 3 weeks --- sys/geom/mirror/g_mirror.c | 10 ++++++++-- sys/geom/mirror/g_mirror.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/sys/geom/mirror/g_mirror.c b/sys/geom/mirror/g_mirror.c index baa4c1f28fa8..7aec8f24c285 100644 --- a/sys/geom/mirror/g_mirror.c +++ b/sys/geom/mirror/g_mirror.c @@ -71,6 +71,10 @@ SYSCTL_UINT(_kern_geom_mirror, OID_AUTO, disconnect_on_failure, CTLFLAG_RWTUN, static u_int g_mirror_syncreqs = 2; SYSCTL_UINT(_kern_geom_mirror, OID_AUTO, sync_requests, CTLFLAG_RDTUN, &g_mirror_syncreqs, 0, "Parallel synchronization I/O requests."); +static u_int g_mirror_sync_period = 5; +SYSCTL_UINT(_kern_geom_mirror, OID_AUTO, sync_update_period, CTLFLAG_RWTUN, + &g_mirror_sync_period, 0, + "Metadata update period during synchroniztion, in seconds"); #define MSLEEP(ident, mtx, priority, wmesg, timeout) do { \ G_MIRROR_DEBUG(4, "%s: Sleeping %p.", __func__, (ident)); \ @@ -465,6 +469,7 @@ g_mirror_init_disk(struct g_mirror_softc *sc, struct g_provider *pp, disk->d_sync.ds_consumer = NULL; disk->d_sync.ds_offset = md->md_sync_offset; disk->d_sync.ds_offset_done = md->md_sync_offset; + disk->d_sync.ds_update_ts = time_uptime; disk->d_genid = md->md_genid; disk->d_sync.ds_syncid = md->md_syncid; if (errorp != NULL) @@ -1459,10 +1464,11 @@ g_mirror_sync_request(struct bio *bp) if (bp != NULL && bp->bio_offset < offset) offset = bp->bio_offset; } - if (sync->ds_offset_done + (MAXPHYS * 100) < offset) { - /* Update offset_done on every 100 blocks. */ + if (g_mirror_sync_period > 0 && + time_uptime - sync->ds_update_ts > g_mirror_sync_period) { sync->ds_offset_done = offset; g_mirror_update_metadata(disk); + sync->ds_update_ts = time_uptime; } return; } diff --git a/sys/geom/mirror/g_mirror.h b/sys/geom/mirror/g_mirror.h index c29fc53ebde0..84b31100de5f 100644 --- a/sys/geom/mirror/g_mirror.h +++ b/sys/geom/mirror/g_mirror.h @@ -110,6 +110,7 @@ struct g_mirror_disk_sync { off_t ds_offset; /* Offset of next request to send. */ off_t ds_offset_done; /* Offset of already synchronized region. */ + time_t ds_update_ts; /* Time of last metadata update. */ u_int ds_syncid; /* Disk's synchronization ID. */ u_int ds_inflight; /* Number of in-flight sync requests. */ struct bio **ds_bios; /* BIOs for synchronization I/O. */