Memory controller improve user interface (v3)
Subsystems (3)
PATCH 1/1 Memory controller improve user interface (v3)
Changelog for version 3
1. Change memory.limit and memory.usage to memory.limit_in_bytes and memory.usage_in_bytes respectively
2. Remove "Bytes" from the output of the limit and usage counters
3. Remove spurious printk
Changelog for version 2
1. Back end tracking is done in bytes, round up values of the limit if the specified value is not a multiple of page size. Display memory.usage and memory.limit in bytes (Dave Hansen, Paul Menage)
Change the interface to use bytes instead of pages. Page sizes can vary across platforms and configurations. A new strategy routine has been added to the resource counters infrastructure to format the data as desired.
Suggested by David Rientjes, Andrew Morton and Herbert Poetzl
Tested on a UML setup with the config for memory control enabled.
---
---
Documentation/controllers/memory.txt | 28 ++++++++++++++--- include/linux/res_counter.h | 10 +++--- kernel/res_counter.c | 30 +++++++++++++----- mm/memcontrol.c | 56 +++++++++++++++++++++++++++-------- 4 files changed, 94 insertions(+), 30 deletions(-)
Documentation/controllers/memory.txt renamed from Documentation/controllers/memory.txt~mem-control-make-ui-more-usable +23 -5
@@ -165,11 +165,29 @@ c. Enable CONFIG_CONTAINER_MEM_CONT Since now we're in the 0 container, We can alter the memory limit: -# echo -n 6000 > /containers/0/memory.limit +# echo -n 4M > /containers/0/memory.limit_in_bytes + +NOTE: We can use a suffix (k, K, m, M, g or G) to indicate values in kilo, +mega or gigabytes. + +# cat /containers/0/memory.limit_in_bytes +4194304 Bytes + +NOTE: The interface has now changed to display the usage in bytes +instead of pages We can check the usage: -# cat /containers/0/memory.usage -25 +# cat /containers/0/memory.usage_in_bytes +1216512 Bytes + +Setting a limit to a number that is not a multiple of page size causes +rounding up of the value. The user must check back to see (by reading +memory.limit_in_bytes), to check for differences between desired values and +committed values. Currently, all accounting is done in multiples of PAGE_SIZE + +# echo -n 1 > memory.limit_in_bytes +# cat memory.limit_in_bytes +4096 Bytes The memory.failcnt field gives the number of times that the container limit was exceeded.
@@ -206,8 +224,8 @@ container might have some charge associa tasks have migrated away from it. If some pages are still left, after following the steps listed in sections 4.1 and 4.2, check the Swap Cache usage in /proc/meminfo to see if the Swap Cache usage is showing up in the -containers memory.usage counter. A simple test of swapoff -a and swapon -a -should free any pending Swap Cache usage. +containers memory.usage_in_bytes counter. A simple test of swapoff -a and +swapon -a should free any pending Swap Cache usage. 4.4 Choosing what to account -- Page Cache (unmapped) vs RSS (mapped)?
include/linux/res_counter.h renamed from include/linux/res_counter.h~mem-control-make-ui-more-usable +6 -4
@@ -23,11 +23,11 @@ struct res_counter {/* * the current resource consumption level */ -unsigned long usage; +unsigned long long usage;/* * the limit that usage cannot exceed */ -unsigned long limit; +unsigned long long limit;/* * the number of unsuccessful attempts to consume the resource */
@@ -52,9 +52,11 @@ struct res_counter {*/ ssize_t res_counter_read (struct res_counter *counter,int member, -const char __user *buf,size_t nbytes,loff_t *pos); +const char __user *buf,size_t nbytes,loff_t *pos, +int (*read_strategy)(unsigned long long val,char *s));ssize_t res_counter_write (struct res_counter *counter,int member, -const char __user *buf,size_t nbytes,loff_t *pos); +const char __user *buf,size_t nbytes,loff_t *pos, +int (*write_strategy)(char *buf,unsigned long long *val));/* * the field descriptors. one for each member of res_counter
kernel/res_counter.c renamed from kernel/res_counter.c~mem-control-make-ui-more-usable +21 -9
@@ -16,7 +16,7 @@void res_counter_init (struct res_counter *counter) {spin_lock_init (&counter->lock); - counter->limit = (unsigned long )LONG_MAX ; + counter->limit = (unsigned long long )LLONG_MAX ; }int res_counter_charge_locked (struct res_counter *counter,unsigned long val)
@@ -76,24 +76,29 @@ static inline unsigned long *res_counter }ssize_t res_counter_read (struct res_counter *counter,int member, -const char __user *userbuf,size_t nbytes,loff_t *pos) +const char __user *userbuf,size_t nbytes,loff_t *pos, +int (*read_strategy)(unsigned long long val,char *st_buf)) { -unsigned long *val; +unsigned long long *val;char buf[64 ], *s; s = buf; val =res_counter_member (counter, member); - s +=sprintf (s,"%lu\n" , *val); +if (read_strategy) + s +=read_strategy (*val, s); +else + s +=sprintf (s,"%lu\n" , *val);return simple_read_from_buffer ((void __user *)userbuf, nbytes, pos, buf, s - buf); }ssize_t res_counter_write (struct res_counter *counter,int member, -const char __user *userbuf,size_t nbytes,loff_t *pos) +const char __user *userbuf,size_t nbytes,loff_t *pos, +int (*write_strategy)(char *st_buf,unsigned long long *val)) {int ret;char *buf, *end; -unsigned long tmp, *val; +unsigned long long tmp, *val; buf =kmalloc (nbytes +1 ,GFP_KERNEL ); ret = -ENOMEM ;
@@ -106,9 +111,16 @@ ssize_t res_counter_write(struct res_cou goto out_free; ret = -EINVAL ; - tmp =simple_strtoul (buf, &end,10 ); -if (*end !='\0' ) - goto out_free; + +if (write_strategy) { +if (write_strategy (buf, &tmp)) { + goto out_free; + } + }else { + tmp =simple_strtoul (buf, &end,10 ); +if (*end !='\0' ) + goto out_free; + } val =res_counter_member (counter, member); *val = tmp;
mm/memcontrol.c renamed from mm/memcontrol.c~mem-control-make-ui-more-usable +44 -12
99 lines not on this page · raw message
_
Signature · 4 lines
Warm Regards, Balbir Singh Linux Technology Center IBM, ISTL
kernel/res_counter.c static inline unsigned long *res_counter · line 90
Quoted 5 lines · Balbir Singh
kernel/res_counter.c renamed from kernel/res_counter.c~mem-control-make-ui-more-usable +4
-1- s +=sprintf (s,"%lu\n" , *val); +if (read_strategy) + s +=read_strategy (*val, s); +else + s +=sprintf (s,"%lu\n" , *val);
This would be better as %llu
Quoted 1 line
+ tmp =
simple_strtoul(buf, &end, 10);
and this as simple_strtoull()
Paul
Quoted 7 lines · Paul Menage
kernel/res_counter.c static inline unsigned long *res_counter · line 90
Quoted 5 lines · Balbir Singh
kernel/res_counter.c renamed from kernel/res_counter.c~mem-control-make-ui-more-usable +4
-1- s +=sprintf (s,"%lu\n" , *val); +if (read_strategy) + s +=read_strategy (*val, s); +else + s +=sprintf (s,"%lu\n" , *val);
Quoted 8 lines
This would be better as %llu
Quoted 1 line
+ tmp =
simple_strtoul(buf, &end, 10);and this as
simple_strtoull()Paul
Thanks for catching it, I'll fix that.
Signature · 4 lines
Warm Regards, Balbir Singh Linux Technology Center IBM, ISTL
Quoted 9 lines · Paul Menage
kernel/res_counter.c static inline unsigned long *res_counter · line 90
Quoted 5 lines · Balbir Singh
kernel/res_counter.c renamed from kernel/res_counter.c~mem-control-make-ui-more-usable +4
-1- s +=sprintf (s,"%lu\n" , *val); +if (read_strategy) + s +=read_strategy (*val, s); +else + s +=sprintf (s,"%lu\n" , *val);This would be better as %llu
Hi, Paul,
This does not need fixing, since the other counters like failcnt are still unsigned long
Quoted 4 lines
Quoted 1 line
+ tmp =
simple_strtoul(buf, &end, 10);and this as
simple_strtoull()
Will do, thanks!
Signature · 4 lines
Warm Regards, Balbir Singh Linux Technology Center IBM, ISTL
Quoted 8 lines · Balbir Singh
Quoted 7 lines · Paul Menage
Quoted 5 lines · Balbir Singh
kernel/res_counter.c renamed from kernel/res_counter.c~mem-control-make-ui-more-usable +4
-1- s +=sprintf (s,"%lu\n" , *val); +if (read_strategy) + s +=read_strategy (*val, s); +else + s +=sprintf (s,"%lu\n" , *val);
Quoted 8 lines
Quoted 2 lines
This would be better as %llu
Hi, Paul,
This does not need fixing, since the other counters like failcnt are still unsigned long
But val is an unsigned long long*. So printing *val with %lu will break (at least a warning, and maybe corruption if you had other parameters) on 32-bit archs.
Paul
Quoted 12 lines · Paul Menage
Quoted 11 lines · Balbir Singh
Quoted 8 lines · Paul Menage
kernel/res_counter.c static inline unsigned long *res_counter · line 90
Quoted 5 lines · Balbir Singh
kernel/res_counter.c renamed from kernel/res_counter.c~mem-control-make-ui-more-usable +4
-1- s +=sprintf (s,"%lu\n" , *val); +if (read_strategy) + s +=read_strategy (*val, s); +else + s +=sprintf (s,"%lu\n" , *val);This would be better as %llu
Hi, Paul,
Quoted 8 lines
Quoted 3 lines
This does not need fixing, since the other counters like failcnt are still unsigned long
But val is an unsigned long long*. So printing *val with %lu will break (at least a warning, and maybe corruption if you had other parameters) on 32-bit archs.
Yeah... Hmm.. just wonder if all the counters should be unsigned long long? failcnt is the only remaining unsigned long counter now.
Signature · 4 lines
Warm Regards, Balbir Singh Linux Technology Center IBM, ISTL
Quoted 5 lines
But val is an unsigned long long*. So printing *val with %lu will break (at least a warning, and maybe corruption if you had other parameters) on 32-bit archs.
How does this look?
Changelog for version 4
1. Make all resource counters members unsigned long long
2. Use documentation comments from Dave Hansen
Changelog for version 3
1. Change memory.limit and memory.usage to memory.limit_in_bytes and memory.usage_in_bytes respectively
2. Remove "Bytes" from the output of the limit and usage counters
3. Remove spurious printk
Changelog for version 2
1. Back end tracking is done in bytes, round up values of the limit if the specified value is not a multiple of page size. Display memory.usage and memory.limit in bytes (Dave Hansen, Paul Menage)
Change the interface to use bytes instead of pages. Page sizes can vary across platforms and configurations. A new strategy routine has been added to the resource counters infrastructure to format the data as desired.
Suggested by David Rientjes, Andrew Morton and Herbert Poetzl
Tested on a UML setup with the config for memory control enabled.
---
Documentation/controllers/memory.txt | 29 ++++++++++++++++++++++++----- include/linux/res_counter.h | 12 +++++++----- kernel/res_counter.c | 34 +++++++++++++++++++++++----------- mm/memcontrol.c | 35 +++++++++++++++++++++++++---------- 4 files changed, 79 insertions(+), 31 deletions(-)
Documentation/controllers/memory.txt renamed from Documentation/controllers/memory.txt~mem-control-make-ui-more-usable +24 -5
@@ -165,11 +165,30 @@ c. Enable CONFIG_CONTAINER_MEM_CONT Since now we're in the 0 container, We can alter the memory limit: -# echo -n 6000 > /containers/0/memory.limit +# echo -n 4M > /containers/0/memory.limit_in_bytes + +NOTE: We can use a suffix (k, K, m, M, g or G) to indicate values in kilo, +mega or gigabytes. + +# cat /containers/0/memory.limit_in_bytes +4194304 Bytes + +NOTE: The interface has now changed to display the usage in bytes +instead of pages We can check the usage: -# cat /containers/0/memory.usage -25 +# cat /containers/0/memory.usage_in_bytes +1216512 Bytes + +A successful write to this file does not guarantee a successful set of +this limit to the value written into the file. This can be due to a +number of factors, such as rounding up to page boundaries or the total +availability of memory on the system. The user is required to re-read +this file after a write to guarantee the value committed by the kernel. + +# echo -n 1 > memory.limit_in_bytes +# cat memory.limit_in_bytes +4096 Bytes The memory.failcnt field gives the number of times that the container limit was exceeded.
@@ -206,8 +225,8 @@ container might have some charge associa tasks have migrated away from it. If some pages are still left, after following the steps listed in sections 4.1 and 4.2, check the Swap Cache usage in /proc/meminfo to see if the Swap Cache usage is showing up in the -containers memory.usage counter. A simple test of swapoff -a and swapon -a -should free any pending Swap Cache usage. +containers memory.usage_in_bytes counter. A simple test of swapoff -a and +swapon -a should free any pending Swap Cache usage. 4.4 Choosing what to account -- Page Cache (unmapped) vs RSS (mapped)?
include/linux/res_counter.h renamed from include/linux/res_counter.h~mem-control-make-ui-more-usable +7 -5
@@ -23,15 +23,15 @@ struct res_counter {/* * the current resource consumption level */ -unsigned long usage; +unsigned long long usage;/* * the limit that usage cannot exceed */ -unsigned long limit; +unsigned long long limit;/* * the number of unsuccessful attempts to consume the resource */ -unsigned long failcnt; +unsigned long long failcnt;/* * the lock to protect all of the above. * the routines below consider this to be IRQ-safe
@@ -52,9 +52,11 @@ struct res_counter {*/ ssize_t res_counter_read (struct res_counter *counter,int member, -const char __user *buf,size_t nbytes,loff_t *pos); +const char __user *buf,size_t nbytes,loff_t *pos, +int (*read_strategy)(unsigned long long val,char *s));ssize_t res_counter_write (struct res_counter *counter,int member, -const char __user *buf,size_t nbytes,loff_t *pos); +const char __user *buf,size_t nbytes,loff_t *pos, +int (*write_strategy)(char *buf,unsigned long long *val));/* * the field descriptors. one for each member of res_counter
kernel/res_counter.c renamed from kernel/res_counter.c~mem-control-make-ui-more-usable +23 -11
@@ -16,7 +16,7 @@void res_counter_init (struct res_counter *counter) {spin_lock_init (&counter->lock); - counter->limit = (unsigned long )LONG_MAX ; + counter->limit = (unsigned long long )LLONG_MAX ; }int res_counter_charge_locked (struct res_counter *counter,unsigned long val)
@@ -59,8 +59,8 @@ void res_counter_uncharge(struct res_cou } -static inline unsigned long *res_counter_member (struct res_counter *counter, -int member) +static inline unsigned long long * +res_counter_member (struct res_counter *counter,int member) {switch (member) {case RES_USAGE :
@@ -76,24 +76,29 @@ static inline unsigned long *res_counter }ssize_t res_counter_read (struct res_counter *counter,int member, -const char __user *userbuf,size_t nbytes,loff_t *pos) +const char __user *userbuf,size_t nbytes,loff_t *pos, +int (*read_strategy)(unsigned long long val,char *st_buf)) { -unsigned long *val; +unsigned long long *val;char buf[64 ], *s; s = buf; val =res_counter_member (counter, member); - s +=sprintf (s,"%lu\n" , *val); +if (read_strategy) + s +=read_strategy (*val, s); +else + s +=sprintf (s,"%llu\n" , *val);return simple_read_from_buffer ((void __user *)userbuf, nbytes, pos, buf, s - buf); }ssize_t res_counter_write (struct res_counter *counter,int member, -const char __user *userbuf,size_t nbytes,loff_t *pos) +const char __user *userbuf,size_t nbytes,loff_t *pos, +int (*write_strategy)(char *st_buf,unsigned long long *val)) {int ret;char *buf, *end; -unsigned long tmp, *val; +unsigned long long tmp, *val; buf =kmalloc (nbytes +1 ,GFP_KERNEL ); ret = -ENOMEM ;
@@ -106,9 +111,16 @@ ssize_t res_counter_write(struct res_cou goto out_free; ret = -EINVAL ; - tmp =simple_strtoul (buf, &end,10 ); -if (*end !='\0' ) - goto out_free; + +if (write_strategy) { +if (write_strategy (buf, &tmp)) { + goto out_free; + } + }else { + tmp =simple_strtoull (buf, &end,10 ); +if (*end !='\0' ) + goto out_free; + } val =res_counter_member (counter, member); *val = tmp;
mm/memcontrol.c renamed from mm/memcontrol.c~mem-control-make-ui-more-usable +25 -10
@@ -313,7 +313,7 @@ int mem_container_charge(struct page *pa* If we created the page_container, we should free it on exceeding * the container limit. */ -while (res_counter_charge (&mem->res,1 )) { +while (res_counter_charge (&mem->res,PAGE_SIZE )) {if (try_to_free_mem_container_pages (mem))continue ;
@@ -353,7 +353,7 @@ int mem_container_charge(struct page *pakfree (pc); pc = race_pc;atomic_inc (&pc->ref_cnt); -res_counter_uncharge (&mem->res,1 ); +res_counter_uncharge (&mem->res,PAGE_SIZE );css_put (&mem->css); goto done; }
@@ -418,7 +418,7 @@ void mem_container_uncharge(struct page_css_put (&mem->css);page_assign_page_container (page,NULL );unlock_page_container (page); -res_counter_uncharge (&mem->res,1 ); +res_counter_uncharge (&mem->res,PAGE_SIZE );spin_lock_irqsave (&mem->lru_lock, flags);list_del_init (&pc->lru);
@@ -427,12 +427,26 @@ void mem_container_uncharge(struct page_ } } -static ssize_t mem_container_read (struct container *cont,struct cftype *cft, -struct file *file,char __user *userbuf,size_t nbytes, -loff_t *ppos) +int mem_container_write_strategy (char *buf,unsigned long long *tmp) +{ + *tmp =memparse (buf, &buf); +if (*buf !='\0' ) +return -EINVAL ; + +/* +* Round up the value to the closest page size +*/ + *tmp = ((*tmp +PAGE_SIZE -1 ) >>PAGE_SHIFT ) <<PAGE_SHIFT ; +return 0 ; +} + +static ssize_t mem_container_read (struct container *cont, +struct cftype *cft,struct file *file, +char __user *userbuf,size_t nbytes,loff_t *ppos) {return res_counter_read (&mem_container_from_cont (cont)->res, - cft->private, userbuf, nbytes, ppos); + cft->private, userbuf, nbytes, ppos, +NULL ); } static ssize_t mem_container_write(struct container *cont, struct cftype *cft,
@@ -440,7 +454,8 @@ static ssize_t mem_container_write(struc size_t nbytes, loff_t *ppos) { return res_counter_write(&mem_container_from_cont(cont)->res, - cft->private, userbuf, nbytes, ppos); + cft->private, userbuf, nbytes, ppos, +mem_container_write_strategy ); } static ssize_t mem_control_type_write(struct container *cont,
@@ -499,12 +514,12 @@ static ssize_t mem_control_type_read(strstatic struct cftype mem_container_files[] = { { - .name ="usage" , + .name ="usage_in_bytes" , .private =RES_USAGE , .read = mem_container_read, }, { - .name ="limit" , + .name ="limit_in_bytes" , .private =RES_LIMIT , .write = mem_container_write, .read = mem_container_read,
_
Signature · 4 lines
Warm Regards, Balbir Singh Linux Technology Center IBM, ISTL
Quoted 7 lines · Paul Menage
Review
Quoted 5 lines · Balbir Singh
(quoted diff) +4
-1- s += sprintf(s, "%lu\n", *val); + if (read_strategy) + s += read_strategy(*val, s); + else + s += sprintf(s, "%lu\n", *val);
Quoted 6 lines
This would be better as %llu
Quoted 1 line
+ tmp =
simple_strtoul(buf, &end, 10);and this as
simple_strtoull()
Hi,
Here's the new patch for the UI changes. I hope I've got it right (Jetlag can do funny things to the mind and eyes :-) )
Changelog for version 4
1. Fix parsing of unsigned long long arguments.
Changelog for version 3
1. Change memory.limit and memory.usage to memory.limit_in_bytes and memory.usage_in_bytes respectively
2. Remove "Bytes" from the output of the limit and usage counters
3. Remove spurious printk
Changelog for version 2
1. Back end tracking is done in bytes, round up values of the limit if the specified value is not a multiple of page size. Display memory.usage and memory.limit in bytes (Dave Hansen, Paul Menage)
Change the interface to use bytes instead of pages. Page sizes can vary across platforms and configurations. A new strategy routine has been added to the resource counters infrastructure to format the data as desired.
Suggested by David Rientjes, Andrew Morton and Herbert Poetzl
Tested on a UML setup with the config for memory control enabled.
---
---
Documentation/controllers/memory.txt | 28 ++++++++++++++--- include/linux/res_counter.h | 10 +++--- kernel/res_counter.c | 30 +++++++++++++----- mm/memcontrol.c | 56 +++++++++++++++++++++++++++-------- 4 files changed, 94 insertions(+), 30 deletions(-)
Documentation/controllers/memory.txt renamed from Documentation/controllers/memory.txt~mem-control-make-ui-more-usable +23 -5
@@ -165,11 +165,29 @@ c. Enable CONFIG_CONTAINER_MEM_CONT Since now we're in the 0 container, We can alter the memory limit: -# echo -n 6000 > /containers/0/memory.limit +# echo -n 4M > /containers/0/memory.limit_in_bytes + +NOTE: We can use a suffix (k, K, m, M, g or G) to indicate values in kilo, +mega or gigabytes. + +# cat /containers/0/memory.limit_in_bytes +4194304 Bytes + +NOTE: The interface has now changed to display the usage in bytes +instead of pages We can check the usage: -# cat /containers/0/memory.usage -25 +# cat /containers/0/memory.usage_in_bytes +1216512 Bytes + +Setting a limit to a number that is not a multiple of page size causes +rounding up of the value. The user must check back to see (by reading +memory.limit_in_bytes), to check for differences between desired values and +committed values. Currently, all accounting is done in multiples of PAGE_SIZE + +# echo -n 1 > memory.limit_in_bytes +# cat memory.limit_in_bytes +4096 Bytes The memory.failcnt field gives the number of times that the container limit was exceeded.
@@ -206,8 +224,8 @@ container might have some charge associa tasks have migrated away from it. If some pages are still left, after following the steps listed in sections 4.1 and 4.2, check the Swap Cache usage in /proc/meminfo to see if the Swap Cache usage is showing up in the -containers memory.usage counter. A simple test of swapoff -a and swapon -a -should free any pending Swap Cache usage. +containers memory.usage_in_bytes counter. A simple test of swapoff -a and +swapon -a should free any pending Swap Cache usage. 4.4 Choosing what to account -- Page Cache (unmapped) vs RSS (mapped)?
include/linux/res_counter.h renamed from include/linux/res_counter.h~mem-control-make-ui-more-usable +6 -4
@@ -23,11 +23,11 @@ struct res_counter {/* * the current resource consumption level */ -unsigned long usage; +unsigned long long usage;/* * the limit that usage cannot exceed */ -unsigned long limit; +unsigned long long limit;/* * the number of unsuccessful attempts to consume the resource */
@@ -52,9 +52,11 @@ struct res_counter {*/ ssize_t res_counter_read (struct res_counter *counter,int member, -const char __user *buf,size_t nbytes,loff_t *pos); +const char __user *buf,size_t nbytes,loff_t *pos, +int (*read_strategy)(unsigned long long val,char *s));ssize_t res_counter_write (struct res_counter *counter,int member, -const char __user *buf,size_t nbytes,loff_t *pos); +const char __user *buf,size_t nbytes,loff_t *pos, +int (*write_strategy)(char *buf,unsigned long long *val));/* * the field descriptors. one for each member of res_counter
kernel/res_counter.c renamed from kernel/res_counter.c~mem-control-make-ui-more-usable +21 -9
@@ -16,7 +16,7 @@void res_counter_init (struct res_counter *counter) {spin_lock_init (&counter->lock); - counter->limit = (unsigned long )LONG_MAX ; + counter->limit = (unsigned long long )LLONG_MAX ; }int res_counter_charge_locked (struct res_counter *counter,unsigned long val)
@@ -76,24 +76,29 @@ static inline unsigned long *res_counter }ssize_t res_counter_read (struct res_counter *counter,int member, -const char __user *userbuf,size_t nbytes,loff_t *pos) +const char __user *userbuf,size_t nbytes,loff_t *pos, +int (*read_strategy)(unsigned long long val,char *st_buf)) { -unsigned long *val; +unsigned long long *val;char buf[64 ], *s; s = buf; val =res_counter_member (counter, member); - s +=sprintf (s,"%lu\n" , *val); +if (read_strategy) + s +=read_strategy (*val, s); +else + s +=sprintf (s,"%lu\n" , *val);return simple_read_from_buffer ((void __user *)userbuf, nbytes, pos, buf, s - buf); }ssize_t res_counter_write (struct res_counter *counter,int member, -const char __user *userbuf,size_t nbytes,loff_t *pos) +const char __user *userbuf,size_t nbytes,loff_t *pos, +int (*write_strategy)(char *st_buf,unsigned long long *val)) {int ret;char *buf, *end; -unsigned long tmp, *val; +unsigned long long tmp, *val; buf =kmalloc (nbytes +1 ,GFP_KERNEL ); ret = -ENOMEM ;
@@ -106,9 +111,16 @@ ssize_t res_counter_write(struct res_cou goto out_free; ret = -EINVAL ; - tmp =simple_strtoul (buf, &end,10 ); -if (*end !='\0' ) - goto out_free; + +if (write_strategy) { +if (write_strategy (buf, &tmp)) { + goto out_free; + } + }else { + tmp =simple_strtoull (buf, &end,10 ); +if (*end !='\0' ) + goto out_free; + } val =res_counter_member (counter, member); *val = tmp;
mm/memcontrol.c renamed from mm/memcontrol.c~mem-control-make-ui-more-usable +44 -12
99 lines not on this page · raw message
_
Signature · 4 lines
Warm Regards, Balbir Singh Linux Technology Center IBM, ISTL
Documentation/controllers/memory.txt c. Enable CONFIG_CONTAINER_MEM_CONT · line 186
Quoted 5 lines · Balbir Singh
Documentation/controllers/memory.txt renamed from Documentation/controllers/memory.txt~mem-control-make-ui-more-usable +4
-0+Setting a limit to a number that is not a multiple of page size causes +rounding up of the value. The user must check back to see (by reading +memory.limit_in_bytes), to check for differences between desired values and +committed values. Currently, all accounting is done in multiples of PAGE_SIZE
I wonder if we can say this in a bit more generic fashion.
A successful write to this file does not guarantee a successful set of this limit to the value written into the file. This can be due to a number of factors, such as rounding up to page boundaries or the total availability of memory on the system. The user is required to re-read this file after a write to guarantee the value committed by the kernel.
This keeps a user from saying "I page aligned the value I stuck in there, no I don't have to check it."
-- Dave