aboutsummaryrefslogtreecommitdiff
path: root/sys/sys/racct.h
diff options
context:
space:
mode:
authorEdward Tomasz Napierala <trasz@FreeBSD.org>2011-03-29 17:47:25 +0000
committerEdward Tomasz Napierala <trasz@FreeBSD.org>2011-03-29 17:47:25 +0000
commit097055e26d9459c7def70856aab62b77d627511d (patch)
tree304753d7f5287660a242996801bd5664ee945d3a /sys/sys/racct.h
parentf77057db0888d2ca3b038c9775188bc83ebcc297 (diff)
downloadsrc-097055e26d9459c7def70856aab62b77d627511d.tar.gz
src-097055e26d9459c7def70856aab62b77d627511d.zip
Add racct. It's an API to keep per-process, per-jail, per-loginclass
and per-loginclass resource accounting information, to be used by the new resource limits code. It's connected to the build, but the code that actually calls the new functions will come later. Sponsored by: The FreeBSD Foundation Reviewed by: kib (earlier version)
Notes
Notes: svn path=/head/; revision=220137
Diffstat (limited to 'sys/sys/racct.h')
-rw-r--r--sys/sys/racct.h147
1 files changed, 147 insertions, 0 deletions
diff --git a/sys/sys/racct.h b/sys/sys/racct.h
new file mode 100644
index 000000000000..cbd96a976615
--- /dev/null
+++ b/sys/sys/racct.h
@@ -0,0 +1,147 @@
+/*-
+ * Copyright (c) 2010 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Edward Tomasz Napierala under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * Resource accounting.
+ */
+
+#ifndef _RACCT_H_
+#define _RACCT_H_
+
+#include <sys/cdefs.h>
+#include <sys/queue.h>
+#include <sys/types.h>
+
+struct proc;
+struct rctl_rule_link;
+struct ucred;
+
+/*
+ * Resources.
+ */
+#define RACCT_UNDEFINED -1
+#define RACCT_CPU 0
+#define RACCT_FSIZE 1
+#define RACCT_DATA 2
+#define RACCT_STACK 3
+#define RACCT_CORE 4
+#define RACCT_RSS 5
+#define RACCT_MEMLOCK 6
+#define RACCT_NPROC 7
+#define RACCT_NOFILE 8
+#define RACCT_SBSIZE 9
+#define RACCT_VMEM 10
+#define RACCT_NPTS 11
+#define RACCT_SWAP 12
+#define RACCT_NTHR 13
+#define RACCT_MSGQQUEUED 14
+#define RACCT_MSGQSIZE 15
+#define RACCT_NMSGQ 16
+#define RACCT_NSEM 17
+#define RACCT_NSEMOP 18
+#define RACCT_NSHM 19
+#define RACCT_SHMSIZE 20
+#define RACCT_WALLCLOCK 21
+#define RACCT_MAX RACCT_WALLCLOCK
+
+/*
+ * Resource properties.
+ */
+#define RACCT_IN_THOUSANDS 0x01
+#define RACCT_RECLAIMABLE 0x02
+#define RACCT_INHERITABLE 0x04
+#define RACCT_DENIABLE 0x08
+#define RACCT_SLOPPY 0x10
+
+extern int racct_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 racct_is_in_thousands(X) (racct_types[X] & RACCT_IN_THOUSANDS)
+
+/*
+ * Resource usage can drop, as opposed to only grow.
+ */
+#define racct_is_reclaimable(X) (racct_types[X] & RACCT_RECLAIMABLE)
+
+/*
+ * Children inherit resource usage.
+ */
+#define racct_is_inheritable(X) (racct_types[X] & RACCT_INHERITABLE)
+
+/*
+ * racct_{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 racct_is_deniable(X) (racct_types[X] & RACCT_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 racct_is_sloppy(X) (racct_types[X] & RACCT_SLOPPY)
+
+/*
+ * The 'racct' structure defines resource consumption for a particular
+ * subject, such as process or jail.
+ *
+ * This structure must be filled with zeroes initially.
+ */
+struct racct {
+ int64_t r_resources[RACCT_MAX + 1];
+ LIST_HEAD(, rctl_rule_link) r_rule_links;
+};
+
+int racct_add(struct proc *p, int resource, uint64_t amount);
+void racct_add_cred(struct ucred *cred, int resource, uint64_t amount);
+void racct_add_force(struct proc *p, int resource, uint64_t amount);
+int racct_set(struct proc *p, int resource, uint64_t amount);
+void racct_set_force(struct proc *p, int resource, uint64_t amount);
+void racct_sub(struct proc *p, int resource, uint64_t amount);
+void racct_sub_cred(struct ucred *cred, int resource, uint64_t amount);
+uint64_t racct_get_limit(struct proc *p, int resource);
+uint64_t racct_get_available(struct proc *p, int resource);
+
+void racct_create(struct racct **racctp);
+void racct_destroy(struct racct **racctp);
+
+int racct_proc_fork(struct proc *parent, struct proc *child);
+void racct_proc_exit(struct proc *p);
+
+void racct_proc_ucred_changed(struct proc *p, struct ucred *oldcred,
+ struct ucred *newcred);
+
+#endif /* !_RACCT_H_ */