Re: [PATCH 02/10] cgroups: New resource counter inheritance API

From: Kirill A. Shutemov
Date: Mon Oct 03 2011 - 20:20:27 EST


On Mon, Oct 03, 2011 at 09:07:04PM +0200, Frederic Weisbecker wrote:
> 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 <fweisbec@xxxxxxxxx>

Acked-by: Kirill A. Shutemov <kirill@xxxxxxxxxxxxx>

> Cc: Paul Menage <paul@xxxxxxxxxxxxxx>
> Cc: Li Zefan <lizf@xxxxxxxxxxxxxx>
> Cc: Johannes Weiner <hannes@xxxxxxxxxxx>
> Cc: Aditya Kali <adityakali@xxxxxxxxxx>
> Cc: Oleg Nesterov <oleg@xxxxxxxxxx>
> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Cc: Kay Sievers <kay.sievers@xxxxxxxx>
> Cc: Tim Hockin <thockin@xxxxxxxxxx>
> Cc: Tejun Heo <tj@xxxxxxxxxx>
> Cc: Kirill A. Shutemov <kirill@xxxxxxxxxxxxx>
> Cc: Containers <containers@xxxxxxxxxxxxxxxxxxxxxxxxxx>
> ---
> include/linux/res_counter.h | 2 ++
> kernel/res_counter.c | 18 ++++++++++++++++++
> 2 files changed, 20 insertions(+), 0 deletions(-)
>
> diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h
> index 1b3fe05..109d118 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 0faafcc..37abf4e 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);
> + }
> +}
> --
> 1.7.5.4
>

--
Kirill A. Shutemov
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/