xref: /freebsd-src/sys/contrib/openzfs/module/os/freebsd/zfs/sysctl_os.c (revision e67e85659c0de33e617e5fbf1028c6e8b49eee53)
1 /*
2  * Copyright (c) 2020 iXsystems, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  */
27 
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
30 
31 #include <sys/types.h>
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/conf.h>
35 #include <sys/kernel.h>
36 #include <sys/lock.h>
37 #include <sys/malloc.h>
38 #include <sys/mutex.h>
39 #include <sys/proc.h>
40 #include <sys/errno.h>
41 #include <sys/uio.h>
42 #include <sys/buf.h>
43 #include <sys/file.h>
44 #include <sys/kmem.h>
45 #include <sys/conf.h>
46 #include <sys/cmn_err.h>
47 #include <sys/stat.h>
48 #include <sys/zfs_ioctl.h>
49 #include <sys/zfs_vfsops.h>
50 #include <sys/zfs_znode.h>
51 #include <sys/zap.h>
52 #include <sys/spa.h>
53 #include <sys/spa_impl.h>
54 #include <sys/vdev.h>
55 #include <sys/vdev_impl.h>
56 #include <sys/dmu.h>
57 #include <sys/dsl_dir.h>
58 #include <sys/dsl_dataset.h>
59 #include <sys/dsl_prop.h>
60 #include <sys/dsl_deleg.h>
61 #include <sys/dmu_objset.h>
62 #include <sys/dmu_impl.h>
63 #include <sys/dmu_tx.h>
64 #include <sys/sunddi.h>
65 #include <sys/policy.h>
66 #include <sys/zone.h>
67 #include <sys/nvpair.h>
68 #include <sys/mount.h>
69 #include <sys/taskqueue.h>
70 #include <sys/sdt.h>
71 #include <sys/fs/zfs.h>
72 #include <sys/zfs_ctldir.h>
73 #include <sys/zfs_dir.h>
74 #include <sys/zfs_onexit.h>
75 #include <sys/zvol.h>
76 #include <sys/dsl_scan.h>
77 #include <sys/dmu_objset.h>
78 #include <sys/dmu_send.h>
79 #include <sys/dsl_destroy.h>
80 #include <sys/dsl_bookmark.h>
81 #include <sys/dsl_userhold.h>
82 #include <sys/zfeature.h>
83 #include <sys/zcp.h>
84 #include <sys/zio_checksum.h>
85 #include <sys/vdev_removal.h>
86 #include <sys/dsl_crypt.h>
87 
88 #include <sys/zfs_ioctl_compat.h>
89 #include <sys/zfs_context.h>
90 
91 #include <sys/arc_impl.h>
92 #include <sys/dsl_pool.h>
93 
94 
95 SYSCTL_DECL(_vfs_zfs);
96 SYSCTL_NODE(_vfs_zfs, OID_AUTO, arc, CTLFLAG_RW, 0,
97 	"ZFS adaptive replacement cache");
98 SYSCTL_NODE(_vfs_zfs, OID_AUTO, condense, CTLFLAG_RW, 0, "ZFS condense");
99 SYSCTL_NODE(_vfs_zfs, OID_AUTO, dbuf, CTLFLAG_RW, 0, "ZFS disk buf cache");
100 SYSCTL_NODE(_vfs_zfs, OID_AUTO, dbuf_cache, CTLFLAG_RW, 0,
101 	"ZFS disk buf cache");
102 SYSCTL_NODE(_vfs_zfs, OID_AUTO, deadman, CTLFLAG_RW, 0, "ZFS deadman");
103 SYSCTL_NODE(_vfs_zfs, OID_AUTO, dedup, CTLFLAG_RW, 0, "ZFS dedup");
104 SYSCTL_NODE(_vfs_zfs, OID_AUTO, l2arc, CTLFLAG_RW, 0, "ZFS l2arc");
105 SYSCTL_NODE(_vfs_zfs, OID_AUTO, livelist, CTLFLAG_RW, 0, "ZFS livelist");
106 SYSCTL_NODE(_vfs_zfs, OID_AUTO, lua, CTLFLAG_RW, 0, "ZFS lua");
107 SYSCTL_NODE(_vfs_zfs, OID_AUTO, metaslab, CTLFLAG_RW, 0, "ZFS metaslab");
108 SYSCTL_NODE(_vfs_zfs, OID_AUTO, mg, CTLFLAG_RW, 0, "ZFS metaslab group");
109 SYSCTL_NODE(_vfs_zfs, OID_AUTO, multihost, CTLFLAG_RW, 0,
110 	"ZFS multihost protection");
111 SYSCTL_NODE(_vfs_zfs, OID_AUTO, prefetch, CTLFLAG_RW, 0, "ZFS prefetch");
112 SYSCTL_NODE(_vfs_zfs, OID_AUTO, reconstruct, CTLFLAG_RW, 0, "ZFS reconstruct");
113 SYSCTL_NODE(_vfs_zfs, OID_AUTO, recv, CTLFLAG_RW, 0, "ZFS receive");
114 SYSCTL_NODE(_vfs_zfs, OID_AUTO, send, CTLFLAG_RW, 0, "ZFS send");
115 SYSCTL_NODE(_vfs_zfs, OID_AUTO, spa, CTLFLAG_RW, 0, "ZFS space allocation");
116 SYSCTL_NODE(_vfs_zfs, OID_AUTO, trim, CTLFLAG_RW, 0, "ZFS TRIM");
117 SYSCTL_NODE(_vfs_zfs, OID_AUTO, txg, CTLFLAG_RW, 0, "ZFS transaction group");
118 SYSCTL_NODE(_vfs_zfs, OID_AUTO, vdev, CTLFLAG_RW, 0, "ZFS VDEV");
119 SYSCTL_NODE(_vfs_zfs, OID_AUTO, vnops, CTLFLAG_RW, 0, "ZFS VNOPS");
120 SYSCTL_NODE(_vfs_zfs, OID_AUTO, zevent, CTLFLAG_RW, 0, "ZFS event");
121 SYSCTL_NODE(_vfs_zfs, OID_AUTO, zil, CTLFLAG_RW, 0, "ZFS ZIL");
122 SYSCTL_NODE(_vfs_zfs, OID_AUTO, zio, CTLFLAG_RW, 0, "ZFS ZIO");
123 
124 SYSCTL_NODE(_vfs_zfs_livelist, OID_AUTO, condense, CTLFLAG_RW, 0,
125 	"ZFS livelist condense");
126 SYSCTL_NODE(_vfs_zfs_vdev, OID_AUTO, cache, CTLFLAG_RW, 0, "ZFS VDEV Cache");
127 SYSCTL_NODE(_vfs_zfs_vdev, OID_AUTO, file, CTLFLAG_RW, 0, "ZFS VDEV file");
128 SYSCTL_NODE(_vfs_zfs_vdev, OID_AUTO, mirror, CTLFLAG_RD, 0,
129 	"ZFS VDEV mirror");
130 
131 SYSCTL_DECL(_vfs_zfs_version);
132 SYSCTL_CONST_STRING(_vfs_zfs_version, OID_AUTO, module, CTLFLAG_RD,
133 	(ZFS_META_VERSION "-" ZFS_META_RELEASE), "OpenZFS module version");
134 
135 extern arc_state_t ARC_anon;
136 extern arc_state_t ARC_mru;
137 extern arc_state_t ARC_mru_ghost;
138 extern arc_state_t ARC_mfu;
139 extern arc_state_t ARC_mfu_ghost;
140 extern arc_state_t ARC_l2c_only;
141 
142 /*
143  * minimum lifespan of a prefetch block in clock ticks
144  * (initialized in arc_init())
145  */
146 
147 /* arc.c */
148 
149 int
150 param_set_arc_max(SYSCTL_HANDLER_ARGS)
151 {
152 	uint64_t val;
153 	int err;
154 
155 	val = zfs_arc_max;
156 	err = sysctl_handle_long(oidp, &val, 0, req);
157 	if (err != 0 || req->newptr == NULL)
158 		return (SET_ERROR(err));
159 
160 	if (val != 0 && (val < MIN_ARC_MAX || val <= arc_c_min ||
161 	    val >= arc_all_memory()))
162 		return (SET_ERROR(EINVAL));
163 
164 	zfs_arc_max = val;
165 	arc_tuning_update(B_TRUE);
166 
167 	/* Update the sysctl to the tuned value */
168 	if (val != 0)
169 		zfs_arc_max = arc_c_max;
170 
171 	return (0);
172 }
173 
174 int
175 param_set_arc_min(SYSCTL_HANDLER_ARGS)
176 {
177 	uint64_t val;
178 	int err;
179 
180 	val = zfs_arc_min;
181 	err = sysctl_handle_64(oidp, &val, 0, req);
182 	if (err != 0 || req->newptr == NULL)
183 		return (SET_ERROR(err));
184 
185 	if (val != 0 && (val < 2ULL << SPA_MAXBLOCKSHIFT || val > arc_c_max))
186 		return (SET_ERROR(EINVAL));
187 
188 	zfs_arc_min = val;
189 	arc_tuning_update(B_TRUE);
190 
191 	/* Update the sysctl to the tuned value */
192 	if (val != 0)
193 		zfs_arc_min = arc_c_min;
194 
195 	return (0);
196 }
197 
198 /* legacy compat */
199 extern uint64_t l2arc_write_max;	/* def max write size */
200 extern uint64_t l2arc_write_boost;	/* extra warmup write */
201 extern uint64_t l2arc_headroom;		/* # of dev writes */
202 extern uint64_t l2arc_headroom_boost;
203 extern uint64_t l2arc_feed_secs;	/* interval seconds */
204 extern uint64_t l2arc_feed_min_ms;	/* min interval msecs */
205 extern int l2arc_noprefetch;			/* don't cache prefetch bufs */
206 extern int l2arc_feed_again;			/* turbo warmup */
207 extern int l2arc_norw;			/* no reads during writes */
208 
209 /* BEGIN CSTYLED */
210 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, l2arc_write_max, CTLFLAG_RW,
211 	&l2arc_write_max, 0, "max write size (LEGACY)");
212 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, l2arc_write_boost, CTLFLAG_RW,
213 	&l2arc_write_boost, 0, "extra write during warmup (LEGACY)");
214 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, l2arc_headroom, CTLFLAG_RW,
215 	&l2arc_headroom, 0, "number of dev writes (LEGACY)");
216 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, l2arc_feed_secs, CTLFLAG_RW,
217 	&l2arc_feed_secs, 0, "interval seconds (LEGACY)");
218 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, l2arc_feed_min_ms, CTLFLAG_RW,
219 	&l2arc_feed_min_ms, 0, "min interval milliseconds (LEGACY)");
220 
221 SYSCTL_INT(_vfs_zfs, OID_AUTO, l2arc_noprefetch, CTLFLAG_RW,
222 	&l2arc_noprefetch, 0, "don't cache prefetch bufs (LEGACY)");
223 SYSCTL_INT(_vfs_zfs, OID_AUTO, l2arc_feed_again, CTLFLAG_RW,
224 	&l2arc_feed_again, 0, "turbo warmup (LEGACY)");
225 SYSCTL_INT(_vfs_zfs, OID_AUTO, l2arc_norw, CTLFLAG_RW,
226 	&l2arc_norw, 0, "no reads during writes (LEGACY)");
227 
228 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, anon_size, CTLFLAG_RD,
229 	&ARC_anon.arcs_size.rc_count, 0, "size of anonymous state");
230 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, anon_metadata_esize, CTLFLAG_RD,
231 	&ARC_anon.arcs_esize[ARC_BUFC_METADATA].rc_count, 0,
232 	"size of anonymous state");
233 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, anon_data_esize, CTLFLAG_RD,
234 	&ARC_anon.arcs_esize[ARC_BUFC_DATA].rc_count, 0,
235 	"size of anonymous state");
236 
237 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mru_size, CTLFLAG_RD,
238 	&ARC_mru.arcs_size.rc_count, 0, "size of mru state");
239 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mru_metadata_esize, CTLFLAG_RD,
240 	&ARC_mru.arcs_esize[ARC_BUFC_METADATA].rc_count, 0,
241 	"size of metadata in mru state");
242 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mru_data_esize, CTLFLAG_RD,
243 	&ARC_mru.arcs_esize[ARC_BUFC_DATA].rc_count, 0,
244 	"size of data in mru state");
245 
246 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mru_ghost_size, CTLFLAG_RD,
247 	&ARC_mru_ghost.arcs_size.rc_count, 0, "size of mru ghost state");
248 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mru_ghost_metadata_esize, CTLFLAG_RD,
249 	&ARC_mru_ghost.arcs_esize[ARC_BUFC_METADATA].rc_count, 0,
250 	"size of metadata in mru ghost state");
251 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mru_ghost_data_esize, CTLFLAG_RD,
252 	&ARC_mru_ghost.arcs_esize[ARC_BUFC_DATA].rc_count, 0,
253 	"size of data in mru ghost state");
254 
255 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mfu_size, CTLFLAG_RD,
256 	&ARC_mfu.arcs_size.rc_count, 0, "size of mfu state");
257 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mfu_metadata_esize, CTLFLAG_RD,
258 	&ARC_mfu.arcs_esize[ARC_BUFC_METADATA].rc_count, 0,
259 	"size of metadata in mfu state");
260 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mfu_data_esize, CTLFLAG_RD,
261 	&ARC_mfu.arcs_esize[ARC_BUFC_DATA].rc_count, 0,
262 	"size of data in mfu state");
263 
264 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mfu_ghost_size, CTLFLAG_RD,
265 	&ARC_mfu_ghost.arcs_size.rc_count, 0, "size of mfu ghost state");
266 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mfu_ghost_metadata_esize, CTLFLAG_RD,
267 	&ARC_mfu_ghost.arcs_esize[ARC_BUFC_METADATA].rc_count, 0,
268 	"size of metadata in mfu ghost state");
269 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mfu_ghost_data_esize, CTLFLAG_RD,
270 	&ARC_mfu_ghost.arcs_esize[ARC_BUFC_DATA].rc_count, 0,
271 	"size of data in mfu ghost state");
272 
273 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, l2c_only_size, CTLFLAG_RD,
274 	&ARC_l2c_only.arcs_size.rc_count, 0, "size of mru state");
275 /* END CSTYLED */
276 
277 static int
278 sysctl_vfs_zfs_arc_no_grow_shift(SYSCTL_HANDLER_ARGS)
279 {
280 	int err, val;
281 
282 	val = arc_no_grow_shift;
283 	err = sysctl_handle_int(oidp, &val, 0, req);
284 	if (err != 0 || req->newptr == NULL)
285 		return (err);
286 
287 	if (val < 0 || val >= arc_shrink_shift)
288 		return (EINVAL);
289 
290 	arc_no_grow_shift = val;
291 	return (0);
292 }
293 
294 SYSCTL_PROC(_vfs_zfs, OID_AUTO, arc_no_grow_shift,
295     CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, NULL, sizeof (int),
296     sysctl_vfs_zfs_arc_no_grow_shift, "I",
297 	"log2(fraction of ARC which must be free to allow growing)");
298 
299 int
300 param_set_arc_long(SYSCTL_HANDLER_ARGS)
301 {
302 	int err;
303 
304 	err = sysctl_handle_long(oidp, arg1, 0, req);
305 	if (err != 0 || req->newptr == NULL)
306 		return (err);
307 
308 	arc_tuning_update(B_TRUE);
309 
310 	return (0);
311 }
312 
313 int
314 param_set_arc_int(SYSCTL_HANDLER_ARGS)
315 {
316 	int err;
317 
318 	err = sysctl_handle_int(oidp, arg1, 0, req);
319 	if (err != 0 || req->newptr == NULL)
320 		return (err);
321 
322 	arc_tuning_update(B_TRUE);
323 
324 	return (0);
325 }
326 
327 /* BEGIN CSTYLED */
328 SYSCTL_PROC(_vfs_zfs, OID_AUTO, arc_min,
329 	CTLTYPE_ULONG | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
330 	&zfs_arc_min, sizeof (zfs_arc_min), param_set_arc_min, "LU",
331 	"min arc size (LEGACY)");
332 SYSCTL_PROC(_vfs_zfs, OID_AUTO, arc_max,
333 	CTLTYPE_ULONG | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
334 	&zfs_arc_max, sizeof (zfs_arc_max), param_set_arc_max, "LU",
335 	"max arc size (LEGACY)");
336 /* END CSTYLED */
337 
338 /* dbuf.c */
339 
340 
341 /* dmu.c */
342 
343 /* dmu_zfetch.c */
344 SYSCTL_NODE(_vfs_zfs, OID_AUTO, zfetch, CTLFLAG_RW, 0, "ZFS ZFETCH (LEGACY)");
345 
346 /* max bytes to prefetch per stream (default 8MB) */
347 extern uint32_t	zfetch_max_distance;
348 SYSCTL_UINT(_vfs_zfs_zfetch, OID_AUTO, max_distance, CTLFLAG_RWTUN,
349 	&zfetch_max_distance, 0, "Max bytes to prefetch per stream (LEGACY)");
350 
351 /* max bytes to prefetch indirects for per stream (default 64MB) */
352 extern uint32_t	zfetch_max_idistance;
353 /* BEGIN CSTYLED */
354 SYSCTL_UINT(_vfs_zfs_zfetch, OID_AUTO, max_idistance, CTLFLAG_RWTUN,
355 	&zfetch_max_idistance, 0,
356 	"Max bytes to prefetch indirects for per stream (LEGACY)");
357 /* END CSTYLED */
358 
359 /* dsl_pool.c */
360 
361 /* dnode.c */
362 extern int zfs_default_bs;
363 SYSCTL_INT(_vfs_zfs, OID_AUTO, default_bs, CTLFLAG_RWTUN,
364 	&zfs_default_bs, 0, "Default dnode block shift");
365 
366 extern int zfs_default_ibs;
367 SYSCTL_INT(_vfs_zfs, OID_AUTO, default_ibs, CTLFLAG_RWTUN,
368 	&zfs_default_ibs, 0, "Default dnode indirect block shift");
369 
370 
371 /* dsl_scan.c */
372 
373 /* metaslab.c */
374 
375 /* BEGIN CSTYLED */
376 /*
377  * In pools where the log space map feature is not enabled we touch
378  * multiple metaslabs (and their respective space maps) with each
379  * transaction group. Thus, we benefit from having a small space map
380  * block size since it allows us to issue more I/O operations scattered
381  * around the disk. So a sane default for the space map block size
382  * is 8~16K.
383  */
384 extern int zfs_metaslab_sm_blksz_no_log;
385 SYSCTL_INT(_vfs_zfs_metaslab, OID_AUTO, sm_blksz_no_log, CTLFLAG_RDTUN,
386 	&zfs_metaslab_sm_blksz_no_log, 0,
387 	"Block size for space map in pools with log space map disabled.  "
388 	"Power of 2 greater than 4096.");
389 
390 /*
391  * When the log space map feature is enabled, we accumulate a lot of
392  * changes per metaslab that are flushed once in a while so we benefit
393  * from a bigger block size like 128K for the metaslab space maps.
394  */
395 extern int zfs_metaslab_sm_blksz_with_log;
396 SYSCTL_INT(_vfs_zfs_metaslab, OID_AUTO, sm_blksz_with_log, CTLFLAG_RDTUN,
397 	&zfs_metaslab_sm_blksz_with_log, 0,
398 	"Block size for space map in pools with log space map enabled.  "
399 	"Power of 2 greater than 4096.");
400 
401 /*
402  * The in-core space map representation is more compact than its on-disk form.
403  * The zfs_condense_pct determines how much more compact the in-core
404  * space map representation must be before we compact it on-disk.
405  * Values should be greater than or equal to 100.
406  */
407 extern int zfs_condense_pct;
408 SYSCTL_INT(_vfs_zfs, OID_AUTO, condense_pct, CTLFLAG_RWTUN,
409 	&zfs_condense_pct, 0,
410 	"Condense on-disk spacemap when it is more than this many percents"
411 	" of in-memory counterpart");
412 
413 extern int zfs_remove_max_segment;
414 SYSCTL_INT(_vfs_zfs, OID_AUTO, remove_max_segment, CTLFLAG_RWTUN,
415 	&zfs_remove_max_segment, 0, "Largest contiguous segment ZFS will"
416 	" attempt to allocate when removing a device");
417 
418 extern int zfs_removal_suspend_progress;
419 SYSCTL_INT(_vfs_zfs, OID_AUTO, removal_suspend_progress, CTLFLAG_RWTUN,
420 	&zfs_removal_suspend_progress, 0,
421 	"Ensures certain actions can happen while in the middle of a removal");
422 
423 
424 /*
425  * Minimum size which forces the dynamic allocator to change
426  * it's allocation strategy.  Once the space map cannot satisfy
427  * an allocation of this size then it switches to using more
428  * aggressive strategy (i.e search by size rather than offset).
429  */
430 extern uint64_t metaslab_df_alloc_threshold;
431 SYSCTL_QUAD(_vfs_zfs_metaslab, OID_AUTO, df_alloc_threshold, CTLFLAG_RWTUN,
432 	&metaslab_df_alloc_threshold, 0, "Minimum size which forces the dynamic"
433 	" allocator to change its allocation strategy");
434 
435 /*
436  * The minimum free space, in percent, which must be available
437  * in a space map to continue allocations in a first-fit fashion.
438  * Once the space map's free space drops below this level we dynamically
439  * switch to using best-fit allocations.
440  */
441 extern int metaslab_df_free_pct;
442 SYSCTL_INT(_vfs_zfs_metaslab, OID_AUTO, df_free_pct, CTLFLAG_RWTUN,
443 	&metaslab_df_free_pct, 0,
444 	"The minimum free space, in percent, which must be available in a"
445 	" space map to continue allocations in a first-fit fashion");
446 
447 /*
448  * Percentage of all cpus that can be used by the metaslab taskq.
449  */
450 extern int metaslab_load_pct;
451 SYSCTL_INT(_vfs_zfs_metaslab, OID_AUTO, load_pct, CTLFLAG_RWTUN,
452 	&metaslab_load_pct, 0,
453 	"Percentage of cpus that can be used by the metaslab taskq");
454 
455 /*
456  * Max number of metaslabs per group to preload.
457  */
458 extern int metaslab_preload_limit;
459 SYSCTL_INT(_vfs_zfs_metaslab, OID_AUTO, preload_limit, CTLFLAG_RWTUN,
460 	&metaslab_preload_limit, 0,
461 	"Max number of metaslabs per group to preload");
462 
463 /* spa.c */
464 extern int zfs_ccw_retry_interval;
465 SYSCTL_INT(_vfs_zfs, OID_AUTO, ccw_retry_interval, CTLFLAG_RWTUN,
466 	&zfs_ccw_retry_interval, 0, "Configuration cache file write,"
467 	" retry after failure, interval (seconds)");
468 
469 extern uint64_t zfs_max_missing_tvds_cachefile;
470 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, max_missing_tvds_cachefile, CTLFLAG_RWTUN,
471 	&zfs_max_missing_tvds_cachefile, 0,
472 	"allow importing pools with missing top-level vdevs in cache file");
473 
474 extern uint64_t zfs_max_missing_tvds_scan;
475 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, max_missing_tvds_scan, CTLFLAG_RWTUN,
476 	&zfs_max_missing_tvds_scan, 0,
477 	"allow importing pools with missing top-level vdevs during scan");
478 /* END CSTYLED */
479 
480 /* spa_misc.c */
481 extern int zfs_flags;
482 static int
483 sysctl_vfs_zfs_debug_flags(SYSCTL_HANDLER_ARGS)
484 {
485 	int err, val;
486 
487 	val = zfs_flags;
488 	err = sysctl_handle_int(oidp, &val, 0, req);
489 	if (err != 0 || req->newptr == NULL)
490 		return (err);
491 
492 	/*
493 	 * ZFS_DEBUG_MODIFY must be enabled prior to boot so all
494 	 * arc buffers in the system have the necessary additional
495 	 * checksum data.  However, it is safe to disable at any
496 	 * time.
497 	 */
498 	if (!(zfs_flags & ZFS_DEBUG_MODIFY))
499 		val &= ~ZFS_DEBUG_MODIFY;
500 	zfs_flags = val;
501 
502 	return (0);
503 }
504 
505 /* BEGIN CSTYLED */
506 SYSCTL_PROC(_vfs_zfs, OID_AUTO, debugflags,
507 	CTLTYPE_UINT | CTLFLAG_MPSAFE | CTLFLAG_RWTUN, NULL, 0,
508 	sysctl_vfs_zfs_debug_flags, "IU", "Debug flags for ZFS testing.");
509 /* END CSTYLED */
510 
511 int
512 param_set_deadman_synctime(SYSCTL_HANDLER_ARGS)
513 {
514 	unsigned long val;
515 	int err;
516 
517 	val = zfs_deadman_synctime_ms;
518 	err = sysctl_handle_long(oidp, &val, 0, req);
519 	if (err != 0 || req->newptr == NULL)
520 		return (err);
521 	zfs_deadman_synctime_ms = val;
522 
523 	spa_set_deadman_synctime(MSEC2NSEC(zfs_deadman_synctime_ms));
524 
525 	return (0);
526 }
527 
528 int
529 param_set_deadman_ziotime(SYSCTL_HANDLER_ARGS)
530 {
531 	unsigned long val;
532 	int err;
533 
534 	val = zfs_deadman_ziotime_ms;
535 	err = sysctl_handle_long(oidp, &val, 0, req);
536 	if (err != 0 || req->newptr == NULL)
537 		return (err);
538 	zfs_deadman_ziotime_ms = val;
539 
540 	spa_set_deadman_ziotime(MSEC2NSEC(zfs_deadman_synctime_ms));
541 
542 	return (0);
543 }
544 
545 int
546 param_set_deadman_failmode(SYSCTL_HANDLER_ARGS)
547 {
548 	char buf[16];
549 	int rc;
550 
551 	if (req->newptr == NULL)
552 		strlcpy(buf, zfs_deadman_failmode, sizeof (buf));
553 
554 	rc = sysctl_handle_string(oidp, buf, sizeof (buf), req);
555 	if (rc || req->newptr == NULL)
556 		return (rc);
557 	if (strcmp(buf, zfs_deadman_failmode) == 0)
558 		return (0);
559 	if (strcmp(buf, "wait") == 0)
560 		zfs_deadman_failmode = "wait";
561 	if (strcmp(buf, "continue") == 0)
562 		zfs_deadman_failmode = "continue";
563 	if (strcmp(buf, "panic") == 0)
564 		zfs_deadman_failmode = "panic";
565 
566 	return (-param_set_deadman_failmode_common(buf));
567 }
568 
569 
570 /* spacemap.c */
571 extern int space_map_ibs;
572 SYSCTL_INT(_vfs_zfs, OID_AUTO, space_map_ibs, CTLFLAG_RWTUN,
573 	&space_map_ibs, 0, "Space map indirect block shift");
574 
575 
576 /* vdev.c */
577 int
578 param_set_min_auto_ashift(SYSCTL_HANDLER_ARGS)
579 {
580 	uint64_t val;
581 	int err;
582 
583 	val = zfs_vdev_min_auto_ashift;
584 	err = sysctl_handle_64(oidp, &val, 0, req);
585 	if (err != 0 || req->newptr == NULL)
586 		return (SET_ERROR(err));
587 
588 	if (val < ASHIFT_MIN || val > zfs_vdev_max_auto_ashift)
589 		return (SET_ERROR(EINVAL));
590 
591 	zfs_vdev_min_auto_ashift = val;
592 
593 	return (0);
594 }
595 
596 int
597 param_set_max_auto_ashift(SYSCTL_HANDLER_ARGS)
598 {
599 	uint64_t val;
600 	int err;
601 
602 	val = zfs_vdev_max_auto_ashift;
603 	err = sysctl_handle_64(oidp, &val, 0, req);
604 	if (err != 0 || req->newptr == NULL)
605 		return (SET_ERROR(err));
606 
607 	if (val > ASHIFT_MAX || val < zfs_vdev_min_auto_ashift)
608 		return (SET_ERROR(EINVAL));
609 
610 	zfs_vdev_max_auto_ashift = val;
611 
612 	return (0);
613 }
614 
615 /* BEGIN CSTYLED */
616 SYSCTL_PROC(_vfs_zfs, OID_AUTO, min_auto_ashift,
617 	CTLTYPE_U64 | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
618 	&zfs_vdev_min_auto_ashift, sizeof (zfs_vdev_min_auto_ashift),
619 	param_set_min_auto_ashift, "QU",
620 	"Min ashift used when creating new top-level vdev. (LEGACY)");
621 SYSCTL_PROC(_vfs_zfs, OID_AUTO, max_auto_ashift,
622 	CTLTYPE_U64 | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
623 	&zfs_vdev_max_auto_ashift, sizeof (zfs_vdev_max_auto_ashift),
624 	param_set_max_auto_ashift, "QU",
625 	"Max ashift used when optimizing for logical -> physical sector size on"
626 	" new top-level vdevs. (LEGACY)");
627 
628 /*
629  * Since the DTL space map of a vdev is not expected to have a lot of
630  * entries, we default its block size to 4K.
631  */
632 extern int zfs_vdev_dtl_sm_blksz;
633 SYSCTL_INT(_vfs_zfs, OID_AUTO, dtl_sm_blksz, CTLFLAG_RDTUN,
634 	&zfs_vdev_dtl_sm_blksz, 0,
635 	"Block size for DTL space map.  Power of 2 greater than 4096.");
636 
637 /*
638  * vdev-wide space maps that have lots of entries written to them at
639  * the end of each transaction can benefit from a higher I/O bandwidth
640  * (e.g. vdev_obsolete_sm), thus we default their block size to 128K.
641  */
642 extern int zfs_vdev_standard_sm_blksz;
643 SYSCTL_INT(_vfs_zfs, OID_AUTO, standard_sm_blksz, CTLFLAG_RDTUN,
644 	&zfs_vdev_standard_sm_blksz, 0,
645 	"Block size for standard space map.  Power of 2 greater than 4096.");
646 /* END CSTYLED */
647 
648 extern int vdev_validate_skip;
649 SYSCTL_INT(_vfs_zfs, OID_AUTO, validate_skip, CTLFLAG_RDTUN,
650 	&vdev_validate_skip, 0, "Enable to bypass vdev_validate().");
651 
652 
653 /* vdev_cache.c */
654 
655 /* vdev_mirror.c */
656 /*
657  * The load configuration settings below are tuned by default for
658  * the case where all devices are of the same rotational type.
659  *
660  * If there is a mixture of rotating and non-rotating media, setting
661  * non_rotating_seek_inc to 0 may well provide better results as it
662  * will direct more reads to the non-rotating vdevs which are more
663  * likely to have a higher performance.
664  */
665 
666 
667 /* vdev_queue.c */
668 /* BEGIN CSTYLED */
669 extern uint32_t zfs_vdev_max_active;
670 SYSCTL_UINT(_vfs_zfs, OID_AUTO, top_maxinflight, CTLFLAG_RWTUN,
671 	&zfs_vdev_max_active, 0,
672 	"The maximum number of I/Os of all types active for each device."
673 	" (LEGACY)");
674 
675 extern int zfs_vdev_def_queue_depth;
676 SYSCTL_INT(_vfs_zfs_vdev, OID_AUTO, def_queue_depth, CTLFLAG_RWTUN,
677 	&zfs_vdev_def_queue_depth, 0,
678 	"Default queue depth for each allocator");
679 
680 
681 SYSCTL_INT(_vfs_zfs_zio, OID_AUTO, exclude_metadata, CTLFLAG_RDTUN,
682 	&zio_exclude_metadata, 0,
683 	"Exclude metadata buffers from dumps as well");
684 /* END CSTYLED */
685 
686 int
687 param_set_slop_shift(SYSCTL_HANDLER_ARGS)
688 {
689 	int val;
690 	int err;
691 
692 	val = *(int *)arg1;
693 
694 	err = sysctl_handle_int(oidp, &val, 0, req);
695 	if (err != 0 || req->newptr == NULL)
696 		return (err);
697 
698 	if (val < 1 || val > 31)
699 		return (EINVAL);
700 
701 	*(int *)arg1 = val;
702 
703 	return (0);
704 }
705 
706 int
707 param_set_multihost_interval(SYSCTL_HANDLER_ARGS)
708 {
709 	int err;
710 
711 	err = sysctl_handle_long(oidp, arg1, 0, req);
712 	if (err != 0 || req->newptr == NULL)
713 		return (err);
714 
715 	if (spa_mode_global != SPA_MODE_UNINIT)
716 		mmp_signal_all_threads();
717 
718 	return (0);
719 }
720