Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 24 Feb 2011 21:17:53 GMT
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 189096 for review
Message-ID:  <201102242117.p1OLHrAf006650@skunkworks.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include <sys/param.h>
+#include <sys/bus.h>
 #include <sys/container.h>
 #include <sys/rctl.h>
-#include <sys/param.h>
 #include <sys/malloc.h>
 #include <sys/queue.h>
 #include <sys/refcount.h>
@@ -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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201102242117.p1OLHrAf006650>