Skip to content

Commit 0428749

Browse files
committed
add prefetch property
ZFS prefetch is currently governed by the zfs_prefetch_disable tunable. However, this is a module-wide settings - if a specific dataset benefits from prefetch, while others have issue with it, an optimal solution does not exists. This commit introduce the "prefetch" property, which enable granular control (at dataset/volume level) for prefetching. This patch does not remove the zfs_prefetch_disable, which reimains a system-wide switch for enable/disable prefetch. However, to avoid duplication, it would be preferable to deprecate and then remove the module tunable. Signed-off-by: Gionatan Danti <[email protected]>
1 parent 95f71c0 commit 0428749

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

include/sys/dmu_objset.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ struct objset {
197197
dmu_objset_upgrade_cb_t os_upgrade_cb;
198198
boolean_t os_upgrade_exit;
199199
int os_upgrade_status;
200+
201+
/* prefetch */
202+
boolean_t os_prefetch;
200203
};
201204

202205
#define DMU_META_OBJSET 0

include/sys/fs/zfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ typedef enum {
191191
ZFS_PROP_REDACTED,
192192
ZFS_PROP_REDACT_SNAPS,
193193
ZFS_PROP_SNAPSHOTS_CHANGED,
194+
ZFS_PROP_PREFETCH,
194195
ZFS_NUM_PROPS
195196
} zfs_prop_t;
196197

module/zcommon/zfs_prop.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,10 @@ zfs_prop_init(void)
746746
ZFS_TYPE_VOLUME, "<date>", "SNAPSHOTS_CHANGED", B_FALSE, B_TRUE,
747747
B_TRUE, NULL, sfeatures);
748748

749+
zprop_register_index(ZFS_PROP_PREFETCH, "prefetch", 1, PROP_INHERIT,
750+
ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
751+
"on | off", "PREFETCH", boolean_table, sfeatures);
752+
749753
zfs_mod_list_supported_free(sfeatures);
750754
}
751755

module/zfs/dmu_objset.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,18 @@ secondary_cache_changed_cb(void *arg, uint64_t newval)
263263
os->os_secondary_cache = newval;
264264
}
265265

266+
static void
267+
prefetch_changed_cb(void *arg, uint64_t newval)
268+
{
269+
objset_t *os = arg;
270+
271+
/*
272+
* Inheritance should have been done by now.
273+
*/
274+
ASSERT(newval == B_TRUE || newval == B_FALSE);
275+
os->os_prefetch = newval;
276+
}
277+
266278
static void
267279
sync_changed_cb(void *arg, uint64_t newval)
268280
{
@@ -562,6 +574,11 @@ dmu_objset_open_impl(spa_t *spa, dsl_dataset_t *ds, blkptr_t *bp,
562574
zfs_prop_to_name(ZFS_PROP_SECONDARYCACHE),
563575
secondary_cache_changed_cb, os);
564576
}
577+
if (err == 0) {
578+
err = dsl_prop_register(ds,
579+
zfs_prop_to_name(ZFS_PROP_PREFETCH),
580+
prefetch_changed_cb, os);
581+
}
565582
if (!ds->ds_is_snapshot) {
566583
if (err == 0) {
567584
err = dsl_prop_register(ds,

module/zfs/dmu_zfetch.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,11 @@ dmu_zfetch_prepare(zfetch_t *zf, uint64_t blkid, uint64_t nblks,
329329
{
330330
zstream_t *zs;
331331
spa_t *spa = zf->zf_dnode->dn_objset->os_spa;
332+
boolean_t os_prefetch = zf->zf_dnode->dn_objset->os_prefetch;
332333

333-
if (zfs_prefetch_disable)
334+
if (zfs_prefetch_disable || !os_prefetch)
334335
return (NULL);
336+
335337
/*
336338
* If we haven't yet loaded the indirect vdevs' mappings, we
337339
* can only read from blocks that we carefully ensure are on

0 commit comments

Comments
 (0)