[PATCH -mm 2/6] introduce struct res_counter_ratelimit

Previous thread: [PATCH -mm 1/6] i/o controller documentation by Andrea Righi on Wednesday, September 17, 2008 - 4:05 am. (1 message)

Next thread: [PATCH -mm 3/6] i/o controller infrastructure by Andrea Righi on Wednesday, September 17, 2008 - 4:05 am. (1 message)
From: Andrea Righi
Date: Wednesday, September 17, 2008 - 4:05 am

Introduce res_counter_ratelimit as a generic structure to implement
throttling-based cgroup subsystems.

[ Only the interfaces needed by the IO controller are implemented right now ]

Signed-off-by: Andrea Righi <righi.andrea@gmail.com>
---
 include/linux/res_counter.h |   70 +++++++++++++++++++++++++
 kernel/res_counter.c        |  118 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 187 insertions(+), 1 deletions(-)

diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h
index 0ab55c4..ff677d9 100644
--- a/include/linux/res_counter.h
+++ b/include/linux/res_counter.h
@@ -14,6 +14,7 @@
  */
 
 #include <linux/cgroup.h>
+#include <linux/jiffies.h>
 
 /*
  * The core object. the cgroup that wishes to account for some
@@ -45,6 +46,38 @@ struct res_counter {
 	spinlock_t lock;
 };
 
+/* The various policies that can be used for throttling */
+#define	RATELIMIT_LEAKY_BUCKET	0
+#define	RATELIMIT_TOKEN_BUCKET	1
+
+struct res_counter_ratelimit {
+	/*
+	 * the current resource consumption level
+	 */
+	unsigned long long usage;
+	/*
+	 * the maximal value of the usage from the counter creation
+	 */
+	unsigned long long max_usage;
+	/*
+	 * the rate limit that cannot be exceeded
+	 */
+	unsigned long long limit;
+	/*
+	 * the limiting policy / algorithm
+	 */
+	unsigned long long policy;
+	/*
+	 * timestamp of the last accounted resource request
+	 */
+	unsigned long long timestamp;
+	/*
+	 * the lock to protect all of the above.
+	 * the routines below consider this to be IRQ-safe
+	 */
+	spinlock_t lock;
+};
+
 /**
  * Helpers to interact with userspace
  * res_counter_read_u64() - returns the value of the specified member.
@@ -60,10 +93,17 @@ struct res_counter {
 
 u64 res_counter_read_u64(struct res_counter *counter, int member);
 
+u64 res_counter_ratelimit_read_u64(struct res_counter_ratelimit *counter,
+				int member);
+
 ssize_t res_counter_read(struct res_counter *counter, int member,
 		const char __user ...
From: Randy Dunlap
Date: Friday, September 19, 2008 - 10:08 am

With such nice struct comments, it looks like you should convert them
to kernel-doc for structs.  See Documentation/kernel-doc-nano-HOWTO.txt
for into, or ask me if you need some help with it.

Thanks,
---
~Randy
--

From: Andrea Righi
Date: Friday, September 19, 2008 - 1:32 pm

Sure! I will do for the next version. Actually, I'm already using the kernel-doc
style in other parts of this patchset (i.e. to document iothrottle structures).

Thanks!
-Andrea
--

From: Paul Menage
Date: Sunday, October 5, 2008 - 11:03 am

Hi Andrea,

The principle seems useful, but you seem to be duplicating a lot of
the existing res_counter code.

Could you not either:

- include these two extra fields in res_counter?
- include res_counter as the first field in a res_counter_ratelimit?

Paul

--

From: Andrea Righi
Date: Monday, October 6, 2008 - 1:03 am

The second solution would save some space if the "ratelimit" part is not used.
Anyway, I'll try to rewrite it to reuse as much code as possible and post a new
patchset.

Thanks for looking into it.

-Andrea
--

From: Paul Menage
Date: Monday, October 6, 2008 - 10:14 am

Having a "policy" field in res_counter seems like it might be reusable
as something for other non-ratelimited res_counters. And even if it's
not, the memory overhead of a couple of extra fields in a res_counter
is trivial compared to the overhead of resource isolation anyway.

So my first approach to this would be just extend res_counter, and
then split them apart later if it turns out that they really do need
mutually incompatible code/handlers.

Paul
--

From: Balbir Singh
Date: Monday, October 6, 2008 - 10:20 am

Yes! I agree

-- 
	Balbir
--

From: Andrea Righi
Date: Monday, October 6, 2008 - 12:38 pm

Good! I'll go for this.

Thanks,
-Andrea
--

Previous thread: [PATCH -mm 1/6] i/o controller documentation by Andrea Righi on Wednesday, September 17, 2008 - 4:05 am. (1 message)

Next thread: [PATCH -mm 3/6] i/o controller infrastructure by Andrea Righi on Wednesday, September 17, 2008 - 4:05 am. (1 message)