cgroup map files: Add a key/value map file type to cgroups
Subsystems (3)
cover cgroup map files: Add a key/value map file type to cgroups
These patches add a new cgroup control file output type - a map from strings to u64 values - and make use of it for the memory controller "stat" file.
It is intended for use when the subsystem wants to return a collection of values that are related in some way, for which a separate control file for each value would make the reporting unwieldy.
The advantages of this are:
- more standardized output from control files that report similarly-structured data
- less boilerplate required in cgroup subsystems
- simplifies transition to a future efficient cgroups binary API
--
--
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>
PATCH 1/2 cgroup map files: Add cgroup map data type
Adds a new type of supported control file representation, a map from strings to u64 values.
--- include/linux/cgroup.h | 19 +++++++++++++++ kernel/cgroup.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 1 deletion(-)
include/linux/cgroup.h +19 -0
@@ -166,6 +166,16 @@ struct css_set { }; +/* +* cgroup_map_cb is an abstract callback API for reporting map-valued +* control files +*/ + +struct cgroup_map_cb { +int (*fill)(struct cgroup_map_cb *cb,const char *key,u64 value); +void *state; +}; +/* struct cftype: * * The files in the cgroup filesystem mostly have a very simple read/write
@@ -194,6 +204,15 @@ struct cftype {* single integer. Use it in place of read() */ u64 (*read_uint) (struct cgroup *cont,struct cftype *cft); +/* +* read_map() is used for defining a map of key/value +* pairs. It should call cb->fill(cb, key, value) for each +* entry. The key/value pairs (and their ordering) should not +* change between reboots. +*/ +int (*read_map) (struct cgroup *cont,struct cftype *cft, +struct cgroup_map_cb *cb); +ssize_t (*write) (struct cgroup *cont,struct cftype *cft,struct file *file,const char __user *buf,size_t nbytes,loff_t *ppos);
kernel/cgroup.c +58 -1
77 lines not on this page · raw message
--
--
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>
PATCH 2/2 cgroup map files: Use cgroup map for memcontrol stats file
In reply to [email protected]Remove the seq_file boilerplate used to construct the memcontrol stats map, and instead use the new map representation for cgroup control files
--- mm/memcontrol.c | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-)
mm/memcontrol.c +6 -24
@@ -974,9 +974,9 @@ static const struct mem_cgroup_stat_desc [MEM_CGROUP_STAT_RSS] = { "rss", PAGE_SIZE, }, }; -static int mem_control_stat_show (struct seq_file *m,void *arg) +static int mem_control_stat_show (struct cgroup *cont,struct cftype *cft, +struct cgroup_map_cb *cb) { -struct cgroup *cont = m->private;struct mem_cgroup *mem_cont =mem_cgroup_from_cont (cont);struct mem_cgroup_stat *stat = &mem_cont->stat;int i;
@@ -986,8 +986,7 @@ static int mem_control_stat_show(struct val =mem_cgroup_read_stat (stat, i); val *= mem_cgroup_stat_desc[i].unit; -seq_printf (m,"%s %lld\n" , mem_cgroup_stat_desc[i].msg, - (long long )val); + cb->fill (cb, mem_cgroup_stat_desc[i].msg, val); }/* showing # of active pages */ {
@@ -997,29 +996,12 @@ static int mem_control_stat_show(struct MEM_CGROUP_ZSTAT_INACTIVE); active =mem_cgroup_get_all_zonestat (mem_cont,MEM_CGROUP_ZSTAT_ACTIVE ); -seq_printf (m,"active %ld\n" , (active) *PAGE_SIZE ); -seq_printf (m,"inactive %ld\n" , (inactive) *PAGE_SIZE ); + cb->fill (cb,"active" , (active) *PAGE_SIZE ); + cb->fill (cb,"inactive" , (inactive) *PAGE_SIZE ); }return 0 ; } -static const struct file_operations mem_control_stat_file_operations = { - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static int mem_control_stat_open (struct inode *unused,struct file *file) -{ -/* XXX __d_cont */ -struct cgroup *cont = file->f_dentry->d_parent->d_fsdata; - - file->f_op = &mem_control_stat_file_operations; -return single_open (file, mem_control_stat_show, cont); -} - - -static struct cftype mem_cgroup_files[] = { { .name ="usage_in_bytes" ,
@@ -1044,7 +1026,7 @@ static struct cftype mem_cgroup_files[] }, { .name = "stat", - .open = mem_control_stat_open, + .read_map = mem_control_stat_show, }, };
--
--
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>
Quoted 10 lines
These patches add a new cgroup control file output type - a map from strings to u64 values - and make use of it for the memory controller "stat" file.
It is intended for use when the subsystem wants to return a collection of values that are related in some way, for which a separate control file for each value would make the reporting unwieldy.
The advantages of this are:
Quoted 8 lines
- more standardized output from control files that report similarly-structured data
- less boilerplate required in cgroup subsystems
- simplifies transition to a future efficient cgroups binary API
Signed-off-by Paul Menage <[email protected]>
it changes the format from "%s %lld" to "%s: %llu", right? why?
YAMAMOTO Takashi
--
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>
Quoted 4 lines · YAMAMOTO Takashi
it changes the format from "%s %lld" to "%s: %llu", right? why?
The colon for consistency with maps in /proc. I think it also makes it slightly more readable.
For %lld versus %llu - I think that cgroup resource APIs are much more likely to need to report unsigned rather than signed values. In the case of the memory.stat file, that's certainly the case.
But I guess there's an argument to be made that nothing's likely to need the final 64th bit of an unsigned value, whereas the ability to report negative numbers could potentially be useful for some cgroups.
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>
Quoted 8 lines · YAMAMOTO Takashi
Quoted 4 lines
it changes the format from "%s %lld" to "%s: %llu", right? why?
The colon for consistency with maps in /proc. I think it also makes it slightly more readable.
can you be a little more specific?
i object against the colon because i want to use the same parser for /proc/vmstat, which doesn't have colons.
btw, when making ABI changes like this, can you please mention it explicitly in the patch descriptions?
Quoted 9 lines
For %lld versus %llu - I think that cgroup resource APIs are much more likely to need to report unsigned rather than signed values. In the case of the memory.stat file, that's certainly the case.
But I guess there's an argument to be made that nothing's likely to need the final 64th bit of an unsigned value, whereas the ability to report negative numbers could potentially be useful for some cgroups.
Paul
i don't have any strong opinions about signedness.
YAMAMOTO Takashi
--
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>
Quoted 6 lines · YAMAMOTO Takashi
Quoted 6 lines · YAMAMOTO Takashi
Quoted 4 lines
it changes the format from "%s %lld" to "%s: %llu", right? why?
Quoted 7 lines
Quoted 2 lines
The colon for consistency with maps in /proc. I think it also makes it slightly more readable.
can you be a little more specific?
i object against the colon because i want to use the same parser for
/proc/vmstat, which doesn't have colons.
Ah. This /proc behaviour of having multiple formats for reporting the same kind of data (compare with /proc/meminfo, which does use colons) is the kind of thing that I want to avoid with cgroups. i.e. if two cgroup subsystems are both reporting the same kind of structured data, then they should both use the same output format.
I guess since /proc has both styles, and memory.stat is the first file reporting key/value pairs in cgroups, you get to call the format. OK, I'll zap the colon.
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>