aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/res_counter.h
diff options
context:
space:
mode:
authorPavel Emelianov <xemul@openvz.org>2008-02-07 03:13:49 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-07 11:42:18 -0500
commite552b6617067ab785256dcec5ca29eeea981aacb (patch)
tree672cccc2e21abfa4dcdc1bdb198e748894bbbbc6 /include/linux/res_counter.h
parent59bd26582de660d4c9c26125747f1b4a5eb40d1e (diff)
Memory controller: resource counters
With fixes from David Rientjes <rientjes@google.com> Introduce generic structures and routines for resource accounting. Each resource accounting cgroup is supposed to aggregate it, cgroup_subsystem_state and its resource-specific members within. Signed-off-by: Pavel Emelianov <xemul@openvz.org> Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com> Cc: Paul Menage <menage@google.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Nick Piggin <nickpiggin@yahoo.com.au> Cc: Kirill Korotaev <dev@sw.ru> Cc: Herbert Poetzl <herbert@13thfloor.at> Cc: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com> Signed-off-by: David Rientjes <rientjes@google.com> Cc: Pavel Emelianov <xemul@openvz.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/res_counter.h')
-rw-r--r--include/linux/res_counter.h102
1 files changed, 102 insertions, 0 deletions
diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h
new file mode 100644
index 00000000000..eeb3f774977
--- /dev/null
+++ b/include/linux/res_counter.h
@@ -0,0 +1,102 @@
1#ifndef __RES_COUNTER_H__
2#define __RES_COUNTER_H__
3
4/*
5 * Resource Counters
6 * Contain common data types and routines for resource accounting
7 *
8 * Copyright 2007 OpenVZ SWsoft Inc
9 *
10 * Author: Pavel Emelianov <xemul@openvz.org>
11 *
12 */
13
14#include <linux/cgroup.h>
15
16/*
17 * The core object. the cgroup that wishes to account for some
18 * resource may include this counter into its structures and use
19 * the helpers described beyond
20 */
21
22struct res_counter {
23 /*
24 * the current resource consumption level
25 */
26 unsigned long usage;
27 /*
28 * the limit that usage cannot exceed
29 */
30 unsigned long limit;
31 /*
32 * the number of unsuccessful attempts to consume the resource
33 */
34 unsigned long failcnt;
35 /*
36 * the lock to protect all of the above.
37 * the routines below consider this to be IRQ-safe
38 */
39 spinlock_t lock;
40};
41
42/*
43 * Helpers to interact with userspace
44 * res_counter_read/_write - put/get the specified fields from the
45 * res_counter struct to/from the user
46 *
47 * @counter: the counter in question
48 * @member: the field to work with (see RES_xxx below)
49 * @buf: the buffer to opeate on,...
50 * @nbytes: its size...
51 * @pos: and the offset.
52 */
53
54ssize_t res_counter_read(struct res_counter *counter, int member,
55 const char __user *buf, size_t nbytes, loff_t *pos);
56ssize_t res_counter_write(struct res_counter *counter, int member,
57 const char __user *buf, size_t nbytes, loff_t *pos);
58
59/*
60 * the field descriptors. one for each member of res_counter
61 */
62
63enum {
64 RES_USAGE,
65 RES_LIMIT,
66 RES_FAILCNT,
67};
68
69/*
70 * helpers for accounting
71 */
72
73void res_counter_init(struct res_counter *counter);
74
75/*
76 * charge - try to consume more resource.
77 *
78 * @counter: the counter
79 * @val: the amount of the resource. each controller defines its own
80 * units, e.g. numbers, bytes, Kbytes, etc
81 *
82 * returns 0 on success and <0 if the counter->usage will exceed the
83 * counter->limit _locked call expects the counter->lock to be taken
84 */
85
86int res_counter_charge_locked(struct res_counter *counter, unsigned long val);
87int res_counter_charge(struct res_counter *counter, unsigned long val);
88
89/*
90 * uncharge - tell that some portion of the resource is released
91 *
92 * @counter: the counter
93 * @val: the amount of the resource
94 *
95 * these calls check for usage underflow and show a warning on the console
96 * _locked call expects the counter->lock to be taken
97 */
98
99void res_counter_uncharge_locked(struct res_counter *counter, unsigned long val);
100void res_counter_uncharge(struct res_counter *counter, unsigned long val);
101
102#endif