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 ...