PERFORCE change 188347 for review
Edward Tomasz Napierala
trasz at FreeBSD.org
Sun Jan 30 17:50:33 UTC 2011
http://p4web.freebsd.org/@@188347?ac=10
Change 188347 by trasz at trasz_victim on 2011/01/30 17:49:27
Use flag array instead of switch statements.
Affected files ...
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#70 edit
.. //depot/projects/soc2009/trasz_limits/sys/sys/container.h#26 edit
Differences ...
==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#70 (text+ko) ====
@@ -88,129 +88,31 @@
SDT_PROBE_DEFINE2(container, kernel, container, join_failure, join-failure, "struct container *", "struct container *");
SDT_PROBE_DEFINE2(container, kernel, container, leave, leave, "struct container *", "struct container *");
-/*
- * Amount stored in c_resources[] is thousand times bigger than what's
- * visible to the userland. It gets fixed up when retrieving resource
- * usage or adding rules.
- */
-int
-rusage_is_in_thousands(int resource)
-{
- switch (resource) {
- case RUSAGE_CPU:
- case RUSAGE_WALLCLOCK:
- case RUSAGE_PCTCPU:
- return (1);
- default:
- return (0);
- }
-}
-
-/*
- * Resource usage can drop, as opposed to only grow.
- */
-static int
-rusage_is_reclaimable(int resource)
-{
-
- switch (resource) {
- case RUSAGE_CPU:
- case RUSAGE_CORE:
- case RUSAGE_WALLCLOCK:
- return (0);
- default:
- return (1);
- }
-}
-
-/*
- * Children inherit resource usage.
- */
-static int
-rusage_is_inheritable(int resource)
-{
-
- switch (resource) {
- case RUSAGE_CPU:
- case RUSAGE_CORE:
- case RUSAGE_MEMLOCK:
- case RUSAGE_NPROC:
- case RUSAGE_SBSIZE:
- case RUSAGE_NPTS:
- case RUSAGE_SWAP:
- case RUSAGE_NTHR:
- case RUSAGE_NMSGQ:
- case RUSAGE_MSGQQUEUED:
- case RUSAGE_MSGQSIZE:
- case RUSAGE_NSEM:
- case RUSAGE_NSHM:
- case RUSAGE_SHMSIZE:
- case RUSAGE_WALLCLOCK:
- case RUSAGE_PCTCPU:
- return (0);
- default:
- return (1);
- }
-}
-
-/*
- * rusage_{add,set}(9) can actually return an error and not update resource
- * usage counters. Note that even when resource is not deniable, allocating
- * resource might cause signals to be sent by RCTL code.
- */
-static int
-rusage_is_deniable(int resource)
-{
-
- switch (resource) {
- case RUSAGE_RSS:
- case RUSAGE_WALLCLOCK:
- case RUSAGE_PCTCPU:
- case RUSAGE_CPU:
- return (0);
- default:
- return (1);
- }
-}
-
-/*
- * Per-process resource usage information makes no sense, but per-credential
- * one does. This kind of resources are usually allocated for process, but
- * freed using credentials.
- */
-int
-rusage_is_sloppy(int resource)
-{
-
- switch (resource) {
- case RUSAGE_SBSIZE:
- case RUSAGE_NPTS:
- case RUSAGE_SWAP:
- case RUSAGE_NMSGQ:
- case RUSAGE_MSGQQUEUED:
- case RUSAGE_MSGQSIZE:
- case RUSAGE_NSEM:
- case RUSAGE_NSHM:
- case RUSAGE_SHMSIZE:
- return (1);
- default:
- return (0);
- }
-}
-
-/*
- * XXX: Explain somehow.
- */
-static int
-rusage_is_dampened(int resource)
-{
- switch (resource) {
- case RUSAGE_PCTCPU:
- return (1);
- default:
- return (0);
- }
-}
+int rusage_types[] = {
+ [RUSAGE_CPU] = RUSAGE_IN_THOUSANDS,
+ [RUSAGE_FSIZE] = RUSAGE_RECLAIMABLE | RUSAGE_INHERITABLE | RUSAGE_DENIABLE,
+ [RUSAGE_DATA] = RUSAGE_RECLAIMABLE | RUSAGE_INHERITABLE | RUSAGE_DENIABLE,
+ [RUSAGE_STACK] = RUSAGE_RECLAIMABLE | RUSAGE_INHERITABLE | RUSAGE_DENIABLE,
+ [RUSAGE_CORE] = RUSAGE_DENIABLE,
+ [RUSAGE_RSS] = RUSAGE_RECLAIMABLE | RUSAGE_INHERITABLE,
+ [RUSAGE_MEMLOCK] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE,
+ [RUSAGE_NPROC] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE,
+ [RUSAGE_NOFILE] = RUSAGE_RECLAIMABLE | RUSAGE_INHERITABLE | RUSAGE_DENIABLE,
+ [RUSAGE_SBSIZE] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE | RUSAGE_SLOPPY,
+ [RUSAGE_VMEM] = RUSAGE_RECLAIMABLE | RUSAGE_INHERITABLE | RUSAGE_DENIABLE,
+ [RUSAGE_NPTS] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE | RUSAGE_SLOPPY,
+ [RUSAGE_SWAP] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE | RUSAGE_SLOPPY,
+ [RUSAGE_NTHR] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE,
+ [RUSAGE_MSGQQUEUED] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE | RUSAGE_SLOPPY,
+ [RUSAGE_MSGQSIZE] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE | RUSAGE_SLOPPY,
+ [RUSAGE_NMSGQ] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE | RUSAGE_SLOPPY,
+ [RUSAGE_NSEM] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE | RUSAGE_SLOPPY,
+ [RUSAGE_NSEMOP] = RUSAGE_RECLAIMABLE | RUSAGE_INHERITABLE | RUSAGE_DENIABLE,
+ [RUSAGE_NSHM] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE | RUSAGE_SLOPPY,
+ [RUSAGE_SHMSIZE] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE | RUSAGE_SLOPPY,
+ [RUSAGE_WALLCLOCK] = RUSAGE_IN_THOUSANDS,
+ [RUSAGE_PCTCPU] = RUSAGE_IN_THOUSANDS | RUSAGE_RECLAIMABLE | RUSAGE_DAMPENED,
+ [RUSAGE_SHMSIZE] = RUSAGE_RECLAIMABLE | RUSAGE_INHERITABLE | RUSAGE_DENIABLE };
static void
container_add(struct container *dest, const struct container *src)
==== //depot/projects/soc2009/trasz_limits/sys/sys/container.h#26 (text+ko) ====
@@ -71,6 +71,54 @@
#define RUSAGE_MAX RUSAGE_PCTCPU
/*
+ * Resource types.
+ */
+#define RUSAGE_IN_THOUSANDS 0x01
+#define RUSAGE_RECLAIMABLE 0x02
+#define RUSAGE_INHERITABLE 0x04
+#define RUSAGE_DENIABLE 0x08
+#define RUSAGE_SLOPPY 0x10
+#define RUSAGE_DAMPENED 0x20
+
+extern int rusage_types[];
+
+/*
+ * Amount stored in c_resources[] is thousand times bigger than what's
+ * visible to the userland. It gets fixed up when retrieving resource
+ * usage or adding rules.
+ */
+#define rusage_is_in_thousands(X) (rusage_types[X] & RUSAGE_IN_THOUSANDS)
+
+/*
+ * Resource usage can drop, as opposed to only grow.
+ */
+#define rusage_is_reclaimable(X) (rusage_types[X] & RUSAGE_RECLAIMABLE)
+
+/*
+ * Children inherit resource usage.
+ */
+#define rusage_is_inheritable(X) (rusage_types[X] & RUSAGE_INHERITABLE)
+
+/*
+ * rusage_{add,set}(9) can actually return an error and not update resource
+ * usage counters. Note that even when resource is not deniable, allocating
+ * resource might cause signals to be sent by RCTL code.
+ */
+#define rusage_is_deniable(X) (rusage_types[X] & RUSAGE_DENIABLE)
+
+/*
+ * Per-process resource usage information makes no sense, but per-credential
+ * one does. This kind of resources are usually allocated for process, but
+ * freed using credentials.
+ */
+#define rusage_is_sloppy(X) (rusage_types[X] & RUSAGE_SLOPPY)
+
+/*
+ * XXX: Explain somehow.
+ */
+#define rusage_is_dampened(X) (rusage_types[X] & RUSAGE_DAMPENED)
+
+/*
* 'container' defines resource consumption for a particular
* subject, such as process or jail. Containers form a graph - each
* container has zero or more subcontainers and zero or more
@@ -113,7 +161,4 @@
void container_proc_ucred_changed(struct proc *p, struct ucred *oldcred,
struct ucred *newcred);
-int rusage_is_in_thousands(int resource);
-int rusage_is_sloppy(int resource);
-
#endif /* !_CONTAINER_H_ */
More information about the p4-projects
mailing list