Skip to contentSkip to conversation

ResCounter: Add res_counter_read_uint and use it in memory cgroup

PATCH In review [email protected] 5 participants 12 messages Feb 21, 2008 – Feb 24, 2008

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

cover ResCounter: Add res_counter_read_uint and use it in memory cgroup

These patches simplify the code required to report values from a res_counter object in a cgroups control file.

The first patch adds res_counter_read_uint, which simply reports the current value for a res_counter member.

The second replaces the existing mem_cgroup_read() with a simpler version that calls res_counter_read_uint().

--

--
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>

#1 lore raw

PATCH 1/2 ResCounter: Add res_counter_read_uint()

Adds a function for returning the value of a resource counter member, in a form suitable for use in a cgroup read_uint control file method.

---
 include/linux/res_counter.h |    1 +
 kernel/res_counter.c        |    5 +++++
 2 files changed, 6 insertions(+)
include/linux/res_counter.h +1 -0
Index: rescounter-2.6.25-rc2-mm1/include/linux/res_counter.h
===================================================================
@@ -54,6 +54,7 @@ struct res_counter {
 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));
+u64 res_counter_read_uint(struct res_counter *counter, int member);
 ssize_t res_counter_write(struct res_counter *counter, int member,
 		const char __user *buf, size_t nbytes, loff_t *pos,
 		int (*write_strategy)(char *buf, unsigned long long *val));
kernel/res_counter.c +5 -0
Index: rescounter-2.6.25-rc2-mm1/kernel/res_counter.c
===================================================================
@@ -92,6 +92,11 @@ ssize_t res_counter_read(struct res_coun
 			pos, buf, s - buf);
 }
 
+u64 res_counter_read_uint(struct res_counter *counter, int member)
+{
+	return *res_counter_member(counter, member);
+}
+
 ssize_t res_counter_write(struct res_counter *counter, int member,
 		const char __user *userbuf, size_t nbytes, loff_t *pos,
 		int (*write_strategy)(char *st_buf, unsigned long long *val))

--

--
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

PATCH 2/2 ResCounter: Use read_uint in memory controller

In reply to [email protected]

Update the memory controller to use read_uint for its limit/usage/failcnt control files, calling the new res_counter_read_uint() function.

---
 mm/memcontrol.c |   15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
mm/memcontrol.c +6 -9
Index: rescounter-2.6.25-rc2-mm1/mm/memcontrol.c
===================================================================
@@ -922,13 +922,10 @@ int mem_cgroup_write_strategy(char *buf,
 	return 0;
 }
 
