Skip to content

Commit

Permalink
add prefetch property
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
shodanshok committed Sep 3, 2023
1 parent 95f71c0 commit 0c75753
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/sys/dmu_objset.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ struct objset {
dmu_objset_upgrade_cb_t os_upgrade_cb;
boolean_t os_upgrade_exit;
int os_upgrade_status;

/* prefetch */
boolean_t os_prefetch;
};

#define DMU_META_OBJSET 0
Expand Down
1 change: 1 addition & 0 deletions include/sys/fs/zfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ typedef enum {
ZFS_PROP_REDACTED,
ZFS_PROP_REDACT_SNAPS,
ZFS_PROP_SNAPSHOTS_CHANGED,
ZFS_PROP_PREFETCH,
ZFS_NUM_PROPS
} zfs_prop_t;

Expand Down
4 changes: 4 additions & 0 deletions module/zcommon/zfs_prop.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,10 @@ zfs_prop_init(void)
ZFS_TYPE_VOLUME, "<date>", "SNAPSHOTS_CHANGED", B_FALSE, B_TRUE,
B_TRUE, NULL, sfeatures);

zprop_register_index(ZFS_PROP_PREFETCH, "prefetch", 1, PROP_INHERIT,

Check failure on line 749 in module/zcommon/zfs_prop.c

View workflow job for this annotation

GitHub Actions / checkstyle

indent by spaces instead of tabs

Check failure on line 749 in module/zcommon/zfs_prop.c

View workflow job for this annotation

GitHub Actions / checkstyle

non-continuation indented 4 spaces
ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,

Check failure on line 750 in module/zcommon/zfs_prop.c

View workflow job for this annotation

GitHub Actions / checkstyle

indent by spaces instead of tabs
"on | off", "PREFETCH", boolean_table, sfeatures);

Check failure on line 751 in module/zcommon/zfs_prop.c

View workflow job for this annotation

GitHub Actions / checkstyle

indent by spaces instead of tabs

zfs_mod_list_supported_free(sfeatures);
}

Expand Down
17 changes: 17 additions & 0 deletions module/zfs/dmu_objset.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,18 @@ secondary_cache_changed_cb(void *arg, uint64_t newval)
os->os_secondary_cache = newval;
}

static void
prefetch_changed_cb(void *arg, uint64_t newval)
{
objset_t *os = arg;

/*
* Inheritance should have been done by now.
*/

Check failure on line 273 in module/zfs/dmu_objset.c

View workflow job for this annotation

GitHub Actions / checkstyle

improper block comment close
ASSERT(newval == B_TRUE || newval == B_FALSE);
os->os_prefetch = newval;
}

static void
sync_changed_cb(void *arg, uint64_t newval)
{
Expand Down Expand Up @@ -562,6 +574,11 @@ dmu_objset_open_impl(spa_t *spa, dsl_dataset_t *ds, blkptr_t *bp,
zfs_prop_to_name(ZFS_PROP_SECONDARYCACHE),
secondary_cache_changed_cb, os);
}
if (err == 0) {
err = dsl_prop_register(ds,
zfs_prop_to_name(ZFS_PROP_PREFETCH),
prefetch_changed_cb, os);
}
if (!ds->ds_is_snapshot) {
if (err == 0) {
err = dsl_prop_register(ds,
Expand Down
4 changes: 3 additions & 1 deletion module/zfs/dmu_zfetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,11 @@ dmu_zfetch_prepare(zfetch_t *zf, uint64_t blkid, uint64_t nblks,
{
zstream_t *zs;
spa_t *spa = zf->zf_dnode->dn_objset->os_spa;
boolean_t os_prefetch = zf->zf_dnode->dn_objset->os_prefetch;

if (zfs_prefetch_disable)
if (zfs_prefetch_disable || !os_prefetch)
return (NULL);

/*
* If we haven't yet loaded the indirect vdevs' mappings, we
* can only read from blocks that we carefully ensure are on
Expand Down

0 comments on commit 0c75753

Please sign in to comment.