From owner-svn-src-all@freebsd.org Fri Apr 8 18:15:32 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7E90DB080CD; Fri, 8 Apr 2016 18:15:32 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3DC4B164F; Fri, 8 Apr 2016 18:15:32 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u38IFVle017468; Fri, 8 Apr 2016 18:15:31 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u38IFVqL017467; Fri, 8 Apr 2016 18:15:31 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <201604081815.u38IFVqL017467@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Fri, 8 Apr 2016 18:15:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r297722 - head/sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Apr 2016 18:15:32 -0000 Author: trasz Date: Fri Apr 8 18:15:31 2016 New Revision: 297722 URL: https://svnweb.freebsd.org/changeset/base/297722 Log: Make it possible to tweak RCTL throttling sysctls at runtime. MFC after: 1 month Sponsored by: The FreeBSD Foundation Modified: head/sys/kern/kern_rctl.c Modified: head/sys/kern/kern_rctl.c ============================================================================== --- head/sys/kern/kern_rctl.c Fri Apr 8 16:14:18 2016 (r297721) +++ head/sys/kern/kern_rctl.c Fri Apr 8 18:15:31 2016 (r297722) @@ -80,28 +80,43 @@ FEATURE(rctl, "Resource Limits"); static unsigned int rctl_maxbufsize = RCTL_MAX_OUTBUFSIZE; static int rctl_log_rate_limit = 10; static int rctl_devctl_rate_limit = 10; -static unsigned int rctl_throttle_min = 0; -static unsigned int rctl_throttle_max = 0; -static unsigned int rctl_throttle_pct = 0; -static unsigned int rctl_throttle_pct2 = 0; + +/* + * Values below are initialized in rctl_init(). + */ +static int rctl_throttle_min = -1; +static int rctl_throttle_max = -1; +static int rctl_throttle_pct = -1; +static int rctl_throttle_pct2 = -1; + +static int rctl_throttle_min_sysctl(SYSCTL_HANDLER_ARGS); +static int rctl_throttle_max_sysctl(SYSCTL_HANDLER_ARGS); +static int rctl_throttle_pct_sysctl(SYSCTL_HANDLER_ARGS); +static int rctl_throttle_pct2_sysctl(SYSCTL_HANDLER_ARGS); SYSCTL_NODE(_kern_racct, OID_AUTO, rctl, CTLFLAG_RW, 0, "Resource Limits"); SYSCTL_UINT(_kern_racct_rctl, OID_AUTO, maxbufsize, CTLFLAG_RWTUN, &rctl_maxbufsize, 0, "Maximum output buffer size"); SYSCTL_UINT(_kern_racct_rctl, OID_AUTO, log_rate_limit, CTLFLAG_RW, &rctl_log_rate_limit, 0, "Maximum number of log messages per second"); -SYSCTL_UINT(_kern_racct_rctl, OID_AUTO, devctl_rate_limit, CTLFLAG_RW, +SYSCTL_UINT(_kern_racct_rctl, OID_AUTO, devctl_rate_limit, CTLFLAG_RWTUN, &rctl_devctl_rate_limit, 0, "Maximum number of devctl messages per second"); -SYSCTL_UINT(_kern_racct_rctl, OID_AUTO, throttle_min, CTLFLAG_RDTUN, - &rctl_throttle_min, 0, "Shortest throttling duration, in hz"); -SYSCTL_UINT(_kern_racct_rctl, OID_AUTO, throttle_max, CTLFLAG_RDTUN, - &rctl_throttle_max, 0, "Longest throttling duration, in hz"); -SYSCTL_UINT(_kern_racct_rctl, OID_AUTO, throttle_pct, CTLFLAG_RDTUN, - &rctl_throttle_pct, 0, +SYSCTL_PROC(_kern_racct_rctl, OID_AUTO, throttle_min, + CTLTYPE_UINT | CTLFLAG_RWTUN, 0, 0, &rctl_throttle_min_sysctl, "IU", + "Shortest throttling duration, in hz"); +TUNABLE_INT("kern.racct.rctl.throttle_min", &rctl_throttle_min); +SYSCTL_PROC(_kern_racct_rctl, OID_AUTO, throttle_max, + CTLTYPE_UINT | CTLFLAG_RWTUN, 0, 0, &rctl_throttle_max_sysctl, "IU", + "Longest throttling duration, in hz"); +TUNABLE_INT("kern.racct.rctl.throttle_max", &rctl_throttle_max); +SYSCTL_PROC(_kern_racct_rctl, OID_AUTO, throttle_pct, + CTLTYPE_UINT | CTLFLAG_RWTUN, 0, 0, &rctl_throttle_pct_sysctl, "IU", "Throttling penalty for process consumption, in percent"); -SYSCTL_UINT(_kern_racct_rctl, OID_AUTO, throttle_pct2, CTLFLAG_RDTUN, - &rctl_throttle_pct2, 0, +TUNABLE_INT("kern.racct.rctl.throttle_pct", &rctl_throttle_pct); +SYSCTL_PROC(_kern_racct_rctl, OID_AUTO, throttle_pct2, + CTLTYPE_UINT | CTLFLAG_RWTUN, 0, 0, &rctl_throttle_pct2_sysctl, "IU", "Throttling penalty for container consumption, in percent"); +TUNABLE_INT("kern.racct.rctl.throttle_pct2", &rctl_throttle_pct2); /* * 'rctl_rule_link' connects a rule with every racct it's related to. @@ -212,6 +227,78 @@ static void rctl_rule_to_sbuf(struct sbu static MALLOC_DEFINE(M_RCTL, "rctl", "Resource Limits"); +static int rctl_throttle_min_sysctl(SYSCTL_HANDLER_ARGS) +{ + int val = rctl_throttle_min; + int error; + + error = sysctl_handle_int(oidp, &val, 0, req); + if (error || !req->newptr) + return (error); + if (val < 1 || val > rctl_throttle_max) + return (EINVAL); + + RCTL_WLOCK(); + rctl_throttle_min = val; + RCTL_WUNLOCK(); + + return (0); +} + +static int rctl_throttle_max_sysctl(SYSCTL_HANDLER_ARGS) +{ + int val = rctl_throttle_max; + int error; + + error = sysctl_handle_int(oidp, &val, 0, req); + if (error || !req->newptr) + return (error); + if (val < rctl_throttle_min) + return (EINVAL); + + RCTL_WLOCK(); + rctl_throttle_max = val; + RCTL_WUNLOCK(); + + return (0); +} + +static int rctl_throttle_pct_sysctl(SYSCTL_HANDLER_ARGS) +{ + int val = rctl_throttle_pct; + int error; + + error = sysctl_handle_int(oidp, &val, 0, req); + if (error || !req->newptr) + return (error); + if (val < 0) + return (EINVAL); + + RCTL_WLOCK(); + rctl_throttle_pct = val; + RCTL_WUNLOCK(); + + return (0); +} + +static int rctl_throttle_pct2_sysctl(SYSCTL_HANDLER_ARGS) +{ + int val = rctl_throttle_pct2; + int error; + + error = sysctl_handle_int(oidp, &val, 0, req); + if (error || !req->newptr) + return (error); + if (val < 0) + return (EINVAL); + + RCTL_WLOCK(); + rctl_throttle_pct2 = val; + RCTL_WUNLOCK(); + + return (0); +} + static const char * rctl_subject_type_name(int subject) { @@ -2122,13 +2209,19 @@ rctl_init(void) rctl_rule_zone = uma_zcreate("rctl_rule", sizeof(struct rctl_rule), NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE); - if (rctl_throttle_min <= 0) + /* + * Set default values, making sure not to overwrite the ones + * fetched from tunables. Most of those could be set at the + * declaration, except for the rctl_throttle_max - we cannot + * set it there due to hz not being compile time constant. + */ + if (rctl_throttle_min < 1) rctl_throttle_min = 1; - if (rctl_throttle_max <= 0) + if (rctl_throttle_max < rctl_throttle_min) rctl_throttle_max = 2 * hz; - if (rctl_throttle_pct <= 0) + if (rctl_throttle_pct < 0) rctl_throttle_pct = 100; - if (rctl_throttle_pct2 <= 0) + if (rctl_throttle_pct2 < 0) rctl_throttle_pct2 = 100; }