Date: Fri, 7 Feb 2014 14:29:03 +0000 (UTC) From: Gleb Smirnoff <glebius@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r261593 - in head: share/man/man9 sys/sys sys/vm Message-ID: <201402071429.s17ET3Rw053264@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: glebius Date: Fri Feb 7 14:29:03 2014 New Revision: 261593 URL: http://svnweb.freebsd.org/changeset/base/261593 Log: Provide macros that allow easily export uma(9) zone limits and current usage via sysctl(9): SYSCTL_UMA_MAX() SYSCTL_ADD_UMA_MAX() SYSCTL_UMA_CUR() SYSCTL_ADD_UMA_CUR() Sponsored by: Nginx, Inc. Modified: head/share/man/man9/zone.9 head/sys/sys/sysctl.h head/sys/vm/uma_core.c Modified: head/share/man/man9/zone.9 ============================================================================== --- head/share/man/man9/zone.9 Fri Feb 7 14:26:33 2014 (r261592) +++ head/share/man/man9/zone.9 Fri Feb 7 14:29:03 2014 (r261593) @@ -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 s .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 Modified: head/sys/sys/sysctl.h ============================================================================== --- head/sys/sys/sysctl.h Fri Feb 7 14:26:33 2014 (r261592) +++ head/sys/sys/sysctl.h Fri Feb 7 14:29:03 2014 (r261593) @@ -186,6 +186,9 @@ int sysctl_handle_string(SYSCTL_HANDLER_ 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 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. Modified: head/sys/vm/uma_core.c ============================================================================== --- head/sys/vm/uma_core.c Fri Feb 7 14:26:33 2014 (r261592) +++ head/sys/vm/uma_core.c Fri Feb 7 14:29:03 2014 (r261593) @@ -3465,6 +3465,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) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201402071429.s17ET3Rw053264>