Annontate FreeBSD sysctls with CTLFLAG_MPSAFE

Without this, the sysctl system calls will acquire a global lock before
invoking the handler.  This is noticeable in some situations when
running top(1).  The global lock is mostly vestigal but continues to see
some use and so contention is still a problem; until the default sense
of the MPSAFE flag changes, we have to annotate each and every handler.

Reviewed-by: Allan Jude <allan@klarasystems.com>
Reviewed-by: Ryan Moeller <ryan@ixsystems.com>
Signed-off-by: Mark Johnston <markj@FreeBSD.org>
Closes #10836
This commit is contained in:
Mark Johnston 2020-09-18 08:45:54 -04:00 committed by Brian Behlendorf
parent c50f3c902f
commit 6bdb09510b
2 changed files with 31 additions and 26 deletions

View File

@ -349,50 +349,50 @@ kstat_install_named(kstat_t *ksp)
SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx, SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx,
SYSCTL_CHILDREN(ksp->ks_sysctl_root), SYSCTL_CHILDREN(ksp->ks_sysctl_root),
OID_AUTO, namelast, OID_AUTO, namelast,
CTLTYPE_S32 | CTLFLAG_RD, ksp, i, CTLTYPE_S32 | CTLFLAG_RD | CTLFLAG_MPSAFE,
kstat_sysctl, "I", namelast); ksp, i, kstat_sysctl, "I", namelast);
break; break;
case KSTAT_DATA_UINT32: case KSTAT_DATA_UINT32:
SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx, SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx,
SYSCTL_CHILDREN(ksp->ks_sysctl_root), SYSCTL_CHILDREN(ksp->ks_sysctl_root),
OID_AUTO, namelast, OID_AUTO, namelast,
CTLTYPE_U32 | CTLFLAG_RD, ksp, i, CTLTYPE_U32 | CTLFLAG_RD | CTLFLAG_MPSAFE,
kstat_sysctl, "IU", namelast); ksp, i, kstat_sysctl, "IU", namelast);
break; break;
case KSTAT_DATA_INT64: case KSTAT_DATA_INT64:
SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx, SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx,
SYSCTL_CHILDREN(ksp->ks_sysctl_root), SYSCTL_CHILDREN(ksp->ks_sysctl_root),
OID_AUTO, namelast, OID_AUTO, namelast,
CTLTYPE_S64 | CTLFLAG_RD, ksp, i, CTLTYPE_S64 | CTLFLAG_RD | CTLFLAG_MPSAFE,
kstat_sysctl, "Q", namelast); ksp, i, kstat_sysctl, "Q", namelast);
break; break;
case KSTAT_DATA_UINT64: case KSTAT_DATA_UINT64:
SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx, SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx,
SYSCTL_CHILDREN(ksp->ks_sysctl_root), SYSCTL_CHILDREN(ksp->ks_sysctl_root),
OID_AUTO, namelast, OID_AUTO, namelast,
CTLTYPE_U64 | CTLFLAG_RD, ksp, i, CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_MPSAFE,
kstat_sysctl, "QU", namelast); ksp, i, kstat_sysctl, "QU", namelast);
break; break;
case KSTAT_DATA_LONG: case KSTAT_DATA_LONG:
SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx, SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx,
SYSCTL_CHILDREN(ksp->ks_sysctl_root), SYSCTL_CHILDREN(ksp->ks_sysctl_root),
OID_AUTO, namelast, OID_AUTO, namelast,
CTLTYPE_LONG | CTLFLAG_RD, ksp, i, CTLTYPE_LONG | CTLFLAG_RD | CTLFLAG_MPSAFE,
kstat_sysctl, "L", namelast); ksp, i, kstat_sysctl, "L", namelast);
break; break;
case KSTAT_DATA_ULONG: case KSTAT_DATA_ULONG:
SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx, SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx,
SYSCTL_CHILDREN(ksp->ks_sysctl_root), SYSCTL_CHILDREN(ksp->ks_sysctl_root),
OID_AUTO, namelast, OID_AUTO, namelast,
CTLTYPE_ULONG | CTLFLAG_RD, ksp, i, CTLTYPE_ULONG | CTLFLAG_RD | CTLFLAG_MPSAFE,
kstat_sysctl, "LU", namelast); ksp, i, kstat_sysctl, "LU", namelast);
break; break;
case KSTAT_DATA_STRING: case KSTAT_DATA_STRING:
SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx, SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx,
SYSCTL_CHILDREN(ksp->ks_sysctl_root), SYSCTL_CHILDREN(ksp->ks_sysctl_root),
OID_AUTO, namelast, OID_AUTO, namelast,
CTLTYPE_STRING | CTLFLAG_RD, ksp, i, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
kstat_sysctl_string, "A", namelast); ksp, i, kstat_sysctl_string, "A", namelast);
break; break;
default: default:
panic("unsupported type: %d", typelast); panic("unsupported type: %d", typelast);
@ -417,14 +417,14 @@ kstat_install(kstat_t *ksp)
root = SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx, root = SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx,
SYSCTL_CHILDREN(ksp->ks_sysctl_root), SYSCTL_CHILDREN(ksp->ks_sysctl_root),
OID_AUTO, ksp->ks_name, OID_AUTO, ksp->ks_name,
CTLTYPE_STRING | CTLFLAG_RD, ksp, 0, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
kstat_sysctl_raw, "A", ksp->ks_name); ksp, 0, kstat_sysctl_raw, "A", ksp->ks_name);
} else { } else {
root = SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx, root = SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx,
SYSCTL_CHILDREN(ksp->ks_sysctl_root), SYSCTL_CHILDREN(ksp->ks_sysctl_root),
OID_AUTO, ksp->ks_name, OID_AUTO, ksp->ks_name,
CTLTYPE_OPAQUE | CTLFLAG_RD, ksp, 0, CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE,
kstat_sysctl_raw, "", ksp->ks_name); ksp, 0, kstat_sysctl_raw, "", ksp->ks_name);
} }
VERIFY(root != NULL); VERIFY(root != NULL);
break; break;
@ -432,8 +432,8 @@ kstat_install(kstat_t *ksp)
root = SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx, root = SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx,
SYSCTL_CHILDREN(ksp->ks_sysctl_root), SYSCTL_CHILDREN(ksp->ks_sysctl_root),
OID_AUTO, ksp->ks_name, OID_AUTO, ksp->ks_name,
CTLTYPE_STRING | CTLFLAG_RD, ksp, 0, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
kstat_sysctl_io, "A", ksp->ks_name); ksp, 0, kstat_sysctl_io, "A", ksp->ks_name);
break; break;
case KSTAT_TYPE_TIMER: case KSTAT_TYPE_TIMER:
case KSTAT_TYPE_INTR: case KSTAT_TYPE_INTR:

