mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-26 12:12:13 +03:00
Cleanup: Specify unsignedness on things that should not be signed
In #13871, zfs_vdev_aggregation_limit_non_rotating and zfs_vdev_aggregation_limit being signed was pointed out as a possible reason not to eliminate an unnecessary MAX(unsigned, 0) since the unsigned value was assigned from them. There is no reason for these module parameters to be signed and upon inspection, it was found that there are a number of other module parameters that are signed, but should not be, so we make them unsigned. Making them unsigned made it clear that some other variables in the code should also be unsigned, so we also make those unsigned. This prevents users from setting negative values that could potentially cause bad behaviors. It also makes the code slightly easier to understand. Mostly module parameters that deal with timeouts, limits, bitshifts and percentages are made unsigned by this. Any that are boolean are left signed, since whether booleans should be considered signed or unsigned does not matter. Making zfs_arc_lotsfree_percent unsigned caused a `zfs_arc_lotsfree_percent >= 0` check to become redundant, so it was removed. Removing the check was also necessary to prevent a compiler error from -Werror=type-limits. Several end of line comments had to be moved to their own lines because replacing int with uint_t caused us to exceed the 80 character limit enforced by cstyle.pl. The following were kept signed because they are passed to taskq_create(), which expects signed values and modifying the OpenSolaris/Illumos DDI is out of scope of this patch: * metaslab_load_pct * zfs_sync_taskq_batch_pct * zfs_zil_clean_taskq_nthr_pct * zfs_zil_clean_taskq_minalloc * zfs_zil_clean_taskq_maxalloc * zfs_arc_prune_task_threads Also, negative values in those parameters was found to be harmless. The following were left signed because either negative values make sense, or more analysis was needed to determine whether negative values should be disallowed: * zfs_metaslab_switch_threshold * zfs_pd_bytes_max * zfs_livelist_min_percent_shared zfs_multihost_history was made static to be consistent with other parameters. A number of module parameters were marked as signed, but in reality referenced unsigned variables. upgrade_errlog_limit is one of the numerous examples. In the case of zfs_vdev_async_read_max_active, it was already uint32_t, but zdb had an extern int declaration for it. Interestingly, the documentation in zfs.4 was right for upgrade_errlog_limit despite the module parameter being wrongly marked, while the documentation for zfs_vdev_async_read_max_active (and friends) was wrong. It was also wrong for zstd_abort_size, which was unsigned, but was documented as signed. Also, the documentation in zfs.4 incorrectly described the following parameters as ulong when they were int: * zfs_arc_meta_adjust_restarts * zfs_override_estimate_recordsize They are now uint_t as of this patch and thus the man page has been updated to describe them as uint. dbuf_state_index was left alone since it does nothing and perhaps should be removed in another patch. If any module parameters were missed, they were not found by `grep -r 'ZFS_MODULE_PARAM' | grep ', INT'`. I did find a few that grep missed, but only because they were in files that had hits. This patch intentionally did not attempt to address whether some of these module parameters should be elevated to 64-bit parameters, because the length of a long on 32-bit is 32-bit. Lastly, it was pointed out during review that uint_t is a better match for these variables than uint32_t because FreeBSD kernel parameter definitions are designed for uint_t, whose bit width can change in future memory models. As a result, we change the existing parameters that are uint32_t to use uint_t. Reviewed-by: Alexander Motin <mav@FreeBSD.org> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Neal Gompa <ngompa@datto.com> Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu> Closes #13875
This commit is contained in:
+22
-22
@@ -81,7 +81,7 @@ int zfs_metaslab_sm_blksz_with_log = (1 << 17);
|
||||
* space map representation must be before we compact it on-disk.
|
||||
* Values should be greater than or equal to 100.
|
||||
*/
|
||||
int zfs_condense_pct = 200;
|
||||
uint_t zfs_condense_pct = 200;
|
||||
|
||||
/*
|
||||
* Condensing a metaslab is not guaranteed to actually reduce the amount of
|
||||
@@ -111,7 +111,7 @@ static const int zfs_metaslab_condense_block_threshold = 4;
|
||||
* eligible to allocate on any metaslab group. The default value of 0 means
|
||||
* no metaslab group will be excluded based on this criterion.
|
||||
*/
|
||||
static int zfs_mg_noalloc_threshold = 0;
|
||||
static uint_t zfs_mg_noalloc_threshold = 0;
|
||||
|
||||
/*
|
||||
* Metaslab groups are considered eligible for allocations if their
|
||||
@@ -135,7 +135,7 @@ static int zfs_mg_noalloc_threshold = 0;
|
||||
* enough to avoid hitting the speed bump on pools that are being pushed
|
||||
* to the edge.
|
||||
*/
|
||||
static int zfs_mg_fragmentation_threshold = 95;
|
||||
static uint_t zfs_mg_fragmentation_threshold = 95;
|
||||
|
||||
/*
|
||||
* Allow metaslabs to keep their active state as long as their fragmentation
|
||||
@@ -143,7 +143,7 @@ static int zfs_mg_fragmentation_threshold = 95;
|
||||
* active metaslab that exceeds this threshold will no longer keep its active
|
||||
* status allowing better metaslabs to be selected.
|
||||
*/
|
||||
static int zfs_metaslab_fragmentation_threshold = 70;
|
||||
static uint_t zfs_metaslab_fragmentation_threshold = 70;
|
||||
|
||||
/*
|
||||
* When set will load all metaslabs when pool is first opened.
|
||||
@@ -169,7 +169,7 @@ uint64_t metaslab_df_alloc_threshold = SPA_OLD_MAXBLOCKSIZE;
|
||||
* Once the space map's free space drops below this level we dynamically
|
||||
* switch to using best-fit allocations.
|
||||
*/
|
||||
int metaslab_df_free_pct = 4;
|
||||
uint_t metaslab_df_free_pct = 4;
|
||||
|
||||
/*
|
||||
* Maximum distance to search forward from the last offset. Without this
|
||||
@@ -184,7 +184,7 @@ int metaslab_df_free_pct = 4;
|
||||
* With the default setting of 16MB this is 16*1024 (with ashift=9) or
|
||||
* 2048 (with ashift=12).
|
||||
*/
|
||||
static int metaslab_df_max_search = 16 * 1024 * 1024;
|
||||
static uint_t metaslab_df_max_search = 16 * 1024 * 1024;
|
||||
|
||||
/*
|
||||
* Forces the metaslab_block_picker function to search for at least this many
|
||||
@@ -215,13 +215,13 @@ int metaslab_load_pct = 50;
|
||||
* unloaded sooner. These settings are intended to be generous -- to keep
|
||||
* metaslabs loaded for a long time, reducing the rate of metaslab loading.
|
||||
*/
|
||||
static int metaslab_unload_delay = 32;
|
||||
static int metaslab_unload_delay_ms = 10 * 60 * 1000; /* ten minutes */
|
||||
static uint_t metaslab_unload_delay = 32;
|
||||
static uint_t metaslab_unload_delay_ms = 10 * 60 * 1000; /* ten minutes */
|
||||
|
||||
/*
|
||||
* Max number of metaslabs per group to preload.
|
||||
*/
|
||||
int metaslab_preload_limit = 10;
|
||||
uint_t metaslab_preload_limit = 10;
|
||||
|
||||
/*
|
||||
* Enable/disable preloading of metaslab.
|
||||
@@ -293,7 +293,7 @@ static unsigned long zfs_metaslab_max_size_cache_sec = 1 * 60 * 60; /* 1 hour */
|
||||
* a metaslab would take it over this percentage, the oldest selected metaslab
|
||||
* is automatically unloaded.
|
||||
*/
|
||||
static int zfs_metaslab_mem_limit = 25;
|
||||
static uint_t zfs_metaslab_mem_limit = 25;
|
||||
|
||||
/*
|
||||
* Force the per-metaslab range trees to use 64-bit integers to store
|
||||
@@ -337,7 +337,7 @@ static int zfs_metaslab_try_hard_before_gang = B_FALSE;
|
||||
* subsequent metaslab has ms_max_size >60KB (but fewer segments in this
|
||||
* bucket, and therefore a lower weight).
|
||||
*/
|
||||
static int zfs_metaslab_find_max_tries = 100;
|
||||
static uint_t zfs_metaslab_find_max_tries = 100;
|
||||
|
||||
static uint64_t metaslab_weight(metaslab_t *, boolean_t);
|
||||
static void metaslab_set_fragmentation(metaslab_t *, boolean_t);
|
||||
@@ -1672,7 +1672,7 @@ metaslab_df_alloc(metaslab_t *msp, uint64_t size)
|
||||
uint64_t align = size & -size;
|
||||
uint64_t *cursor = &msp->ms_lbas[highbit64(align) - 1];
|
||||
range_tree_t *rt = msp->ms_allocatable;
|
||||
int free_pct = range_tree_space(rt) * 100 / msp->ms_size;
|
||||
uint_t free_pct = range_tree_space(rt) * 100 / msp->ms_size;
|
||||
uint64_t offset;
|
||||
|
||||
ASSERT(MUTEX_HELD(&msp->ms_lock));
|
||||
@@ -2169,7 +2169,7 @@ metaslab_potentially_evict(metaslab_class_t *mc)
|
||||
uint64_t allmem = arc_all_memory();
|
||||
uint64_t inuse = spl_kmem_cache_inuse(zfs_btree_leaf_cache);
|
||||
uint64_t size = spl_kmem_cache_entry_size(zfs_btree_leaf_cache);
|
||||
int tries = 0;
|
||||
uint_t tries = 0;
|
||||
for (; allmem * zfs_metaslab_mem_limit / 100 < inuse * size &&
|
||||
tries < multilist_get_num_sublists(&mc->mc_metaslab_txg_list) * 2;
|
||||
tries++) {
|
||||
@@ -4640,7 +4640,7 @@ find_valid_metaslab(metaslab_group_t *mg, uint64_t activation_weight,
|
||||
if (msp == NULL)
|
||||
msp = avl_nearest(t, idx, AVL_AFTER);
|
||||
|
||||
int tries = 0;
|
||||
uint_t tries = 0;
|
||||
for (; msp != NULL; msp = AVL_NEXT(t, msp)) {
|
||||
int i;
|
||||
|
||||
@@ -6215,18 +6215,18 @@ ZFS_MODULE_PARAM(zfs_metaslab, metaslab_, debug_unload, INT, ZMOD_RW,
|
||||
ZFS_MODULE_PARAM(zfs_metaslab, metaslab_, preload_enabled, INT, ZMOD_RW,
|
||||
"Preload potential metaslabs during reassessment");
|
||||
|
||||
ZFS_MODULE_PARAM(zfs_metaslab, metaslab_, unload_delay, INT, ZMOD_RW,
|
||||
ZFS_MODULE_PARAM(zfs_metaslab, metaslab_, unload_delay, UINT, ZMOD_RW,
|
||||
"Delay in txgs after metaslab was last used before unloading");
|
||||
|
||||
ZFS_MODULE_PARAM(zfs_metaslab, metaslab_, unload_delay_ms, INT, ZMOD_RW,
|
||||
ZFS_MODULE_PARAM(zfs_metaslab, metaslab_, unload_delay_ms, UINT, ZMOD_RW,
|
||||
"Delay in milliseconds after metaslab was last used before unloading");
|
||||
|
||||
/* BEGIN CSTYLED */
|
||||
ZFS_MODULE_PARAM(zfs_mg, zfs_mg_, noalloc_threshold, INT, ZMOD_RW,
|
||||
ZFS_MODULE_PARAM(zfs_mg, zfs_mg_, noalloc_threshold, UINT, ZMOD_RW,
|
||||
"Percentage of metaslab group size that should be free to make it "
|
||||
"eligible for allocation");
|
||||
|
||||
ZFS_MODULE_PARAM(zfs_mg, zfs_mg_, fragmentation_threshold, INT, ZMOD_RW,
|
||||
ZFS_MODULE_PARAM(zfs_mg, zfs_mg_, fragmentation_threshold, UINT, ZMOD_RW,
|
||||
"Percentage of metaslab group size that should be considered eligible "
|
||||
"for allocations unless all metaslab groups within the metaslab class "
|
||||
"have also crossed this threshold");
|
||||
@@ -6236,7 +6236,7 @@ ZFS_MODULE_PARAM(zfs_metaslab, metaslab_, fragmentation_factor_enabled, INT,
|
||||
"Use the fragmentation metric to prefer less fragmented metaslabs");
|
||||
/* END CSTYLED */
|
||||
|
||||
ZFS_MODULE_PARAM(zfs_metaslab, zfs_metaslab_, fragmentation_threshold, INT,
|
||||
ZFS_MODULE_PARAM(zfs_metaslab, zfs_metaslab_, fragmentation_threshold, UINT,
|
||||
ZMOD_RW, "Fragmentation for metaslab to allow allocation");
|
||||
|
||||
ZFS_MODULE_PARAM(zfs_metaslab, metaslab_, lba_weighting_enabled, INT, ZMOD_RW,
|
||||
@@ -6254,7 +6254,7 @@ ZFS_MODULE_PARAM(zfs_metaslab, zfs_metaslab_, switch_threshold, INT, ZMOD_RW,
|
||||
ZFS_MODULE_PARAM(zfs_metaslab, metaslab_, force_ganging, ULONG, ZMOD_RW,
|
||||
"Blocks larger than this size are forced to be gang blocks");
|
||||
|
||||
ZFS_MODULE_PARAM(zfs_metaslab, metaslab_, df_max_search, INT, ZMOD_RW,
|
||||
ZFS_MODULE_PARAM(zfs_metaslab, metaslab_, df_max_search, UINT, ZMOD_RW,
|
||||
"Max distance (bytes) to search forward before using size tree");
|
||||
|
||||
ZFS_MODULE_PARAM(zfs_metaslab, metaslab_, df_use_largest_segment, INT, ZMOD_RW,
|
||||
@@ -6263,11 +6263,11 @@ ZFS_MODULE_PARAM(zfs_metaslab, metaslab_, df_use_largest_segment, INT, ZMOD_RW,
|
||||
ZFS_MODULE_PARAM(zfs_metaslab, zfs_metaslab_, max_size_cache_sec, ULONG,
|
||||
ZMOD_RW, "How long to trust the cached max chunk size of a metaslab");
|
||||
|
||||
ZFS_MODULE_PARAM(zfs_metaslab, zfs_metaslab_, mem_limit, INT, ZMOD_RW,
|
||||
ZFS_MODULE_PARAM(zfs_metaslab, zfs_metaslab_, mem_limit, UINT, ZMOD_RW,
|
||||
"Percentage of memory that can be used to store metaslab range trees");
|
||||
|
||||
ZFS_MODULE_PARAM(zfs_metaslab, zfs_metaslab_, try_hard_before_gang, INT,
|
||||
ZMOD_RW, "Try hard to allocate before ganging");
|
||||
|
||||
ZFS_MODULE_PARAM(zfs_metaslab, zfs_metaslab_, find_max_tries, INT, ZMOD_RW,
|
||||
ZFS_MODULE_PARAM(zfs_metaslab, zfs_metaslab_, find_max_tries, UINT, ZMOD_RW,
|
||||
"Normally only consider this many of the best metaslabs in each vdev");
|
||||
|
||||
Reference in New Issue
Block a user