From owner-svn-src-head@FreeBSD.ORG Fri Feb 7 14:29:04 2014 Return-Path: <owner-svn-src-head@FreeBSD.ORG> Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 99B82E32; Fri, 7 Feb 2014 14:29:04 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 76C1C129A; Fri, 7 Feb 2014 14:29:04 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s17ET4Ot053268; Fri, 7 Feb 2014 14:29:04 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s17ET3Rw053264; Fri, 7 Feb 2014 14:29:03 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201402071429.s17ET3Rw053264@svn.freebsd.org> From: Gleb Smirnoff <glebius@FreeBSD.org> Date: Fri, 7 Feb 2014 14:29:03 +0000 (UTC) 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 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: SVN commit messages for the src tree for head/-current <svn-src-head.freebsd.org> List-Unsubscribe: <http://lists.freebsd.org/mailman/options/svn-src-head>, <mailto:svn-src-head-request@freebsd.org?subject=unsubscribe> List-Archive: <http://lists.freebsd.org/pipermail/svn-src-head/> List-Post: <mailto:svn-src-head@freebsd.org> List-Help: <mailto:svn-src-head-request@freebsd.org?subject=help> List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-head>, <mailto:svn-src-head-request@freebsd.org?subject=subscribe> X-List-Received-Date: Fri, 07 Feb 2014 14:29:04 -0000 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) {