From: Frederic Weisbecker Date: Thu, 8 Dec 2011 04:42:35 +0000 (+1100) Subject: cgroups: new resource counter inheritance API X-Git-Tag: next-20111213~1^2~70 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=c234e2033d8486c8f53e4c6f9554296463e2b2d4;p=karo-tx-linux.git cgroups: new resource counter inheritance API Provide an API to inherit a counter value from a parent. This can be useful to implement cgroup.clone_children on a resource counter. Still the resources of the children are limited by those of the parent, so this is only to provide a default setting behaviour when clone_children is set. Signed-off-by: Frederic Weisbecker Cc: Paul Menage Cc: Li Zefan Cc: Johannes Weiner Cc: Aditya Kali Cc: Oleg Nesterov Cc: Kay Sievers Cc: Tim Hockin Cc: Tejun Heo Acked-by: Kirill A. Shutemov Signed-off-by: Andrew Morton --- diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h index 1b3fe058fcb1..109d1183ebf2 100644 --- a/include/linux/res_counter.h +++ b/include/linux/res_counter.h @@ -84,6 +84,8 @@ int res_counter_write(struct res_counter *counter, int member, void res_counter_write_u64(struct res_counter *counter, int member, u64 val); +void res_counter_inherit(struct res_counter *counter, int member); + /* * the field descriptors. one for each member of res_counter */ diff --git a/kernel/res_counter.c b/kernel/res_counter.c index 0faafccbb80e..37abf4eda9ad 100644 --- a/kernel/res_counter.c +++ b/kernel/res_counter.c @@ -202,3 +202,21 @@ int res_counter_write(struct res_counter *counter, int member, return 0; } + +/* + * Simple inheritance implementation to get the same value + * than a parent. However this doesn't enforce the child value + * to be always below the one of the parent. But the child is + * subject to its parent limitation anyway. + */ +void res_counter_inherit(struct res_counter *counter, int member) +{ + struct res_counter *parent; + unsigned long long val; + + parent = counter->parent; + if (parent) { + val = res_counter_read_u64(parent, member); + res_counter_write_u64(counter, member, val); + } +}