From: Dwight Engen Subject: [PATCH 2/9] cgroups: new resource counter inheritance API Date: Thu, 12 Dec 2013 16:35:11 -0500 Message-ID: <1386884118-14972-3-git-send-email-dwight.engen@oracle.com> References: <1386884118-14972-1-git-send-email-dwight.engen@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1386884118-14972-1-git-send-email-dwight.engen-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org To: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Cc: Frederic Weisbecker , Max Kellermann List-Id: containers.vger.kernel.org From: Frederic Weisbecker 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: Tim Hockin Cc: Tejun Heo Cc: Containers Cc: Glauber Costa Cc: Cgroups Cc: Daniel J Walsh Cc: "Daniel P. Berrange" Cc: KAMEZAWA Hiroyuki Cc: Max Kellermann Cc: Mandeep Singh Baines Acked-by: Kirill A. Shutemov Signed-off-by: Andrew Morton --- include/linux/res_counter.h | 2 ++ kernel/res_counter.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h index eb78440..92b9e18 100644 --- a/include/linux/res_counter.h +++ b/include/linux/res_counter.h @@ -80,6 +80,8 @@ int res_counter_memparse_write_strategy(const char *buf, 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 673a7a6..6174478 100644 --- a/kernel/res_counter.c +++ b/kernel/res_counter.c @@ -219,3 +219,21 @@ int res_counter_memparse_write_strategy(const char *buf, 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); + } +} -- 1.8.3.1