-static ssize_t mem_cgroup_read(struct cgroup *cont,
-			struct cftype *cft, struct file *file,
-			char __user *userbuf, size_t nbytes, loff_t *ppos)
+static u64 mem_cgroup_read(struct cgroup *cont, struct cftype *cft)
 {
-	return res_counter_read(&mem_cgroup_from_cont(cont)->res,
-				cft->private, userbuf, nbytes, ppos,
-				NULL);
+	return res_counter_read_uint(&mem_cgroup_from_cont(cont)->res,
+				     cft->private);
 }
 
 static ssize_t mem_cgroup_write(struct cgroup *cont, struct cftype *cft,
@@ -1024,18 +1021,18 @@ static struct cftype mem_cgroup_files[] 
 	{
 		.name = "usage_in_bytes",
 		.private = RES_USAGE,
-		.read = mem_cgroup_read,
+		.read_uint = mem_cgroup_read,
 	},
 	{
 		.name = "limit_in_bytes",
 		.private = RES_LIMIT,
 		.write = mem_cgroup_write,
-		.read = mem_cgroup_read,
+		.read_uint = mem_cgroup_read,
 	},
 	{
 		.name = "failcnt",
 		.private = RES_FAILCNT,
-		.read = mem_cgroup_read,
+		.read_uint = mem_cgroup_read,
 	},
 	{
 		.name = "force_empty",

--

--
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>

#3 lore raw

Re: [PATCH 2/2] ResCounter: Use read_uint in memory controller

Quoted 6 lines · [email protected] wrote:

Update the memory controller to use read_uint for its limit/usage/failcnt control files, calling the new res_counter_read_uint() function.

Hi, Paul,

Looks good, except for the name uint(), can we make it u64(). Integers are 32 bit on both ILP32 and LP64, but we really read/write 64 bit values.

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

--
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>
maintainer
#4 lore raw

Re: [PATCH 2/2] ResCounter: Use read_uint in memory controller

Quoted 5 lines · On Fri, 22 Feb 2008 09:59:41 +0530 Balbir Singh <[email protected]>…
Quoted 4 lines · [email protected] wrote:

Update the memory controller to use read_uint for its limit/usage/failcnt control files, calling the new res_counter_read_uint() function.

Quoted 8 lines
Quoted 2 lines

Hi, Paul,

Looks good, except for the name uint(), can we make it u64(). Integers are 32 bit on both ILP32 and LP64, but we really read/write 64 bit values.

yup, I agree. Even though I don't know what ILP32 and LP64 are ;)

--
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>

#5 lore raw

Re: [PATCH 2/2] ResCounter: Use read_uint in memory controller

Hi Andrew,

Quoted 1 line

yup, I agree. Even though I don't know what ILP32 and LP64 are ;)

ILP32: integer and long and pointer size is 32bit
LP64:  long and pointer size is 64bit, but int size is 32bit

linux 32bit kernel obey ILP32 model, 64bit kernel obey LP64.

Thanks.

- kosaki

--
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>

#6 lore raw

Re: [PATCH 2/2] ResCounter: Use read_uint in memory controller

In reply to Andrew Morton
Quoted 9 lines · Andrew Morton
Quoted 7 lines · On Fri, 22 Feb 2008 09:59:41 +0530 Balbir Singh <[email protected]>…
Quoted 6 lines · [email protected] wrote:

Update the memory controller to use read_uint for its limit/usage/failcnt control files, calling the new res_counter_read_uint() function.

Quoted 7 lines
Quoted 5 lines

Hi, Paul,

Looks good, except for the name uint(), can we make it u64(). Integers are 32 bit on both ILP32 and LP64, but we really read/write 64 bit values.

yup, I agree. Even though I don't know what ILP32 and LP64 are ;)

ILP32 and LP64 are programming models. They stand for Integer, Long, Pointer 32 bit for 32 bit systems and Long, Pointer 64 bit for 64 bit systems (which implies integers are 32 bit).

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

--
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>
#7 lore raw

Re: [PATCH 2/2] ResCounter: Use read_uint in memory controller

In reply to Balbir Singh
Quoted 3 lines · Balbir Singh

Looks good, except for the name uint(), can we make it u64(). Integers are 32 bit on both ILP32 and LP64, but we really read/write 64 bit values.

Yes, that's true. But read_uint() is more consistent with all the other instances in cgroups and subsystems. So if we were to call it res_counter_read_u64() I'd also want to rename all the other *read_uint functions/fields to *read_u64 too. Can I do that in a separate patch?

Paul

--
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>

maintainer
#8 lore raw

Re: [PATCH 2/2] ResCounter: Use read_uint in memory controller

Quoted 11 lines · On Sat, 23 Feb 2008 06:33:34 -0800 "Paul Menage" <[email protected]> wrote:
Quoted 3 lines · Balbir Singh

Looks good, except for the name uint(), can we make it u64(). Integers are 32 bit on both ILP32 and LP64, but we really read/write 64 bit values.

Yes, that's true. But read_uint() is more consistent with all the other instances in cgroups and subsystems. So if we were to call it res_counter_read_u64() I'd also want to rename all the other *read_uint functions/fields to *read_u64 too. Can I do that in a separate patch?

Sounds sensible to me.

--
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>

#9 lore raw

Re: [PATCH 2/2] ResCounter: Use read_uint in memory controller

Quoted 5 lines · Andrew Morton
Quoted 3 lines · On Sat, 23 Feb 2008 06:33:34 -0800 "Paul Menage" <[email protected]> wrote:
Quoted 2 lines · Balbir Singh

Looks good, except for the name uint(), can we make it u64(). Integers are 32 bit on both ILP32 and LP64, but we really read/write 64 bit values.

Quoted 9 lines
Quoted 6 lines

Yes, that's true. But read_uint() is more consistent with all the other instances in cgroups and subsystems. So if we were to call it res_counter_read_u64() I'd also want to rename all the other *read_uint functions/fields to *read_u64 too. Can I do that in a separate patch?

Sounds sensible to me.

Sure, fair enough.

Signature · 4 lines
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL
#10 lore raw

Re: [PATCH 2/2] ResCounter: Use read_uint in memory controller

Quoted 10 lines · Balbir Singh
Quoted 7 lines
Quoted 4 lines

res_counter_read_u64() I'd also want to rename all the other *read_uint functions/fields to *read_u64 too. Can I do that in a separate patch?

Sounds sensible to me.

Sure, fair enough.

Actually, since multiple people were asking for this change I did the search/replace and sent it out already (as a precursor of the other patches in the series that I sent today).

Paul

--
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>

Acked-by on v1 2/2
#11 lore raw

Re: [PATCH 2/2] ResCounter: Use read_uint in memory controller

In reply to [email protected]
Quoted 5 lines · [email protected] wrote:

Update the memory controller to use read_uint for its limit/usage/failcnt control files, calling the new res_counter_read_uint() function.

--
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>