View File

@ -243,8 +243,9 @@ sysctl_vfs_zfs_arc_no_grow_shift(SYSCTL_HANDLER_ARGS)
return (0); return (0);
} }
SYSCTL_PROC(_vfs_zfs, OID_AUTO, arc_no_grow_shift, CTLTYPE_U32 | CTLFLAG_RWTUN, SYSCTL_PROC(_vfs_zfs, OID_AUTO, arc_no_grow_shift,
0, sizeof (uint32_t), sysctl_vfs_zfs_arc_no_grow_shift, "U", CTLTYPE_U32 | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, 0, sizeof (uint32_t),
sysctl_vfs_zfs_arc_no_grow_shift, "U",
"log2(fraction of ARC which must be free to allow growing)"); "log2(fraction of ARC which must be free to allow growing)");
int int
@ -275,10 +276,12 @@ param_set_arc_int(SYSCTL_HANDLER_ARGS)
return (0); return (0);
} }
SYSCTL_PROC(_vfs_zfs, OID_AUTO, arc_min, CTLTYPE_ULONG | CTLFLAG_RWTUN, SYSCTL_PROC(_vfs_zfs, OID_AUTO, arc_min,
CTLTYPE_ULONG | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
&zfs_arc_min, sizeof (zfs_arc_min), param_set_arc_long, "LU", &zfs_arc_min, sizeof (zfs_arc_min), param_set_arc_long, "LU",
"min arc size (LEGACY)"); "min arc size (LEGACY)");
SYSCTL_PROC(_vfs_zfs, OID_AUTO, arc_max, CTLTYPE_ULONG | CTLFLAG_RWTUN, SYSCTL_PROC(_vfs_zfs, OID_AUTO, arc_max,
CTLTYPE_ULONG | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
&zfs_arc_max, sizeof (zfs_arc_max), param_set_arc_long, "LU", &zfs_arc_max, sizeof (zfs_arc_max), param_set_arc_long, "LU",
"max arc size (LEGACY)"); "max arc size (LEGACY)");
@ -558,11 +561,13 @@ param_set_max_auto_ashift(SYSCTL_HANDLER_ARGS)
return (0); return (0);
} }
SYSCTL_PROC(_vfs_zfs, OID_AUTO, min_auto_ashift, CTLTYPE_U64 | CTLFLAG_RWTUN, SYSCTL_PROC(_vfs_zfs, OID_AUTO, min_auto_ashift,
CTLTYPE_U64 | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
&zfs_vdev_min_auto_ashift, sizeof (zfs_vdev_min_auto_ashift), &zfs_vdev_min_auto_ashift, sizeof (zfs_vdev_min_auto_ashift),
param_set_min_auto_ashift, "QU", param_set_min_auto_ashift, "QU",
"Min ashift used when creating new top-level vdev. (LEGACY)"); "Min ashift used when creating new top-level vdev. (LEGACY)");
SYSCTL_PROC(_vfs_zfs, OID_AUTO, max_auto_ashift, CTLTYPE_U64 | CTLFLAG_RWTUN, SYSCTL_PROC(_vfs_zfs, OID_AUTO, max_auto_ashift,
CTLTYPE_U64 | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
&zfs_vdev_max_auto_ashift, sizeof (zfs_vdev_max_auto_ashift), &zfs_vdev_max_auto_ashift, sizeof (zfs_vdev_max_auto_ashift),
param_set_max_auto_ashift, "QU", param_set_max_auto_ashift, "QU",
"Max ashift used when optimizing for logical -> physical sector size on " "Max ashift used when optimizing for logical -> physical sector size on "