From: Frederic Weisbecker <fweisbec@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
Paul Menage <menage@google.com>, Li Zefan <lizf@cn.fujitsu.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [RFC PATCH 3/4] cgroups: New resource counter inheritance API
Date: Mon, 20 Jun 2011 01:51:13 +0200 [thread overview]
Message-ID: <1308527474-20704-4-git-send-email-fweisbec@gmail.com> (raw)
In-Reply-To: <1308527474-20704-1-git-send-email-fweisbec@gmail.com>
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@gmail.com>
Cc: Paul Menage <menage@google.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
include/linux/res_counter.h | 2 ++
kernel/res_counter.c | 25 +++++++++++++++++++++++++
2 files changed, 27 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 806d041..8cb0362 100644
--- a/kernel/res_counter.c
+++ b/kernel/res_counter.c
@@ -198,3 +198,28 @@ int res_counter_write(struct res_counter *counter, int member,
return 0;
}
+
+void res_counter_inherit(struct res_counter *counter, int member)
+{
+ struct res_counter *parent;
+ unsigned long long *pval, val;
+ unsigned long flags;
+
+ parent = counter->parent;
+ if (!parent)
+ return;
+
+ local_irq_save(flags);
+
+ spin_lock(&counter->lock);
+ pval = res_counter_member(counter, member);
+ val = *pval;
+ spin_unlock(&counter->lock);
+
+ spin_lock(&parent->lock);
+ pval = res_counter_member(parent, member);
+ *pval = val;
+ spin_unlock(&parent->lock);
+
+ local_irq_restore(flags);
+}
--
1.7.5.4
next prev parent reply other threads:[~2011-06-19 23:51 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-19 23:51 [RFC PATCH 0/4] cgroups: Start a basic rlimit subsystem Frederic Weisbecker
2011-06-19 23:51 ` [RFC PATCH 1/4] cgroups: Allow a cgroup subsys to reject a fork Frederic Weisbecker
2011-06-21 17:39 ` Paul Menage
2011-06-23 13:38 ` Frederic Weisbecker
2011-06-19 23:51 ` [RFC PATCH 2/4] cgroups: Add res_counter_write_u64() API Frederic Weisbecker
2011-06-19 23:51 ` Frederic Weisbecker [this message]
2011-06-19 23:51 ` [RFC PATCH 4/4] cgroups: Add an rlimit subsystem Frederic Weisbecker
2011-06-21 17:37 ` Paul Menage
2011-06-23 13:48 ` Frederic Weisbecker
2011-06-24 22:22 ` Paul Menage
2011-06-28 17:37 ` Aditya Kali
2011-07-06 0:21 ` Frederic Weisbecker
2011-06-28 18:08 ` Aditya Kali
2011-07-06 0:43 ` Frederic Weisbecker
2011-06-20 6:33 ` [RFC PATCH 0/4] cgroups: Start a basic " Li Zefan
2011-06-20 19:11 ` Frederic Weisbecker
2011-06-21 8:09 ` Li Zefan
2011-06-21 16:18 ` Frederic Weisbecker
2011-06-21 17:08 ` Paul Menage
2011-06-23 13:30 ` Frederic Weisbecker
2011-06-24 22:18 ` Paul Menage
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1308527474-20704-4-git-send-email-fweisbec@gmail.com \
--to=fweisbec@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizf@cn.fujitsu.com \
--cc=menage@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox