From owner-p4-projects@FreeBSD.ORG Thu Feb 24 21:17:54 2011 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id C68BF106567A; Thu, 24 Feb 2011 21:17:54 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 711E21065670 for ; Thu, 24 Feb 2011 21:17:54 +0000 (UTC) (envelope-from trasz@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 5DC6E8FC17 for ; Thu, 24 Feb 2011 21:17:54 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id p1OLHs4V006653 for ; Thu, 24 Feb 2011 21:17:54 GMT (envelope-from trasz@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id p1OLHrAf006650 for perforce@freebsd.org; Thu, 24 Feb 2011 21:17:53 GMT (envelope-from trasz@freebsd.org) Date: Thu, 24 Feb 2011 21:17:53 GMT Message-Id: <201102242117.p1OLHrAf006650@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to trasz@freebsd.org using -f From: Edward Tomasz Napierala To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 189096 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Feb 2011 21:17:55 -0000 http://p4web.freebsd.org/@@189096?ac=10 Change 189096 by trasz@trasz_victim on 2011/02/24 21:17:41 Implement "devctl" action. Affected files ... .. //depot/projects/soc2009/trasz_limits/etc/devd.conf#7 edit .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_rctl.c#36 edit .. //depot/projects/soc2009/trasz_limits/sys/sys/rctl.h#13 edit .. //depot/projects/soc2009/trasz_limits/usr.bin/rctl/rctl.8#9 edit Differences ... ==== //depot/projects/soc2009/trasz_limits/etc/devd.conf#7 (text+ko) ==== @@ -301,6 +301,7 @@ # Button: Button pressed (0 for power, 1 for sleep) # CMBAT: ACPI battery events # Lid: Lid state (0 is closed, 1 is open) +# RCTL: Resource limits # Suspend, Resume: Suspend and resume notification # Thermal: ACPI thermal zone events # @@ -313,4 +314,13 @@ match "subsystem" "ACAD"; action "/etc/acpi_ac $notify"; }; + +# This example works around a memory leak in PostgreSQL, restarting +# it when "user:pgsql:swap:devctl=1G" rctl(8) rule gets triggered. +notify 0 { + match "system" "RCTL"; + match "rule" "user:70:swap:.*"; + action "/usr/local/etc/rc.d/postgresql restart" +}; + */ ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_rctl.c#36 (text+ko) ==== @@ -32,9 +32,10 @@ #include __FBSDID("$FreeBSD$"); +#include +#include #include #include -#include #include #include #include @@ -157,6 +158,7 @@ { "sigthr", RCTL_ACTION_SIGTHR }, { "deny", RCTL_ACTION_DENY }, { "log", RCTL_ACTION_LOG }, + { "devctl", RCTL_ACTION_DEVCTL }, { NULL, -1 }}; static void rctl_init(void); @@ -331,6 +333,27 @@ free(buf, M_RCTL); link->rrl_exceeded = 1; continue; + case RCTL_ACTION_DEVCTL: + if (link->rrl_exceeded != 0) + continue; + + buf = malloc(RCTL_LOG_BUFSIZE, M_RCTL, M_NOWAIT); + if (buf == NULL) { + printf("rctl_enforce: out of memory\n"); + continue; + } + sbuf_new(&sb, buf, RCTL_LOG_BUFSIZE, SBUF_FIXEDLEN); + sbuf_printf(&sb, "rule="); + rctl_rule_to_sbuf(&sb, rule); + sbuf_printf(&sb, " pid=%d ruid=%d jid=%d", p->p_pid, + p->p_ucred->cr_ruid, p->p_ucred->cr_prison->pr_id); + sbuf_finish(&sb); + devctl_notify_f("RCTL", "rule", "matched", + sbuf_data(&sb), M_NOWAIT); + sbuf_delete(&sb); + free(buf, M_RCTL); + link->rrl_exceeded = 1; + continue; default: if (link->rrl_exceeded != 0) continue; ==== //depot/projects/soc2009/trasz_limits/sys/sys/rctl.h#13 (text+ko) ==== @@ -128,7 +128,8 @@ #define RCTL_ACTION_SIGNAL_MAX RCTL_ACTION_SIGTHR #define RCTL_ACTION_DENY (RCTL_ACTION_SIGNAL_MAX + 1) #define RCTL_ACTION_LOG (RCTL_ACTION_SIGNAL_MAX + 2) -#define RCTL_ACTION_MAX RCTL_ACTION_LOG +#define RCTL_ACTION_DEVCTL (RCTL_ACTION_SIGNAL_MAX + 3) +#define RCTL_ACTION_MAX RCTL_ACTION_DEVCTL #define RCTL_AMOUNT_UNDEFINED -1 ==== //depot/projects/soc2009/trasz_limits/usr.bin/rctl/rctl.8#9 (text+ko) ==== @@ -151,6 +151,8 @@ .Bl -column -offset 3n "msgqqueued" .It deny deny the allocation; not supported for cpu and wallclock .It log log a warning to the console +.It devctl send notification to +.Xr devd 8 .It sig* e.g. sigterm; send a signal to the offending process .El .Pp