Skip to contentSkip to conversation

Add the max_usage member on the res_counter

PATCH In review Pavel Emelyanov 3 participants 4 messages Mar 7, 2008 – Mar 11, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Add the max_usage member on the res_counter

This is a very usefull feature. E.g. one may set the limit to "unlimited" value and check for the memory requirements of a new container.

---
 include/linux/res_counter.h |    5 +++++
 kernel/res_counter.c        |    4 ++++
 mm/memcontrol.c             |    5 +++++
 3 files changed, 14 insertions(+), 0 deletions(-)
include/linux/res_counter.h +5 -0
index 8cb1ecd..2c4deb5 100644
@@ -25,6 +25,10 @@ struct res_counter {
 	 */
 	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
 	 */
 	unsigned long long limit;
@@ -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,
 };
kernel/res_counter.c +4 -0
index 791ff2b..f1f20c2 100644
@@ -27,6 +27,8 @@ int res_counter_charge_locked(struct res_counter *counter, unsigned long val)
 	}
 
 	counter->usage += val;
+	if (counter->usage > counter->max_usage)
+		counter->max_usage = counter->usage;
 	return 0;
 }
 
@@ -65,6 +67,8 @@ res_counter_member(struct res_counter *counter, int member)
 	switch (member) {
 	case RES_USAGE:
 		return &counter->usage;
+	case RES_MAX_USAGE:
+		return &counter->max_usage;
 	case RES_LIMIT:
 		return &counter->limit;
 	case RES_FAILCNT:
mm/memcontrol.c +5 -0
index 2d59163..e5c741a 100644
@@ -911,6 +911,11 @@ static struct cftype mem_cgroup_files[] = {
 		.read_u64 = mem_cgroup_read,
 	},
 	{
+		.name = "max_usage_in_bytes",
+		.private = RES_MAX_USAGE,
+		.read_u64 = mem_cgroup_read,
+	},
+	{
 		.name = "limit_in_bytes",
 		.private = RES_LIMIT,
 		.write = mem_cgroup_write,
Signature · 1 line
1.5.3.4
#1 lore raw
Quoted 4 lines · On Fri, 07 Mar 2008 18:30:55 +0300 Pavel Emelyanov…

This is a very usefull feature. E.g. one may set the limit to "unlimited" value and check for the memory requirements of a new container.

Hm, I like this. Could you add a method to reset this counter ?

Thanks,
-Kame

Quoted 77 lines
---
 include/linux/res_counter.h |    5 +++++
 kernel/res_counter.c        |    4 ++++
 mm/memcontrol.c             |    5 +++++
 3 files changed, 14 insertions(+), 0 deletions(-)
include/linux/res_counter.h +5 -0
index 8cb1ecd..2c4deb5 100644
@@ -25,6 +25,10 @@ struct res_counter {
 	 */
 	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
 	 */
 	unsigned long long limit;
@@ -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,
 };
kernel/res_counter.c +4 -0
index 791ff2b..f1f20c2 100644
@@ -27,6 +27,8 @@ int res_counter_charge_locked(struct res_counter *counter, unsigned long val)
 	}
 
 	counter->usage += val;
+	if (counter->usage > counter->max_usage)
+		counter->max_usage = counter->usage;
 	return 0;
 }
 
@@ -65,6 +67,8 @@ res_counter_member(struct res_counter *counter, int member)
 	switch (member) {
 	case RES_USAGE:
 		return &counter->usage;
+	case RES_MAX_USAGE:
+		return &counter->max_usage;
 	case RES_LIMIT:
 		return &counter->limit;
 	case RES_FAILCNT:
mm/memcontrol.c +5 -0
index 2d59163..e5c741a 100644
@@ -911,6 +911,11 @@ static struct cftype mem_cgroup_files[] = {
 		.read_u64 = mem_cgroup_read,
 	},
 	{
+		.name = "max_usage_in_bytes",
+		.private = RES_MAX_USAGE,
+		.read_u64 = mem_cgroup_read,
+	},
+	{
 		.name = "limit_in_bytes",
 		.private = RES_LIMIT,
 		.write = mem_cgroup_write,
Signature · 7 lines
1.5.3.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw
Quoted 8 lines · KAMEZAWA Hiroyuki
Quoted 4 lines · On Fri, 07 Mar 2008 18:30:55 +0300 Pavel Emelyanov…

This is a very usefull feature. E.g. one may set the limit to "unlimited" value and check for the memory requirements of a new container.

Hm, I like this. Could you add a method to reset this counter ?

OK. Sounds reasonable.

Quoted 3 lines

How about

	counter->max_usage = max(counter->usage, counter->max_usage);

No, I prefer explicit checks :)

Quoted 3 lines

Looks very good,

OK. I'll push this change the the git at openvz.org then.

Acked-by on v1 1/2
#3 lore raw
In reply to Pavel Emelyanov
Quoted 40 lines · Pavel Emelyanov

This is a very usefull feature. E.g. one may set the limit to "unlimited" value and check for the memory requirements of a new container.

---
 include/linux/res_counter.h |    5 +++++
 kernel/res_counter.c        |    4 ++++
 mm/memcontrol.c             |    5 +++++
 3 files changed, 14 insertions(+), 0 deletions(-)
include/linux/res_counter.h +5 -0
index 8cb1ecd..2c4deb5 100644
@@ -25,6 +25,10 @@ struct res_counter {
 	 */
 	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
 	 */
 	unsigned long long limit;
@@ -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,
 };
kernel/res_counter.c +0 -0
index 791ff2b..f1f20c2 100644

kernel/res_counter.c int res_counter_charge_locked(struct res_counter *counter, unsigned long val) · line 31

Quoted 5 lines
kernel/res_counter.c +2 -0
@@ -27,6 +27,8 @@ int res_counter_charge_locked(struct res_counter *counter, unsigned long val)
 	}
 
 	counter->usage += val;
+	if (counter->usage > counter->max_usage)
+		counter->max_usage = counter->usage;

How about

	counter->max_usage = max(counter->usage, counter->max_usage);
Quoted 18 lines
kernel/res_counter.c +2 -0
 	return 0;
 }
 
@@ -65,6 +67,8 @@ res_counter_member(struct res_counter *counter, int member)
 	switch (member) {
 	case RES_USAGE:
 		return &counter->usage;
+	case RES_MAX_USAGE:
+		return &counter->max_usage;
 	case RES_LIMIT:
 		return &counter->limit;
 	case RES_FAILCNT:
mm/memcontrol.c +0 -0
index 2d59163..e5c741a 100644
@@ -911,6 +911,11 @@ static struct cftype mem_cgroup_files[] = {
 		.read_u64 = mem_cgroup_read,

mm/memcontrol.c static struct cftype mem_cgroup_files[] = { · line 921

Quoted 10 lines
mm/memcontrol.c +5 -0
 	},
 	{
+		.name = "max_usage_in_bytes",
+		.private = RES_MAX_USAGE,
+		.read_u64 = mem_cgroup_read,
+	},
+	{
 		.name = "limit_in_bytes",
 		.private = RES_LIMIT,
 		.write = mem_cgroup_write,

Looks very good,

Signature · 4 lines
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL