From 9f6943504aec36f897f814fb7ae5987425436b11 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Tue, 30 Nov 2021 10:38:09 -0800 Subject: [PATCH] Default to zfs_dmu_offset_next_sync=1 Strict hole reporting was previously disabled by default as a performance optimization. However, this has lead to confusion over the expected behavior and a variety of workarounds being adopted by consumers of ZFS. Change the default behavior to always report holes and force the TXG sync. Reviewed-by: Matthew Ahrens Reviewed-by: Tony Hutter Signed-off-by: Brian Behlendorf Upstream-commit: 05b3eb6d232009db247882a39d518e7282630753 Ref: #13261 Closes #12746 --- man/man4/zfs.4 | 8 ++++---- module/zfs/dmu.c | 12 ++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/man/man4/zfs.4 b/man/man4/zfs.4 index 657afc6169b6..3eeed8f439fa 100644 --- a/man/man4/zfs.4 +++ b/man/man4/zfs.4 @@ -1581,12 +1581,12 @@ Allow no-operation writes. The occurrence of nopwrites will further depend on other pool properties .Pq i.a. the checksumming and compression algorithms . . -.It Sy zfs_dmu_offset_next_sync Ns = Ns Sy 0 Ns | Ns 1 Pq int +.It Sy zfs_dmu_offset_next_sync Ns = Ns Sy 1 Ns | Ns 0 Pq int Enable forcing TXG sync to find holes. -When enabled forces ZFS to act like prior versions when +When enabled forces ZFS to sync data when .Sy SEEK_HOLE No or Sy SEEK_DATA -flags are used, which, when a dnode is dirty, -causes TXGs to be synced so that this data can be found. +flags are used allowing holes in a file to be accurately reported. +When disabled holes will not be reported in recently dirtied files. . .It Sy zfs_pd_bytes_max Ns = Ns Sy 52428800 Ns B Po 50MB Pc Pq int The number of bytes which should be prefetched during a pool traversal, like diff --git a/module/zfs/dmu.c b/module/zfs/dmu.c index 0c528f68ccf4..4e7127bd1bab 100644 --- a/module/zfs/dmu.c +++ b/module/zfs/dmu.c @@ -73,9 +73,13 @@ int zfs_nopwrite_enabled = 1; unsigned long zfs_per_txg_dirty_frees_percent = 5; /* - * Enable/disable forcing txg sync when dirty in dmu_offset_next. + * Enable/disable forcing txg sync when dirty checking for holes with lseek(). + * By default this is enabled to ensure accurate hole reporting, it can result + * in a significant performance penalty for lseek(SEEK_HOLE) heavy workloads. + * Disabling this option will result in holes never being reported in dirty + * files which is always safe. */ -int zfs_dmu_offset_next_sync = 0; +int zfs_dmu_offset_next_sync = 1; /* * Limit the amount we can prefetch with one call to this amount. This @@ -2110,8 +2114,8 @@ dmu_offset_next(objset_t *os, uint64_t object, boolean_t hole, uint64_t *off) * If the zfs_dmu_offset_next_sync module option is enabled * then strict hole reporting has been requested. Dirty * dnodes must be synced to disk to accurately report all - * holes. When disabled (the default) dirty dnodes are - * reported to not have any holes which is always safe. + * holes. When disabled dirty dnodes are reported to not + * have any holes which is always safe. * * When called by zfs_holey_common() the zp->z_rangelock * is held to prevent zfs_write() and mmap writeback from