summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2014-03-04 14:21:07 +0000
committerglebius <glebius@FreeBSD.org>2014-03-04 14:21:07 +0000
commit322a3c94d3d120bb067e52cd49285f1c90c17e55 (patch)
tree6cb50c0b6df9e62fa570c2e5f9f776bb8e61b850
parent352d508b164f60d6e5de69dba908cd0b34e56a26 (diff)
downloadFreeBSD-src-322a3c94d3d120bb067e52cd49285f1c90c17e55.zip
FreeBSD-src-322a3c94d3d120bb067e52cd49285f1c90c17e55.tar.gz
Merge 261593 from head:
Provide macros that allow easily export uma(9) zone limits and current usage via sysctl(9).
-rw-r--r--share/man/man9/zone.939
-rw-r--r--sys/sys/sysctl.h27
-rw-r--r--sys/vm/uma_core.c29
3 files changed, 94 insertions, 1 deletions
diff --git a/share/man/man9/zone.9 b/share/man/man9/zone.9
index 4199268..d0af88e 100644
--- a/share/man/man9/zone.9
+++ b/share/man/man9/zone.9
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd March 21, 2013
+.Dd February 7, 2014
.Dt ZONE 9
.Os
.Sh NAME
@@ -71,6 +71,11 @@
.Fn uma_zone_get_cur "uma_zone_t zone"
.Ft void
.Fn uma_zone_set_warning "uma_zone_t zone" "const char *warning"
+.In sys/sysctl.h
+.Fn SYSCTL_UMA_MAX parent nbr name access zone descr
+.Fn SYSCTL_ADD_UMA_MAX ctx parent nbr name access zone descr
+.Fn SYSCTL_UMA_CUR parent nbr name access zone descr
+.Fn SYSCTL_ADD_UMA_CUR ctx parent nbr name access zone descr
.Sh DESCRIPTION
The zone allocator provides an efficient interface for managing
dynamically-sized collections of items of similar size.
@@ -307,6 +312,38 @@ Warnings can be turned off globally by setting the
.Va vm.zone_warnings
sysctl tunable to
.Va 0 .
+.Pp
+The
+.Fn SYSCTL_UMA_MAX parent nbr name access zone descr
+macro declares a static
+.Xr sysctl
+oid that exports the effective upper limit number of items for a zone.
+The
+.Fa zone
+argument should be a pointer to
+.Vt uma_zone_t .
+A read of the oid returns value obtained through
+.Fn uma_zone_get_max .
+A write to the oid sets new value via
+.Fn uma_zone_set_max .
+The
+.Fn SYSCTL_ADD_UMA_MAX ctx parent nbr name access zone descr
+macro is provided to create this type of oid dynamically.
+.Pp
+The
+.Fn SYSCTL_UMA_CUR parent nbr name access zone descr
+macro declares a static read only
+.Xr sysctl
+oid that exports the approximate current occupancy of the zone.
+The
+.Fa zone
+argument should be a pointer to
+.Vt uma_zone_t .
+A read of the oid returns value obtained through
+.Fn uma_zone_get_cur .
+The
+.Fn SYSCTL_ADD_UMA_CUR ctx parent nbr name zone descr
+macro is provided to create this type of oid dynamically.
.Sh RETURN VALUES
The
.Fn uma_zalloc
diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h
index 8e70a12..2a8a24a 100644
--- a/sys/sys/sysctl.h
+++ b/sys/sys/sysctl.h
@@ -186,6 +186,9 @@ int sysctl_handle_string(SYSCTL_HANDLER_ARGS);
int sysctl_handle_opaque(SYSCTL_HANDLER_ARGS);
int sysctl_handle_counter_u64(SYSCTL_HANDLER_ARGS);
+int sysctl_handle_uma_zone_max(SYSCTL_HANDLER_ARGS);
+int sysctl_handle_uma_zone_cur(SYSCTL_HANDLER_ARGS);
+
int sysctl_dpcpu_int(SYSCTL_HANDLER_ARGS);
int sysctl_dpcpu_long(SYSCTL_HANDLER_ARGS);
int sysctl_dpcpu_quad(SYSCTL_HANDLER_ARGS);
@@ -431,6 +434,30 @@ SYSCTL_ALLOWED_TYPES(UINT64, uint64_t *a; unsigned long long *b; );
sysctl_add_oid(ctx, parent, nbr, name, (access), \
ptr, arg, handler, fmt, __DESCR(descr))
+/* Oid to handle limits on uma(9) zone specified by pointer. */
+#define SYSCTL_UMA_MAX(parent, nbr, name, access, ptr, descr) \
+ SYSCTL_ASSERT_TYPE(INT, ptr, parent, name); \
+ SYSCTL_OID(parent, nbr, name, \
+ CTLTYPE_INT | CTLFLAG_MPSAFE | (access), \
+ ptr, 0, sysctl_handle_uma_zone_max, "I", descr)
+#define SYSCTL_ADD_UMA_MAX(ctx, parent, nbr, name, access, ptr, descr)\
+ sysctl_add_oid(ctx, parent, nbr, name, \
+ CTLTYPE_INT | CTLFLAG_MPSAFE | (access), \
+ SYSCTL_ADD_ASSERT_TYPE(INT, ptr), 0, \
+ sysctl_handle_uma_zone_max, "I", __DESCR(descr))
+
+/* Oid to obtain current use of uma(9) zone specified by pointer. */
+#define SYSCTL_UMA_CUR(parent, nbr, name, access, ptr, descr) \
+ SYSCTL_ASSERT_TYPE(INT, ptr, parent, name); \
+ SYSCTL_OID(parent, nbr, name, \
+ CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \
+ ptr, 0, sysctl_handle_uma_zone_cur, "I", descr)
+#define SYSCTL_ADD_UMA_CUR(ctx, parent, nbr, name, access, ptr, descr) \
+ sysctl_add_oid(ctx, parent, nbr, name, \
+ CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \
+ SYSCTL_ADD_ASSERT_TYPE(INT, ptr), 0, \
+ sysctl_handle_uma_zone_cur, "I", __DESCR(descr))
+
/*
* A macro to generate a read-only sysctl to indicate the presense of optional
* kernel features.
diff --git a/sys/vm/uma_core.c b/sys/vm/uma_core.c
index 5b1cbb5..5bfbb72 100644
--- a/sys/vm/uma_core.c
+++ b/sys/vm/uma_core.c
@@ -3462,6 +3462,35 @@ skip:
return (error);
}
+int
+sysctl_handle_uma_zone_max(SYSCTL_HANDLER_ARGS)
+{
+ uma_zone_t zone = *(uma_zone_t *)arg1;
+ int error, max, old;
+
+ old = max = uma_zone_get_max(zone);
+ error = sysctl_handle_int(oidp, &max, 0, req);
+ if (error || !req->newptr)
+ return (error);
+
+ if (max < old)
+ return (EINVAL);
+
+ uma_zone_set_max(zone, max);
+
+ return (0);
+}
+
+int
+sysctl_handle_uma_zone_cur(SYSCTL_HANDLER_ARGS)
+{
+ uma_zone_t zone = *(uma_zone_t *)arg1;
+ int cur;
+
+ cur = uma_zone_get_cur(zone);
+ return (sysctl_handle_int(oidp, &cur, 0, req));
+}
+
#ifdef DDB
DB_SHOW_COMMAND(uma, db_show_uma)
{
OpenPOWER on IntegriCloud