mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +03:00
Cleanup: 64-bit kernel module parameters should use fixed width types
Various module parameters such as `zfs_arc_max` were originally `uint64_t` on OpenSolaris/Illumos, but were changed to `unsigned long` for Linux compatibility because Linux's kernel default module parameter implementation did not support 64-bit types on 32-bit platforms. This caused problems when porting OpenZFS to Windows because its LLP64 memory model made `unsigned long` a 32-bit type on 64-bit, which created the undesireable situation that parameters that should accept 64-bit values could not on 64-bit Windows. Upon inspection, it turns out that the Linux kernel module parameter interface is extensible, such that we are allowed to define our own types. Rather than maintaining the original type change via hacks to to continue shrinking module parameters on 32-bit Linux, we implement support for 64-bit module parameters on Linux. After doing a review of all 64-bit kernel parameters (found via the man page and also proposed changes by Andrew Innes), the kernel module parameters fell into a few groups: Parameters that were originally 64-bit on Illumos: * dbuf_cache_max_bytes * dbuf_metadata_cache_max_bytes * l2arc_feed_min_ms * l2arc_feed_secs * l2arc_headroom * l2arc_headroom_boost * l2arc_write_boost * l2arc_write_max * metaslab_aliquot * metaslab_force_ganging * zfetch_array_rd_sz * zfs_arc_max * zfs_arc_meta_limit * zfs_arc_meta_min * zfs_arc_min * zfs_async_block_max_blocks * zfs_condense_max_obsolete_bytes * zfs_condense_min_mapping_bytes * zfs_deadman_checktime_ms * zfs_deadman_synctime_ms * zfs_initialize_chunk_size * zfs_initialize_value * zfs_lua_max_instrlimit * zfs_lua_max_memlimit * zil_slog_bulk Parameters that were originally 32-bit on Illumos: * zfs_per_txg_dirty_frees_percent Parameters that were originally `ssize_t` on Illumos: * zfs_immediate_write_sz Note that `ssize_t` is `int32_t` on 32-bit and `int64_t` on 64-bit. It has been upgraded to 64-bit. Parameters that were `long`/`unsigned long` because of Linux/FreeBSD influence: * l2arc_rebuild_blocks_min_l2size * zfs_key_max_salt_uses * zfs_max_log_walking * zfs_max_logsm_summary_length * zfs_metaslab_max_size_cache_sec * zfs_min_metaslabs_to_flush * zfs_multihost_interval * zfs_unflushed_log_block_max * zfs_unflushed_log_block_min * zfs_unflushed_log_block_pct * zfs_unflushed_max_mem_amt * zfs_unflushed_max_mem_ppm New parameters that do not exist in Illumos: * l2arc_trim_ahead * vdev_file_logical_ashift * vdev_file_physical_ashift * zfs_arc_dnode_limit * zfs_arc_dnode_limit_percent * zfs_arc_dnode_reduce_percent * zfs_arc_meta_limit_percent * zfs_arc_sys_free * zfs_deadman_ziotime_ms * zfs_delete_blocks * zfs_history_output_max * zfs_livelist_max_entries * zfs_max_async_dedup_frees * zfs_max_nvlist_src_size * zfs_rebuild_max_segment * zfs_rebuild_vdev_limit * zfs_unflushed_log_txg_max * zfs_vdev_max_auto_ashift * zfs_vdev_min_auto_ashift * zfs_vnops_read_chunk_size * zvol_max_discard_blocks Rather than clutter the lists with commentary, the module parameters that need comments are repeated below. A few parameters were defined in Linux/FreeBSD specific code, where the use of ulong/long is not an issue for portability, so we leave them alone: * zfs_delete_blocks * zfs_key_max_salt_uses * zvol_max_discard_blocks The documentation for a few parameters was found to be incorrect: * zfs_deadman_checktime_ms - incorrectly documented as int * zfs_delete_blocks - not documented as Linux only * zfs_history_output_max - incorrectly documented as int * zfs_vnops_read_chunk_size - incorrectly documented as long * zvol_max_discard_blocks - incorrectly documented as ulong The documentation for these has been fixed, alongside the changes to document the switch to fixed width types. In addition, several kernel module parameters were percentages or held ashift values, so being 64-bit never made sense for them. They have been downgraded to 32-bit: * vdev_file_logical_ashift * vdev_file_physical_ashift * zfs_arc_dnode_limit_percent * zfs_arc_dnode_reduce_percent * zfs_arc_meta_limit_percent * zfs_per_txg_dirty_frees_percent * zfs_unflushed_log_block_pct * zfs_vdev_max_auto_ashift * zfs_vdev_min_auto_ashift Of special note are `zfs_vdev_max_auto_ashift` and `zfs_vdev_min_auto_ashift`, which were already defined as `uint64_t`, and passed to the kernel as `ulong`. This is inherently buggy on big endian 32-bit Linux, since the values would not be written to the correct locations. 32-bit FreeBSD was unaffected because its sysctl code correctly treated this as a `uint64_t`. Lastly, a code comment suggests that `zfs_arc_sys_free` is Linux-specific, but there is nothing to indicate to me that it is Linux-specific. Nothing was done about that. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Jorgen Lundman <lundman@lundman.net> Reviewed-by: Ryan Moeller <ryan@iXsystems.com> Reviewed-by: Alexander Motin <mav@FreeBSD.org> Original-patch-by: Andrew Innes <andrew.c12@gmail.com> Original-patch-by: Jorgen Lundman <lundman@lundman.net> Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu> Closes #13984 Closes #14004
This commit is contained in:
committed by
Brian Behlendorf
parent
ff7a0a108f
commit
ab8d9c1783
@@ -137,11 +137,11 @@ SYSCTL_CONST_STRING(_vfs_zfs_version, OID_AUTO, module, CTLFLAG_RD,
|
||||
/* arc.c */
|
||||
|
||||
int
|
||||
param_set_arc_long(SYSCTL_HANDLER_ARGS)
|
||||
param_set_arc_u64(SYSCTL_HANDLER_ARGS)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = sysctl_handle_long(oidp, arg1, 0, req);
|
||||
err = sysctl_handle_64(oidp, arg1, 0, req);
|
||||
if (err != 0 || req->newptr == NULL)
|
||||
return (err);
|
||||
|
||||
@@ -171,7 +171,7 @@ param_set_arc_max(SYSCTL_HANDLER_ARGS)
|
||||
int err;
|
||||
|
||||
val = zfs_arc_max;
|
||||
err = sysctl_handle_long(oidp, &val, 0, req);
|
||||
err = sysctl_handle_64(oidp, &val, 0, req);
|
||||
if (err != 0 || req->newptr == NULL)
|
||||
return (SET_ERROR(err));
|
||||
|
||||
@@ -203,7 +203,7 @@ param_set_arc_min(SYSCTL_HANDLER_ARGS)
|
||||
int err;
|
||||
|
||||
val = zfs_arc_min;
|
||||
err = sysctl_handle_long(oidp, &val, 0, req);
|
||||
err = sysctl_handle_64(oidp, &val, 0, req);
|
||||
if (err != 0 || req->newptr == NULL)
|
||||
return (SET_ERROR(err));
|
||||
|
||||
@@ -599,7 +599,7 @@ param_set_multihost_interval(SYSCTL_HANDLER_ARGS)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = sysctl_handle_long(oidp, &zfs_multihost_interval, 0, req);
|
||||
err = sysctl_handle_64(oidp, &zfs_multihost_interval, 0, req);
|
||||
if (err != 0 || req->newptr == NULL)
|
||||
return (err);
|
||||
|
||||
@@ -676,7 +676,7 @@ param_set_deadman_synctime(SYSCTL_HANDLER_ARGS)
|
||||
int err;
|
||||
|
||||
val = zfs_deadman_synctime_ms;
|
||||
err = sysctl_handle_long(oidp, &val, 0, req);
|
||||
err = sysctl_handle_64(oidp, &val, 0, req);
|
||||
if (err != 0 || req->newptr == NULL)
|
||||
return (err);
|
||||
zfs_deadman_synctime_ms = val;
|
||||
@@ -693,7 +693,7 @@ param_set_deadman_ziotime(SYSCTL_HANDLER_ARGS)
|
||||
int err;
|
||||
|
||||
val = zfs_deadman_ziotime_ms;
|
||||
err = sysctl_handle_long(oidp, &val, 0, req);
|
||||
err = sysctl_handle_64(oidp, &val, 0, req);
|
||||
if (err != 0 || req->newptr == NULL)
|
||||
return (err);
|
||||
zfs_deadman_ziotime_ms = val;
|
||||
@@ -761,11 +761,11 @@ SYSCTL_INT(_vfs_zfs, OID_AUTO, space_map_ibs, CTLFLAG_RWTUN,
|
||||
int
|
||||
param_set_min_auto_ashift(SYSCTL_HANDLER_ARGS)
|
||||
{
|
||||
uint64_t val;
|
||||
int val;
|
||||
int err;
|
||||
|
||||
val = zfs_vdev_min_auto_ashift;
|
||||
err = sysctl_handle_64(oidp, &val, 0, req);
|
||||
err = sysctl_handle_int(oidp, &val, 0, req);
|
||||
if (err != 0 || req->newptr == NULL)
|
||||
return (SET_ERROR(err));
|
||||
|
||||
@@ -779,20 +779,20 @@ param_set_min_auto_ashift(SYSCTL_HANDLER_ARGS)
|
||||
|
||||
/* BEGIN CSTYLED */
|
||||
SYSCTL_PROC(_vfs_zfs, OID_AUTO, min_auto_ashift,
|
||||
CTLTYPE_U64 | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
|
||||
CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
|
||||
&zfs_vdev_min_auto_ashift, sizeof (zfs_vdev_min_auto_ashift),
|
||||
param_set_min_auto_ashift, "QU",
|
||||
param_set_min_auto_ashift, "IU",
|
||||
"Min ashift used when creating new top-level vdev. (LEGACY)");
|
||||
/* END CSTYLED */
|
||||
|
||||
int
|
||||
param_set_max_auto_ashift(SYSCTL_HANDLER_ARGS)
|
||||
{
|
||||
uint64_t val;
|
||||
int val;
|
||||
int err;
|
||||
|
||||
val = zfs_vdev_max_auto_ashift;
|
||||
err = sysctl_handle_64(oidp, &val, 0, req);
|
||||
err = sysctl_handle_int(oidp, &val, 0, req);
|
||||
if (err != 0 || req->newptr == NULL)
|
||||
return (SET_ERROR(err));
|
||||
|
||||
@@ -806,9 +806,9 @@ param_set_max_auto_ashift(SYSCTL_HANDLER_ARGS)
|
||||
|
||||
/* BEGIN CSTYLED */
|
||||
SYSCTL_PROC(_vfs_zfs, OID_AUTO, max_auto_ashift,
|
||||
CTLTYPE_U64 | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
|
||||
CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
|
||||
&zfs_vdev_max_auto_ashift, sizeof (zfs_vdev_max_auto_ashift),
|
||||
param_set_max_auto_ashift, "QU",
|
||||
param_set_max_auto_ashift, "IU",
|
||||
"Max ashift used when optimizing for logical -> physical sector size on"
|
||||
" new top-level vdevs. (LEGACY)");
|
||||
/* END CSTYLED */
|
||||
|
||||
@@ -40,8 +40,8 @@
|
||||
|
||||
static taskq_t *vdev_file_taskq;
|
||||
|
||||
static unsigned long vdev_file_logical_ashift = SPA_MINBLOCKSHIFT;
|
||||
static unsigned long vdev_file_physical_ashift = SPA_MINBLOCKSHIFT;
|
||||
static uint_t vdev_file_logical_ashift = SPA_MINBLOCKSHIFT;
|
||||
static uint_t vdev_file_physical_ashift = SPA_MINBLOCKSHIFT;
|
||||
|
||||
void
|
||||
vdev_file_init(void)
|
||||
@@ -350,7 +350,7 @@ vdev_ops_t vdev_disk_ops = {
|
||||
|
||||
#endif
|
||||
|
||||
ZFS_MODULE_PARAM(zfs_vdev_file, vdev_file_, logical_ashift, ULONG, ZMOD_RW,
|
||||
ZFS_MODULE_PARAM(zfs_vdev_file, vdev_file_, logical_ashift, UINT, ZMOD_RW,
|
||||
"Logical ashift for file-based devices");
|
||||
ZFS_MODULE_PARAM(zfs_vdev_file, vdev_file_, physical_ashift, ULONG, ZMOD_RW,
|
||||
ZFS_MODULE_PARAM(zfs_vdev_file, vdev_file_, physical_ashift, UINT, ZMOD_RW,
|
||||
"Physical ashift for file-based devices");
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include <sys/cred.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/misc.h>
|
||||
#include <linux/mod_compat.h>
|
||||
|
||||
unsigned long spl_hostid = 0;
|
||||
EXPORT_SYMBOL(spl_hostid);
|
||||
@@ -518,6 +519,29 @@ ddi_copyin(const void *from, void *to, size_t len, int flags)
|
||||
}
|
||||
EXPORT_SYMBOL(ddi_copyin);
|
||||
|
||||
#define define_spl_param(type, fmt) \
|
||||
int \
|
||||
spl_param_get_##type(char *buf, zfs_kernel_param_t *kp) \
|
||||
{ \
|
||||
return (scnprintf(buf, PAGE_SIZE, fmt "\n", \
|
||||
*(type *)kp->arg)); \
|
||||
} \
|
||||
int \
|
||||
spl_param_set_##type(const char *buf, zfs_kernel_param_t *kp) \
|
||||
{ \
|
||||
return (kstrto##type(buf, 0, (type *)kp->arg)); \
|
||||
} \
|
||||
const struct kernel_param_ops spl_param_ops_##type = { \
|
||||
.set = spl_param_set_##type, \
|
||||
.get = spl_param_get_##type, \
|
||||
}; \
|
||||
EXPORT_SYMBOL(spl_param_get_##type); \
|
||||
EXPORT_SYMBOL(spl_param_set_##type); \
|
||||
EXPORT_SYMBOL(spl_param_ops_##type);
|
||||
|
||||
define_spl_param(s64, "%lld")
|
||||
define_spl_param(u64, "%llu")
|
||||
|
||||
/*
|
||||
* Post a uevent to userspace whenever a new vdev adds to the pool. It is
|
||||
* necessary to sync blkid information with udev, which zed daemon uses
|
||||
|
||||
@@ -358,11 +358,11 @@ arc_lowmem_fini(void)
|
||||
}
|
||||
|
||||
int
|
||||
param_set_arc_long(const char *buf, zfs_kernel_param_t *kp)
|
||||
param_set_arc_u64(const char *buf, zfs_kernel_param_t *kp)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = param_set_long(buf, kp);
|
||||
error = spl_param_set_u64(buf, kp);
|
||||
if (error < 0)
|
||||
return (SET_ERROR(error));
|
||||
|
||||
@@ -374,13 +374,13 @@ param_set_arc_long(const char *buf, zfs_kernel_param_t *kp)
|
||||
int
|
||||
param_set_arc_min(const char *buf, zfs_kernel_param_t *kp)
|
||||
{
|
||||
return (param_set_arc_long(buf, kp));
|
||||
return (param_set_arc_u64(buf, kp));
|
||||
}
|
||||
|
||||
int
|
||||
param_set_arc_max(const char *buf, zfs_kernel_param_t *kp)
|
||||
{
|
||||
return (param_set_arc_long(buf, kp));
|
||||
return (param_set_arc_u64(buf, kp));
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@@ -30,7 +30,7 @@ param_set_multihost_interval(const char *val, zfs_kernel_param_t *kp)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = param_set_ulong(val, kp);
|
||||
ret = spl_param_set_u64(val, kp);
|
||||
if (ret < 0)
|
||||
return (ret);
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ param_set_deadman_ziotime(const char *val, zfs_kernel_param_t *kp)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = param_set_ulong(val, kp);
|
||||
error = spl_param_set_u64(val, kp);
|
||||
if (error < 0)
|
||||
return (SET_ERROR(error));
|
||||
|
||||
@@ -74,7 +74,7 @@ param_set_deadman_synctime(const char *val, zfs_kernel_param_t *kp)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = param_set_ulong(val, kp);
|
||||
error = spl_param_set_u64(val, kp);
|
||||
if (error < 0)
|
||||
return (SET_ERROR(error));
|
||||
|
||||
|
||||
@@ -1006,17 +1006,17 @@ MODULE_PARM_DESC(zfs_vdev_scheduler, "I/O scheduler");
|
||||
int
|
||||
param_set_min_auto_ashift(const char *buf, zfs_kernel_param_t *kp)
|
||||
{
|
||||
uint64_t val;
|
||||
uint_t val;
|
||||
int error;
|
||||
|
||||
error = kstrtoull(buf, 0, &val);
|
||||
error = kstrtouint(buf, 0, &val);
|
||||
if (error < 0)
|
||||
return (SET_ERROR(error));
|
||||
|
||||
if (val < ASHIFT_MIN || val > zfs_vdev_max_auto_ashift)
|
||||
return (SET_ERROR(-EINVAL));
|
||||
|
||||
error = param_set_ulong(buf, kp);
|
||||
error = param_set_uint(buf, kp);
|
||||
if (error < 0)
|
||||
return (SET_ERROR(error));
|
||||
|
||||
@@ -1026,17 +1026,17 @@ param_set_min_auto_ashift(const char *buf, zfs_kernel_param_t *kp)
|
||||
int
|
||||
param_set_max_auto_ashift(const char *buf, zfs_kernel_param_t *kp)
|
||||
{
|
||||
uint64_t val;
|
||||
uint_t val;
|
||||
int error;
|
||||
|
||||
error = kstrtoull(buf, 0, &val);
|
||||
error = kstrtouint(buf, 0, &val);
|
||||
if (error < 0)
|
||||
return (SET_ERROR(error));
|
||||
|
||||
if (val > ASHIFT_MAX || val < zfs_vdev_min_auto_ashift)
|
||||
return (SET_ERROR(-EINVAL));
|
||||
|
||||
error = param_set_ulong(buf, kp);
|
||||
error = param_set_uint(buf, kp);
|
||||
if (error < 0)
|
||||
return (SET_ERROR(error));
|
||||
|
||||
|
||||
@@ -53,8 +53,8 @@ static taskq_t *vdev_file_taskq;
|
||||
* impact the vdev_ashift setting which can only be set at vdev creation
|
||||
* time.
|
||||
*/
|
||||
static unsigned long vdev_file_logical_ashift = SPA_MINBLOCKSHIFT;
|
||||
static unsigned long vdev_file_physical_ashift = SPA_MINBLOCKSHIFT;
|
||||
static uint_t vdev_file_logical_ashift = SPA_MINBLOCKSHIFT;
|
||||
static uint_t vdev_file_physical_ashift = SPA_MINBLOCKSHIFT;
|
||||
|
||||
static void
|
||||
vdev_file_hold(vdev_t *vd)
|
||||
@@ -376,7 +376,7 @@ vdev_ops_t vdev_disk_ops = {
|
||||
|
||||
#endif
|
||||
|
||||
ZFS_MODULE_PARAM(zfs_vdev_file, vdev_file_, logical_ashift, ULONG, ZMOD_RW,
|
||||
ZFS_MODULE_PARAM(zfs_vdev_file, vdev_file_, logical_ashift, UINT, ZMOD_RW,
|
||||
"Logical ashift for file-based devices");
|
||||
ZFS_MODULE_PARAM(zfs_vdev_file, vdev_file_, physical_ashift, ULONG, ZMOD_RW,
|
||||
ZFS_MODULE_PARAM(zfs_vdev_file, vdev_file_, physical_ashift, UINT, ZMOD_RW,
|
||||
"Physical ashift for file-based devices");
|
||||
|
||||
Reference in New Issue
Block a user