From 2c7eabf37647dd459d555e76954b4de87be2321f Mon Sep 17 00:00:00 2001 From: Paul Menage Date: Tue, 29 Apr 2008 00:59:58 -0700 Subject: CGroup API files: add res_counter_read_u64() Adds a function for returning the value of a resource counter member, in a form suitable for use in a cgroup read_u64 control file method. Signed-off-by: Paul Menage Cc: "Li Zefan" Cc: Balbir Singh Cc: Paul Jackson Cc: Pavel Emelyanov Cc: KAMEZAWA Hiroyuki Cc: "YAMAMOTO Takashi" Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- include/linux/res_counter.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'include/linux/res_counter.h') diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h index 61363ce896d..8cb1ecd420a 100644 --- a/include/linux/res_counter.h +++ b/include/linux/res_counter.h @@ -39,8 +39,9 @@ struct res_counter { spinlock_t lock; }; -/* +/** * Helpers to interact with userspace + * res_counter_read_u64() - returns the value of the specified member. * res_counter_read/_write - put/get the specified fields from the * res_counter struct to/from the user * @@ -51,6 +52,8 @@ struct res_counter { * @pos: and the offset. */ +u64 res_counter_read_u64(struct res_counter *counter, int member); + ssize_t res_counter_read(struct res_counter *counter, int member, const char __user *buf, size_t nbytes, loff_t *pos, int (*read_strategy)(unsigned long long val, char *s)); -- cgit v1.2.3 From c84872e168d10926acd2dee975d19172eef79252 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Tue, 29 Apr 2008 01:00:17 -0700 Subject: memcgroup: add the max_usage member on the res_counter This field is the maximal value of the usage one since the counter creation (or since the latest reset). To reset this to the usage value simply write anything to the appropriate cgroup file. Signed-off-by: Pavel Emelyanov Acked-by: Balbir Singh Cc: KAMEZAWA Hiroyuki Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- include/linux/res_counter.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'include/linux/res_counter.h') diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h index 8cb1ecd420a..df8085acba1 100644 --- a/include/linux/res_counter.h +++ b/include/linux/res_counter.h @@ -24,6 +24,10 @@ struct res_counter { * the current resource consumption level */ unsigned long long usage; + /* + * the maximal value of the usage from the counter creation + */ + unsigned long long max_usage; /* * the limit that usage cannot exceed */ @@ -67,6 +71,7 @@ ssize_t res_counter_write(struct res_counter *counter, int member, enum { RES_USAGE, + RES_MAX_USAGE, RES_LIMIT, RES_FAILCNT, }; @@ -127,4 +132,13 @@ static inline bool res_counter_check_under_limit(struct res_counter *cnt) return ret; } +static inline void res_counter_reset_max(struct res_counter *cnt) +{ + unsigned long flags; + + spin_lock_irqsave(&cnt->lock, flags); + cnt->max_usage = cnt->usage; + spin_unlock_irqrestore(&cnt->lock, flags); +} + #endif -- cgit v1.2.3 From faebe9fdf35058bb8421e4c09f6f70994eaf8db2 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Tue, 29 Apr 2008 01:00:18 -0700 Subject: memcgroups: add a document describing the resource counter abstraction The resource counter is supposed to facilitate the resource accounting of arbitrary resource (and it already does this for memory controller). However, it is about to be used in other resources controllers (swap, kernel memory, networking, etc), so provide a doc describing how to work with it. This will eliminate all the possible future duplications in the appropriate controllers' docs. Fixed errors pointed out by Randy. [akpm@linux-foundation.org: fix documentation tpyo] Signed-off-by: Pavel Emelyanov Cc: Randy Dunlap Cc: Balbir Singh Cc: KAMEZAWA Hiroyuki Cc: Li Zefan Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- include/linux/res_counter.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/linux/res_counter.h') diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h index df8085acba1..629d0ea2d07 100644 --- a/include/linux/res_counter.h +++ b/include/linux/res_counter.h @@ -9,6 +9,8 @@ * * Author: Pavel Emelianov * + * See Documentation/controllers/resource_counter.txt for more + * info about what this counter is. */ #include -- cgit v1.2.3 From 29f2a4dac856e9433a502b05b40e8e90385d8e27 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Tue, 29 Apr 2008 01:00:21 -0700 Subject: memcgroup: implement failcounter reset This is a very common requirement from people using the resource accounting facilities (not only memcgroup but also OpenVZ beancounters). They want to put the cgroup in an initial state without re-creating it. For example after re-configuring a group people want to observe how this new configuration fits the group needs without saving the previous failcnt value. Merge two resets into one mem_cgroup_reset() function to demonstrate how multiplexing work. Besides, I have plans to move the files, that correspond to res_counter to the res_counter.c file and somehow "import" them into controller. I don't know how to make it gracefully yet, but merging resets of max_usage and failcnt in one function will be there for sure. [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: Pavel Emelyanov Acked-by: KAMEZAWA Hiroyuki Cc: Balbir Singh Cc: Paul Menage Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- include/linux/res_counter.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include/linux/res_counter.h') diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h index 629d0ea2d07..6d9e1fca098 100644 --- a/include/linux/res_counter.h +++ b/include/linux/res_counter.h @@ -143,4 +143,12 @@ static inline void res_counter_reset_max(struct res_counter *cnt) spin_unlock_irqrestore(&cnt->lock, flags); } +static inline void res_counter_reset_failcnt(struct res_counter *cnt) +{ + unsigned long flags; + + spin_lock_irqsave(&cnt->lock, flags); + cnt->failcnt = 0; + spin_unlock_irqrestore(&cnt->lock, flags); +} #endif -- cgit v1.2.3