Add file f_flags to cgroup write_string ops
Subsystems (4)
RFC PATCH 1/2 Add file f_flags to cgroup write_string ops
cgroup subsystems may find the O_APPEND and O_NONBLOCK flags useful in determining the way they handle writes. For now only pass these flags through the write_string op.
A subsequent patch will make use of the O_NONBLOCK flag in the cgroup freezer write_string op.
(Cc'ing mem controller maintainers in case they find this useful..)
Cc: Balbir Singh <[email protected]>
Cc: Pavel Emelyanov <[email protected]>
Cc: KAMEZAWA Hiroyuki <[email protected]>
--- include/linux/cgroup.h | 3 ++- kernel/cgroup.c | 5 +++-- kernel/cgroup_freezer.c | 5 ++--- kernel/cpuset.c | 2 +- mm/memcontrol.c | 2 +- security/device_cgroup.c | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-)
include/linux/cgroup.h +2 -1
@@ -315,8 +315,9 @@ struct cftype {* buffer of maximum length determined by max_write_len. * Returns 0 or -ve error code. */ +#define CFTYPE_F_FLAGS (O_APPEND|O_NONBLOCK)int (*write_string)(struct cgroup *cgrp,struct cftype *cft, -const char *buffer); +unsigned int f_flags,const char *buffer);/* * trigger() callback can be used to get some kick from the * userspace, when the actual string written is not important
kernel/cgroup.c +3 -2
@@ -1449,7 +1449,7 @@ bool cgroup_lock_live_group(struct cgroup *cgrp) }static int cgroup_release_agent_write (struct cgroup *cgrp,struct cftype *cft, -const char *buffer) +unsigned int f_flags,const char *buffer) {BUILD_BUG_ON (sizeof (cgrp->root->release_agent_path) <PATH_MAX );if (!cgroup_lock_live_group (cgrp))
@@ -1534,7 +1534,8 @@ static ssize_t cgroup_write_string(struct cgroup *cgrp, struct cftype *cft, buffer[nbytes] =0 ;/* nul-terminate */ strstrip (buffer); - retval = cft->write_string (cgrp, cft, buffer); + retval = cft->write_string (cgrp, cft, file->f_flags &CFTYPE_F_FLAGS , + buffer);if (!retval) retval = nbytes; out:
kernel/cgroup_freezer.c +2 -3
@@ -343,9 +343,8 @@ out:return retval; } -static int freezer_write (struct cgroup *cgroup, -struct cftype *cft, -const char *buffer) +static int freezer_write (struct cgroup *cgroup,struct cftype *cft, +unsigned int f_flags,const char *buffer) {int retval;enum freezer_state goal_state;
kernel/cpuset.c +1 -1
@@ -1470,7 +1470,7 @@ static int cpuset_write_s64(struct cgroup *cgrp, struct cftype *cft, s64 val)* Common handling for a write to a "cpus" or "mems" file. */ static int cpuset_write_resmask (struct cgroup *cgrp,struct cftype *cft, -const char *buf) +unsigned int f_flags,const char *buf) {int retval =0 ;struct cpuset *cs =cgroup_cs (cgrp);
mm/memcontrol.c +1 -1
@@ -2072,7 +2072,7 @@ static u64 mem_cgroup_read(struct cgroup *cont, struct cftype *cft)* RES_LIMIT. */ static int mem_cgroup_write (struct cgroup *cont,struct cftype *cft, -const char *buffer) +unsigned int f_flags,const char *buffer) {struct mem_cgroup *memcg =mem_cgroup_from_cont (cont);int type, name;
security/device_cgroup.c +1 -1
@@ -428,7 +428,7 @@ handle: }static int devcgroup_access_write (struct cgroup *cgrp,struct cftype *cft, -const char *buffer) +unsigned int f_flags,const char *buffer) {int retval;
Signature · 1 line
1.5.6.3
Quoted 12 lines · On Mon, 26 Oct 2009 08:15:29 -0700 Matt Helsley…
cgroup subsystems may find the
O_APPENDandO_NONBLOCKflags useful in determining the way they handle writes. For now only pass these flags through thewrite_stringop.A subsequent patch will make use of the
O_NONBLOCKflag in the cgroup freezerwrite_stringop.Signed-off-by Matt Helsley <matthltc-r/[email protected]>Cc Nathan Lynch <[email protected]>Cc Paul Menage <[email protected]>Cc Li Zefan <[email protected]>
Quoted 4 lines
(Cc'ing mem controller maintainers in case they find this useful..)
Cc: Balbir Singh <[email protected]>
Cc: Pavel Emelyanov <[email protected]>
Cc: KAMEZAWA Hiroyuki <[email protected]>
Hmm, maybe useful if we decided to add memory.drop_memory or some... But now, we have no plan to add backup thread(for asynchronous job). or some trylock ops.
Anyway, no objection from me if you want this.
-Kame
Quoted 107 lines
--- include/linux/cgroup.h | 3 ++- kernel/cgroup.c | 5 +++-- kernel/cgroup_freezer.c | 5 ++--- kernel/cpuset.c | 2 +- mm/memcontrol.c | 2 +- security/device_cgroup.c | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-)include/linux/cgroup.h +2
-1@@ -315,8 +315,9 @@ struct cftype {* buffer of maximum length determined by max_write_len. * Returns 0 or -ve error code. */ +#define CFTYPE_F_FLAGS (O_APPEND|O_NONBLOCK)int (*write_string)(struct cgroup *cgrp,struct cftype *cft, -const char *buffer); +unsigned int f_flags,const char *buffer);/* * trigger() callback can be used to get some kick from the * userspace, when the actual string written is not important kernel/cgroup.c +3
-2@@ -1449,7 +1449,7 @@ bool cgroup_lock_live_group(struct cgroup *cgrp) }static int cgroup_release_agent_write (struct cgroup *cgrp,struct cftype *cft, -const char *buffer) +unsigned int f_flags,const char *buffer) {BUILD_BUG_ON (sizeof (cgrp->root->release_agent_path) <PATH_MAX );if (!cgroup_lock_live_group (cgrp))@@ -1534,7 +1534,8 @@ static ssize_t cgroup_write_string(struct cgroup *cgrp, struct cftype *cft, buffer[nbytes] =0 ;/* nul-terminate */ strstrip (buffer); - retval = cft->write_string (cgrp, cft, buffer); + retval = cft->write_string (cgrp, cft, file->f_flags &CFTYPE_F_FLAGS , + buffer);if (!retval) retval = nbytes; out:kernel/cgroup_freezer.c +2
-3@@ -343,9 +343,8 @@ out:return retval; } -static int freezer_write (struct cgroup *cgroup, -struct cftype *cft, -const char *buffer) +static int freezer_write (struct cgroup *cgroup,struct cftype *cft, +unsigned int f_flags,const char *buffer) {int retval;enum freezer_state goal_state;kernel/cpuset.c +1
-1@@ -1470,7 +1470,7 @@ static int cpuset_write_s64(struct cgroup *cgrp, struct cftype *cft, s64 val)* Common handling for a write to a "cpus" or "mems" file. */ static int cpuset_write_resmask (struct cgroup *cgrp,struct cftype *cft, -const char *buf) +unsigned int f_flags,const char *buf) {int retval =0 ;struct cpuset *cs =cgroup_cs (cgrp);mm/memcontrol.c +1
-1@@ -2072,7 +2072,7 @@ static u64 mem_cgroup_read(struct cgroup *cont, struct cftype *cft)* RES_LIMIT. */ static int mem_cgroup_write (struct cgroup *cont,struct cftype *cft, -const char *buffer) +unsigned int f_flags,const char *buffer) {struct mem_cgroup *memcg =mem_cgroup_from_cont (cont);int type, name;security/device_cgroup.c +1
-1@@ -428,7 +428,7 @@ handle: }static int devcgroup_access_write (struct cgroup *cgrp,struct cftype *cft, -const char *buffer) +unsigned int f_flags,const char *buffer) {int retval;Signature · 1 line
1.5.6.3
Quoted 20 lines · KAMEZAWA Hiroyuki
Quoted 12 lines · On Mon, 26 Oct 2009 08:15:29 -0700 Matt Helsley…
cgroup subsystems may find the
O_APPENDandO_NONBLOCKflags useful in determining the way they handle writes. For now only pass these flags through thewrite_stringop.A subsequent patch will make use of the
O_NONBLOCKflag in the cgroup freezerwrite_stringop.Signed-off-by Matt Helsley <matthltc-r/[email protected]>Cc Nathan Lynch <[email protected]>Cc Paul Menage <[email protected]>Cc Li Zefan <[email protected]>Quoted 4 lines
(Cc'ing mem controller maintainers in case they find this useful..)
Cc: Balbir Singh <[email protected]>
Cc: Pavel Emelyanov <[email protected]>
Cc: KAMEZAWA Hiroyuki <[email protected]>
Quoted 5 lines
Hmm, maybe useful if we decided to add memory.drop_memory or some... But now, we have no plan to add backup thread(for asynchronous job). or some trylock ops.
Anyway, no objection from me if you want this.
I see no issues as well, but no use at the moment right away.
Signature · 1 line
Balbir
Quoted 30 lines · Matt Helsley
cgroup subsystems may find the
O_APPENDandO_NONBLOCKflags useful in determining the way they handle writes. For now only pass these flags through thewrite_stringop.A subsequent patch will make use of the
O_NONBLOCKflag in the cgroup freezerwrite_stringop.Signed-off-by Matt Helsley <matthltc-r/[email protected]>Cc Nathan Lynch <[email protected]>Cc Paul Menage <[email protected]>Cc Li Zefan <[email protected]>(Cc'ing mem controller maintainers in case they find this useful..)
Cc: Balbir Singh <[email protected]>
Cc: Pavel Emelyanov <[email protected]>
Cc: KAMEZAWA Hiroyuki <[email protected]>--- include/linux/cgroup.h | 3 ++- kernel/cgroup.c | 5 +++-- kernel/cgroup_freezer.c | 5 ++--- kernel/cpuset.c | 2 +- mm/memcontrol.c | 2 +- security/device_cgroup.c | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-)include/linux/cgroup.h +0
-0
include/linux/cgroup.h struct cftype { · line 320
Quoted 7 lines
include/linux/cgroup.h +2
-1@@ -315,8 +315,9 @@ struct cftype {* buffer of maximum length determined by max_write_len. * Returns 0 or -ve error code. */ +#define CFTYPE_F_FLAGS (O_APPEND|O_NONBLOCK)int (*write_string)(struct cgroup *cgrp,struct cftype *cft, -const char *buffer); +unsigned int f_flags,const char *buffer);
I think maybe it's better to store struct file *file to struct cftype, so we don't need to change write_string(), write(), write_u64() and write_s64().
Quoted 3 lines
include/linux/cgroup.h +0
-0/* * trigger() callback can be used to get some kick from the * userspace, when the actual string written is not important
Quoted 4 lines · Li Zefan
I think maybe it's better to store struct file *file to struct cftype, so we don't need to change
write_string(),write(),write_u64()andwrite_s64().
We can't do that - multiple open files could be using the same cftype at the same time. I'd be inclined if necessary to just pass the struct file* in, rather than risk needing to change it to pass more parameters later.
Paul
Quoted 10 lines · Paul Menage
Quoted 4 lines · Li Zefan
I think maybe it's better to store struct file *file to struct cftype, so we don't need to change
write_string(),write(),write_u64()andwrite_s64().We can't do that - multiple open files could be using the same cftype at the same time. I'd be inclined if necessary to just pass the struct file* in, rather than risk needing to change it to pass more parameters later.
And I imagine that the number of handlers that actually make use of the cftype* is rather small. If we pass the file* to the handler instead of passing the cftype*, and provide an inline function to get from the file* to the cftype*, then we can avoid adding an extra parameter to the handlers.
Paul
Quoted 12 lines · * [email protected]…
Quoted 10 lines · Paul Menage
Quoted 4 lines · Li Zefan
I think maybe it's better to store struct file *file to struct cftype, so we don't need to change
write_string(),write(),write_u64()andwrite_s64().We can't do that - multiple open files could be using the same cftype at the same time. I'd be inclined if necessary to just pass the struct file* in, rather than risk needing to change it to pass more parameters later.
Quoted 6 lines
And I imagine that the number of handlers that actually make use of the cftype* is rather small. If we pass the file* to the handler instead of passing the cftype*, and provide an inline function to get from the file* to the cftype*, then we can avoid adding an extra parameter to the handlers.
This sounds like a reasonable approach except for the cost of indirection (which I assume is acceptable).
Signature · 1 line
Balbir
Quoted 12 lines · Paul Menage
Quoted 10 lines · Paul Menage
Quoted 4 lines · Li Zefan
I think maybe it's better to store struct file *file to struct cftype, so we don't need to change
write_string(),write(),write_u64()andwrite_s64().We can't do that - multiple open files could be using the same cftype at the same time. I'd be inclined if necessary to just pass the struct file* in, rather than risk needing to change it to pass more parameters later.
Quoted 5 lines
And I imagine that the number of handlers that actually make use of the cftype* is rather small. If we pass the file* to the handler instead of passing the cftype*, and provide an inline function to get from the file* to the cftype*, then we can avoid adding an extra parameter to the handlers.
OK, I've done this for write_string(). I named the inline function cgroup_file_cftype(). It seems that, if we do this for one, then we should do it for all of the cgroup file io ops. Agreed?
Cheers,
-Matt Helsley
Quoted 13 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
I think maybe it's better to store struct file *file to struct cftype, so we don't need to change
write_string(),write(),write_u64()andwrite_s64().We can't do that - multiple open files could be using the same cftype at the same time. I'd be inclined if necessary to just pass the struct file* in, rather than risk needing to change it to pass more parameters later.
Quoted 5 lines
And I imagine that the number of handlers that actually make use of the cftype* is rather small. If we pass the file* to the handler instead of passing the cftype*, and provide an inline function to get from the file* to the cftype*, then we can avoid adding an extra parameter to the handlers.
Quoted 4 lines
OK, I've done this for
write_string(). I named the inline functioncgroup_file_cftype(). It seems that, if we do this for one, then we should do it for all of the cgroup file io ops. Agreed?
I think so, to make interfaces consistent.
Quoted 3 lines · Matt Helsley
OK, I've done this for
write_string(). I named the inline functioncgroup_file_cftype(). It seems that, if we do this for one, then we should do it for all of the cgroup file io ops. Agreed?
Yes.
Thanks,
Paul
Quoted 21 lines · Balbir Singh
Quoted 12 lines · * [email protected]…
Quoted 10 lines · Paul Menage
Quoted 4 lines · Li Zefan
I think maybe it's better to store struct file *file to struct cftype, so we don't need to change
write_string(),write(),write_u64()andwrite_s64().We can't do that - multiple open files could be using the same cftype at the same time. I'd be inclined if necessary to just pass the struct file* in, rather than risk needing to change it to pass more parameters later.
Quoted 6 lines
And I imagine that the number of handlers that actually make use of the cftype* is rather small. If we pass the file* to the handler instead of passing the cftype*, and provide an inline function to get from the file* to the cftype*, then we can avoid adding an extra parameter to the handlers.
Quoted 2 lines
This sounds like a reasonable approach except for the cost of indirection (which I assume is acceptable).
Suprisingly few places require the struct cftype *. So they don't pay any additional cost. Note that the code in kernel/cgroup.c always fetches the op pointer by fetching and dereferencing the struct cftype *. So fetching it with an inline shouldn't add much to the data cache footprint.
The minisclue savings come in two places where struct file * was already passed.
Cheers,
-Matt Helsley