Commit c84872e168d10926acd2dee975d19172eef79252

Authored by Pavel Emelyanov
Committed by Linus Torvalds
1 parent cf475ad28a

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 <xemul@openvz.org>
Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 3 changed files with 35 additions and 0 deletions Side-by-side Diff

include/linux/res_counter.h
... ... @@ -25,6 +25,10 @@
25 25 */
26 26 unsigned long long usage;
27 27 /*
  28 + * the maximal value of the usage from the counter creation
  29 + */
  30 + unsigned long long max_usage;
  31 + /*
28 32 * the limit that usage cannot exceed
29 33 */
30 34 unsigned long long limit;
... ... @@ -67,6 +71,7 @@
67 71  
68 72 enum {
69 73 RES_USAGE,
  74 + RES_MAX_USAGE,
70 75 RES_LIMIT,
71 76 RES_FAILCNT,
72 77 };
... ... @@ -125,6 +130,15 @@
125 130 ret = res_counter_limit_check_locked(cnt);
126 131 spin_unlock_irqrestore(&cnt->lock, flags);
127 132 return ret;
  133 +}
  134 +
  135 +static inline void res_counter_reset_max(struct res_counter *cnt)
  136 +{
  137 + unsigned long flags;
  138 +
  139 + spin_lock_irqsave(&cnt->lock, flags);
  140 + cnt->max_usage = cnt->usage;
  141 + spin_unlock_irqrestore(&cnt->lock, flags);
128 142 }
129 143  
130 144 #endif
kernel/res_counter.c
... ... @@ -28,6 +28,8 @@
28 28 }
29 29  
30 30 counter->usage += val;
  31 + if (counter->usage > counter->max_usage)
  32 + counter->max_usage = counter->usage;
31 33 return 0;
32 34 }
33 35  
... ... @@ -66,6 +68,8 @@
66 68 switch (member) {
67 69 case RES_USAGE:
68 70 return &counter->usage;
  71 + case RES_MAX_USAGE:
  72 + return &counter->max_usage;
69 73 case RES_LIMIT:
70 74 return &counter->limit;
71 75 case RES_FAILCNT:
... ... @@ -855,6 +855,17 @@
855 855 mem_cgroup_write_strategy);
856 856 }
857 857  
  858 +static ssize_t mem_cgroup_max_reset(struct cgroup *cont, struct cftype *cft,
  859 + struct file *file, const char __user *userbuf,
  860 + size_t nbytes, loff_t *ppos)
  861 +{
  862 + struct mem_cgroup *mem;
  863 +
  864 + mem = mem_cgroup_from_cont(cont);
  865 + res_counter_reset_max(&mem->res);
  866 + return nbytes;
  867 +}
  868 +
858 869 static ssize_t mem_force_empty_write(struct cgroup *cont,
859 870 struct cftype *cft, struct file *file,
860 871 const char __user *userbuf,
... ... @@ -907,6 +918,12 @@
907 918 {
908 919 .name = "usage_in_bytes",
909 920 .private = RES_USAGE,
  921 + .read_u64 = mem_cgroup_read,
  922 + },
  923 + {
  924 + .name = "max_usage_in_bytes",
  925 + .private = RES_MAX_USAGE,
  926 + .write = mem_cgroup_max_reset,
910 927 .read_u64 = mem_cgroup_read,
911 928 },
912 929 {