Skip to contentSkip to conversation

Resource Groups... formerly CKRM

PATCH New Chandra Seetharaman 1 participant 13 messages Apr 28, 2006

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover Resource Groups... formerly CKRM

Andrew,

CKRM has gone through a major overhaul by removing some of the complexity, cutting down on features and moving portions to userspace.

We have posted ckrm last week as an RFC:
infrastructure:

	http://www.ussg.iu.edu/hypermail/linux/kernel/0604.2/1297.html
numtasks controller:
	http://www.ussg.iu.edu/hypermail/linux/kernel/0604.2/1311.html
CPU controller:
	http://www.ussg.iu.edu/hypermail/linux/kernel/0604.2/1310.html

Diffstat of this patchset (including the numtasks controller that follows) is:

	23 files changed, 2466 insertions(+), 5 deletions(-)

including Documentaion and comments.

This patchset will be followed with two controllers:
- a simple controller, numtasks to control number of tasks
- CPU controller, to control CPU resource.

Please consider these for inclusion in -mm tree.
--

Changes since last post:
- CKRM has been replaced with Resource Groups
- 'class' has been replaced with resource group
- Limit the depth of the hierarchy.

---------
Patch Descriptions:

01/12 - controller_support

This patch defines data structures for defining a resource group and resource controller.
Provides register/unregister functions for a controller. Provides utility functions to get a controller's data structure.

02/12 - resource_group_support

Provides functions to alloc and free a user defined resource group. Provides utility macro to walk through the resource group hierarchy.

03/12 - shares_support

Provides functions to set/get shares of a specific resource of a resource group.
Defines a teardown function that is intended to be called when user disables resource group (by umount of the configfs component).

04/12 - tasksupport

Adds logic to support adding/removing task to/from a resource group Provides interface to set a task's resource group.

05/12 - tasksupport_fork_exit_init

Initializes and clears Resource Group specific information in a task at fork() and exit(). Inititalizes Resource Groups (called from start_kernel)

06/12: task_procsupport

Adds an interface in /proc to get the name of a resource group to which a task is attached.

07/12 - user_interface

Create the configfs component for managing Resource groups. Hooks up with configfs. Provides functions for creating and deleting resource groups.

08/12 - user_interface_attr_support

Adds the basic attribute store and show functions.

09/12 - user_interface_stats

Adds attr_store and attr_show support for stats file.

10/12 - user_interface_shares

Adds attr_store and attr_show support for shares file.

11/12 - user_interface_members

Adds attr_store and attr_show support for members file.

12/12 - res_groups_docs

Documentation describing important Resource Groups components such as resource group, shares, controllers, and the configfs based user interface. --
Thanks & Regards,

chandra

Signature · 4 lines
----------------------------------------------------------------------
    Chandra Seetharaman               | Be careful what you choose....
              - [email protected]   |      .......you may get it.
----------------------------------------------------------------------
#1 lore raw

PATCH 1/12 Register/Unregister interface for Controllers

01/12 - controller_support

This patch defines data structures for defining a resource group and resource controller.
Provides register/unregister functions for a controller. Provides utility functions to get a controller's data structure. --

 include/linux/res_group.h    |   75 +++++++++++++++
 include/linux/res_group_rc.h |   68 +++++++++++++
 init/Kconfig                 |   14 ++
 kernel/Makefile              |    1 
 kernel/res_group/Makefile    |    1 
 kernel/res_group/local.h     |   10 ++
 kernel/res_group/res_group.c |  214 +++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 383 insertions(+)
include/linux/res_group.h new file +75 -0
Index: linux-2617-rc3/include/linux/res_group.h
===================================================================
@@ -0,0 +1,75 @@
+/*
+ *  res_group.h - Header file to be used by Resource Groups
+ *
+ * Copyright (C) Hubertus Franke, IBM Corp. 2003, 2004
+ *		(C) Shailabh Nagar,  IBM Corp. 2003, 2004
+ *		(C) Chandra Seetharaman, IBM Corp. 2003, 2004, 2005
+ *
+ * Provides data structures, macros and kernel APIs
+ *
+ * More details at http://ckrm.sf.net
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ */
+
+#ifndef _LINUX_RES_GROUP_H
+#define _LINUX_RES_GROUP_H
+
+#ifdef CONFIG_RES_GROUPS
+#include <linux/spinlock.h>
+#include <linux/list.h>
+#include <linux/kref.h>
+
+#define SHARE_UNCHANGED	(-1)	/* implicitly specified by userspace,
+					 * never stored in a resource group'
+					 * shares struct; never displayed */
+#define SHARE_UNSUPPORTED	(-2)	/* If the resource controller doesn't
+					 * support user changing a shares value
+					 * it sets the corresponding share
+					 * value to UNSUPPORTED when it returns
+					 * the newly allocated shares data
+					 * structure */
+#define SHARE_DONT_CARE	(-3)
+
+#define SHARE_DEFAULT_DIVISOR 	(100)
+
+#define MAX_RES_CTLRS	8	/* max # of resource controllers */
+
+#define NO_RES_GROUP		NULL
+#define NO_SHARE		NULL
+#define NO_RES_ID		MAX_RES_CTLRS /* Invalid ID */
+
+/*
+ * Share quantities are a child's fraction of the parent's resource
+ * specified by a divisor in the parent and a dividend in the child.
+ *
+ * Shares are represented as a relative quantity between parent and child
+ * to simplify locking when propagating modifications to the shares of a
+ * resource group. Only the parent and the children of the modified
+ * resource group need to be locked.
+*/
+struct res_shares {
+};
+
+/*
+ * Class is the grouping of tasks with shares of each resource that has
+ * registered a resource controller (see include/linux/res_group_rc.h).
+ */
+struct resource_group {
+	int depth;		/* depth of this resource group. root == 0 */
+	spinlock_t group_lock;	/* protects task_list, shares and children
+				 * When grabbing group_lock in a hierarchy,
+				 * grab parent's group_lock first.
+				 * If resource controller uses a resource_group
+				 * specific lock, grab group_lock before
+				 * grabbing resource specific lock */
+	struct res_shares *shares[MAX_RES_CTLRS];/* resource shares */
+	struct list_head group_list;	/* entry in system-wide list */
+};
+
+#endif /* CONFIG_RES_GROUPS */
+#endif /* _LINUX_RES_GROUP_H */
include/linux/res_group_rc.h new file +68 -0

68 lines not on this page · raw message

kernel/res_group/res_group.c new file +214 -0

214 lines not on this page · raw message

kernel/Makefile +1 -0
Index: linux-2617-rc3/kernel/Makefile
===================================================================
@@ -38,6 +38,7 @@ obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
 obj-$(CONFIG_SECCOMP) += seccomp.o
 obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o
 obj-$(CONFIG_RELAY) += relay.o
+obj-$(CONFIG_RES_GROUPS) += res_group/
 
 ifneq ($(CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER),y)
 # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
kernel/res_group/Makefile new file +1 -0
Index: linux-2617-rc3/kernel/res_group/Makefile
===================================================================
@@ -0,0 +1 @@
+obj-y = res_group.o
init/Kconfig +14 -0
Index: linux-2617-rc3/init/Kconfig
===================================================================
@@ -150,6 +150,20 @@ config BSD_PROCESS_ACCT_V3
 	  for processing it. A preliminary version of these tools is available
 	  at <http://www.physik3.uni-rostock.de/tim/kernel/utils/acct/>.
 
+menu "Resource Groups"
+
+config RES_GROUPS
+	bool "Resource Groups"
+	depends on EXPERIMENTAL
+	help
+	  Resource Groups is a framework for controlling and monitoring
+	  resource allocation of user-defined groups of tasks. For more
+	  information, please visit http://ckrm.sf.net.
+
+	  If you say Y here, enable the Resource Group File System and at least
+	  one of the resource controllers below. Say N if you are unsure.
+
+endmenu
 config SYSCTL
 	bool "Sysctl support"
 	---help---
kernel/res_group/local.h new file +10 -0
Index: linux-2617-rc3/kernel/res_group/local.h
===================================================================
@@ -0,0 +1,10 @@
+/*
+ * Contains function definitions that are local to the Resource Groups.
+ * NOT to be included by controllers.
+ */
+
+#include <linux/res_group_rc.h>
+
+extern struct res_controller *get_controller_by_name(const char *);
+extern struct res_controller *get_controller_by_id(unsigned int);
+extern void put_controller(struct res_controller *);
Signature · 4 lines
----------------------------------------------------------------------
    Chandra Seetharaman               | Be careful what you choose....
              - [email protected]   |      .......you may get it.
----------------------------------------------------------------------
#2 lore raw

PATCH 2/12 Resource group creation/deletion

In reply to Chandra Seetharaman

02/12 - resource_group_support

Provides functions to alloc and free a user defined resource group. Provides utility macro to walk through the resource group hierarchy. --

 include/linux/res_group.h    |    9 ++
 include/linux/res_group_rc.h |    9 ++
 kernel/res_group/local.h     |    4 +
 kernel/res_group/res_group.c |  167 +++++++++++++++++++++++++++++++++++++++----
 4 files changed, 176 insertions(+), 13 deletions(-)
include/linux/res_group.h +9 -0
Index: linux-2617-rc3/include/linux/res_group.h
===================================================================
@@ -38,6 +38,7 @@
 #define SHARE_DEFAULT_DIVISOR 	(100)
 
 #define MAX_RES_CTLRS	8	/* max # of resource controllers */
+#define MAX_DEPTH	5	/* max depth of hierarchy supported */
 
 #define NO_RES_GROUP		NULL
 #define NO_SHARE		NULL
@@ -60,6 +61,8 @@ struct res_shares {
  * registered a resource controller (see include/linux/res_group_rc.h).
  */
 struct resource_group {
+	const char *name;
+	struct kref ref;
 	int depth;		/* depth of this resource group. root == 0 */
 	spinlock_t group_lock;	/* protects task_list, shares and children
 				 * When grabbing group_lock in a hierarchy,
@@ -69,6 +72,12 @@ struct resource_group {
 				 * grabbing resource specific lock */
 	struct res_shares *shares[MAX_RES_CTLRS];/* resource shares */
 	struct list_head group_list;	/* entry in system-wide list */
+
+	struct list_head task_list;	/* this resource groups's tasks */
+
+	struct resource_group *parent;
+	struct list_head siblings;	/* entry in list of siblings */
+	struct list_head children;	/* head of children */
 };
 
 #endif /* CONFIG_RES_GROUPS */
kernel/res_group/res_group.c +154 -13

224 lines not on this page · raw message

include/linux/res_group_rc.h +9 -0
Index: linux-2617-rc3/include/linux/res_group_rc.h
===================================================================
@@ -65,4 +65,13 @@ struct res_controller {
 
 extern int register_controller(struct res_controller *);
 extern int unregister_controller(struct res_controller *);
+extern struct resource_group default_res_group;
+static inline int is_res_group_root(const struct resource_group *rgroup)
+{
+	return (rgroup == &default_res_group);
+}
+
+#define for_each_child(child, parent)	\
+	list_for_each_entry(child, &parent->children, siblings)
+
 #endif /* _LINUX_RES_GROUP_RC_H */
kernel/res_group/local.h +4 -0
Index: linux-2617-rc3/kernel/res_group/local.h
===================================================================
@@ -8,3 +8,7 @@
 extern struct res_controller *get_controller_by_name(const char *);
 extern struct res_controller *get_controller_by_id(unsigned int);
 extern void put_controller(struct res_controller *);
+extern struct resource_group *alloc_res_group(struct resource_group *,
+							const char *);
+extern int free_res_group(struct resource_group *);
+extern void release_res_group(struct kref *);
Signature · 4 lines
----------------------------------------------------------------------
    Chandra Seetharaman               | Be careful what you choose....
              - [email protected]   |      .......you may get it.
----------------------------------------------------------------------
#3 lore raw

PATCH 3/12 Share Handling

In reply to Chandra Seetharaman

03/12 - shares_support

Provides functions to set/get shares of a specific resource of a resource group.
Defines a teardown function that is intended to be called when user disables resource group (by umount of the configfs component). --

 include/linux/res_group.h    |   14 ++
 include/linux/res_group_rc.h |   10 +
 kernel/res_group/Makefile    |    2 
 kernel/res_group/local.h     |    6 +
 kernel/res_group/res_group.c |   24 ++++
 kernel/res_group/shares.c    |  242 +++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 297 insertions(+), 1 deletion(-)
include/linux/res_group.h +14 -0
Index: linux-2617-rc3/include/linux/res_group.h
===================================================================
@@ -54,6 +54,20 @@
  * resource group need to be locked.
 */
 struct res_shares {
+	/* shares only set by userspace */
+	int min_shares; /* minimun fraction of parent's resources allowed */
+	int max_shares; /* maximum fraction of parent's resources allowed */
+	int child_shares_divisor; /* >= 1, may not be DONT_CARE */
+
+	/*
+	 * share values invisible to userspace.  adjusted when userspace
+	 * sets shares
+	 */
+	int unused_min_shares;
+		/* 0 <= unused_min_shares <= (child_shares_divisor -
+		 * 			Sum of min_shares of children)
+		 */
+	int cur_max_shares; /* max(children's max_shares). need better name */
 };
 
 /*
kernel/res_group/shares.c new file +242 -0

242 lines not on this page · raw message

kernel/res_group/Makefile +1 -1
Index: linux-2617-rc3/kernel/res_group/Makefile
===================================================================
@@ -1 +1 @@
-obj-y = res_group.o
+obj-y = res_group.o shares.o
kernel/res_group/res_group.c +24 -0
Index: linux-2617-rc3/kernel/res_group/res_group.c
===================================================================
@@ -173,6 +173,8 @@ static void do_free_shares_struct(struct
 	if (shares == NULL)
 		return;
 
+	set_shares_to_default(rgroup, ctlr);
+
 	spin_lock(&rgroup->group_lock);
 	rgroup->shares[ctlr->ctlr_id] = NULL;
 	spin_unlock(&rgroup->group_lock);
@@ -345,6 +347,26 @@ int unregister_controller(struct res_con
 	return remove_controller(ctlr);
 }
 
+/*
+ * Bring the state of Resource Groups to the initial state. Only shares
+ * of the default resource group need to be changed to default values.
+ * At this point no user-defined resource groups should exist.
+ */
+void res_group_teardown(void)
+{
+	int i;
+	struct res_controller *ctlr;
+
+	BUG_ON(num_res_groups != 0);
+	for (i = 0; i < MAX_RES_CTLRS; i++) {
+		ctlr = get_controller_by_id(i);
+		if (ctlr) {
+			set_shares_to_default(&default_res_group, ctlr);
+			put_controller(ctlr);
+		}
+	}
+}
+
 EXPORT_SYMBOL_GPL(register_controller);
 EXPORT_SYMBOL_GPL(unregister_controller);
 EXPORT_SYMBOL_GPL(get_controller_by_name);
@@ -353,3 +375,5 @@ EXPORT_SYMBOL_GPL(put_controller);
 EXPORT_SYMBOL_GPL(alloc_res_group);
 EXPORT_SYMBOL_GPL(free_res_group);
 EXPORT_SYMBOL_GPL(default_res_group);
+EXPORT_SYMBOL_GPL(set_controller_shares);
+EXPORT_SYMBOL_GPL(res_group_teardown);
include/linux/res_group_rc.h +10 -0
Index: linux-2617-rc3/include/linux/res_group_rc.h
===================================================================
@@ -74,4 +74,14 @@ static inline int is_res_group_root(cons
 #define for_each_child(child, parent)	\
 	list_for_each_entry(child, &parent->children, siblings)
 
+/* Get controller specific shares structure for the given resource group */
+static inline struct res_shares *get_controller_shares(
+		struct resource_group *rgroup, struct res_controller *ctlr)
+{
+	if (rgroup && ctlr)
+		return rgroup->shares[ctlr->ctlr_id];
+	else
+		return NO_SHARE;
+}
+
 #endif /* _LINUX_RES_GROUP_RC_H */
kernel/res_group/local.h +6 -0
Index: linux-2617-rc3/kernel/res_group/local.h
===================================================================
@@ -12,3 +12,9 @@ extern struct resource_group *alloc_res_
 							const char *);
 extern int free_res_group(struct resource_group *);
 extern void release_res_group(struct kref *);
+extern int set_controller_shares(struct resource_group *,
+			struct res_controller *, const struct res_shares *);
+/* Set shares for the given resource group and resource to default values */
+extern void set_shares_to_default(struct resource_group *,
+						struct res_controller *);
+extern void res_group_teardown(void);
Signature · 4 lines
----------------------------------------------------------------------
    Chandra Seetharaman               | Be careful what you choose....
              - [email protected]   |      .......you may get it.
----------------------------------------------------------------------
#6 lore raw

PATCH 6/12 Add proc interface to get resource group info of task

In reply to Chandra Seetharaman

06/12: task_procsupport

Adds an interface in /proc to get the name of a resource group to which a task is attached.
--

 fs/proc/base.c            |   19 +++++++++++++++++++
 include/linux/res_group.h |    2 ++
 kernel/res_group/task.c   |   32 +++++++++++++++++++++++++++++++-
 3 files changed, 52 insertions(+), 1 deletion(-)
fs/proc/base.c +19 -0
Index: linux-2617-rc3/fs/proc/base.c
===================================================================
@@ -70,6 +70,7 @@
 #include <linux/ptrace.h>
 #include <linux/seccomp.h>
 #include <linux/cpuset.h>
+#include <linux/res_group.h>
 #include <linux/audit.h>
 #include <linux/poll.h>
 #include "internal.h"
@@ -115,6 +116,9 @@ enum pid_directory_inos {
 #ifdef CONFIG_CPUSETS
 	PROC_TGID_CPUSET,
 #endif
+#ifdef CONFIG_RES_GROUPS
+	PROC_TGID_RES_GROUP,
+#endif
 #ifdef CONFIG_SECURITY
 	PROC_TGID_ATTR,
 	PROC_TGID_ATTR_CURRENT,
@@ -156,6 +160,9 @@ enum pid_directory_inos {
 #ifdef CONFIG_CPUSETS
 	PROC_TID_CPUSET,
 #endif
+#ifdef CONFIG_RES_GROUPS
+	PROC_TID_RES_GROUP,
+#endif
 #ifdef CONFIG_SECURITY
 	PROC_TID_ATTR,
 	PROC_TID_ATTR_CURRENT,
@@ -219,6 +226,9 @@ static struct pid_entry tgid_base_stuff[
 #ifdef CONFIG_CPUSETS
 	E(PROC_TGID_CPUSET,    "cpuset",  S_IFREG|S_IRUGO),
 #endif
+#ifdef CONFIG_RES_GROUPS
+	E(PROC_TGID_RES_GROUP,"res_group",S_IFREG|S_IRUGO),
+#endif
 	E(PROC_TGID_OOM_SCORE, "oom_score",S_IFREG|S_IRUGO),
 	E(PROC_TGID_OOM_ADJUST,"oom_adj", S_IFREG|S_IRUGO|S_IWUSR),
 #ifdef CONFIG_AUDITSYSCALL
@@ -261,6 +271,9 @@ static struct pid_entry tid_base_stuff[]
 #ifdef CONFIG_CPUSETS
 	E(PROC_TID_CPUSET,     "cpuset",  S_IFREG|S_IRUGO),
 #endif
+#ifdef CONFIG_RES_GROUPS
+	E(PROC_TID_RES_GROUP, "res_group",S_IFREG|S_IRUGO),
+#endif
 	E(PROC_TID_OOM_SCORE,  "oom_score",S_IFREG|S_IRUGO),
 	E(PROC_TID_OOM_ADJUST, "oom_adj", S_IFREG|S_IRUGO|S_IWUSR),
 #ifdef CONFIG_AUDITSYSCALL
@@ -1823,6 +1836,12 @@ static struct dentry *proc_pident_lookup
 			inode->i_fop = &proc_cpuset_operations;
 			break;
 #endif
+#ifdef CONFIG_RES_GROUPS
+		case PROC_TID_RES_GROUP:
+		case PROC_TGID_RES_GROUP:
+			inode->i_fop = &proc_res_group_operations;
+			break;
+#endif
 		case PROC_TID_OOM_SCORE:
 		case PROC_TGID_OOM_SCORE:
 			inode->i_fop = &proc_info_file_operations;
kernel/res_group/task.c +31 -1
Index: linux-2617-rc3/kernel/res_group/task.c
===================================================================
@@ -13,7 +13,8 @@
  * (at your option) any later version.
  *
  */
-#include <linux/sched.h>
+#include <linux/seq_file.h>
+#include <linux/proc_fs.h>
 #include <linux/module.h>
 #include "local.h"
 
@@ -194,4 +195,33 @@ next_task:
 	kref_put(&rgroup->ref, release_res_group);
 }
 
+static int proc_res_group_show(struct seq_file *m, void *v)
+{
+	struct task_struct *tsk = m->private;
+	struct resource_group *rgroup = tsk->res_group;
+
+	if (!rgroup)
+		return -EINVAL;
+
+	kref_get(&rgroup->ref);
+	seq_puts(m, "/");
+	if (!is_res_group_root(rgroup))
+		seq_puts(m, rgroup->name);
+	seq_putc(m, '\n');
+	kref_put(&rgroup->ref, release_res_group);
+	return 0;
+}
+
+static int res_group_open(struct inode *inode, struct file *file)
+{
+	struct task_struct *tsk = PROC_I(inode)->task;
+	return single_open(file, proc_res_group_show, tsk);
+}
+
+struct file_operations proc_res_group_operations = {
+	.open		= res_group_open,
+	.read		= seq_read,
+	.llseek 	= seq_lseek,
+	.release	= single_release,
+};
 EXPORT_SYMBOL_GPL(set_res_group);
include/linux/res_group.h +2 -0
Index: linux-2617-rc3/include/linux/res_group.h
===================================================================
@@ -94,6 +94,8 @@ struct resource_group {
 	struct list_head children;	/* head of children */
 };
 
+extern struct file_operations proc_res_group_operations;
+
 extern void init_task_res_group(struct task_struct *);
 extern void clear_task_res_group(struct task_struct *);
 extern void res_group_init(void);
Signature · 4 lines
----------------------------------------------------------------------
    Chandra Seetharaman               | Be careful what you choose....
              - [email protected]   |      .......you may get it.
----------------------------------------------------------------------
#4 lore raw

PATCH 4/12 Add task logic to resource groups

In reply to Chandra Seetharaman

04/12 - tasksupport

Adds logic to support adding/removing task to/from a resource group Provides interface to set a task's resource group.
--

 include/linux/sched.h        |    4 +
 kernel/res_group/Makefile    |    2 
 kernel/res_group/local.h     |    1 
 kernel/res_group/res_group.c |   25 +++++++
 kernel/res_group/task.c      |  145 +++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 176 insertions(+), 1 deletion(-)
include/linux/sched.h +4 -0
Index: linux-2617-rc3/include/linux/sched.h
===================================================================
@@ -888,6 +888,10 @@ struct task_struct {
 	 * cache last used pipe for splice
 	 */
 	struct pipe_inode_info *splice_pipe;
+#ifdef CONFIG_RES_GROUPS
+	struct resource_group *res_group;
+	struct list_head member_list; /* list of tasks in the resource group */
+#endif /* CONFIG_RES_GROUPS */
 };
 
 static inline pid_t process_group(struct task_struct *tsk)
kernel/res_group/task.c new file +145 -0

145 lines not on this page · raw message

kernel/res_group/Makefile +1 -1
Index: linux-2617-rc3/kernel/res_group/Makefile
===================================================================
@@ -1 +1 @@
-obj-y = res_group.o shares.o
+obj-y = res_group.o shares.o task.o
kernel/res_group/res_group.c +25 -0
Index: linux-2617-rc3/kernel/res_group/res_group.c
===================================================================
@@ -251,6 +251,27 @@ static int add_controller(struct res_con
 	return ret;
 }
 /*
+ * Helper function to move all tasks in a resource group to/from the
+ * registering/unregistering resource controller.
+ *
+ * Assumes ctlr is valid and rgroup is initialized with resource
+ * controller's shares.
+ */
+static void move_tasks(struct resource_group *rgroup,
+		struct res_controller *ctlr,
+		struct res_shares *from, struct res_shares *to)
+{
+	struct task_struct *tsk;
+
+	if (!ctlr->move_task)
+		return;
+	spin_lock(&rgroup->group_lock);
+	list_for_each_entry(tsk, &rgroup->task_list, member_list)
+		ctlr->move_task(tsk, from, to);
+	spin_unlock(&rgroup->group_lock);
+}
+
+/*
  * Interface for registering a resource controller.
  *
  * Returns the 0 on success, -errno for failure.
@@ -287,6 +308,8 @@ int register_controller(struct res_contr
 		kref_get(&rgroup->ref);
 		read_unlock(&res_group_lock);
   		do_alloc_shares_struct(rgroup, ctlr);
+		move_tasks(rgroup, ctlr, NO_SHARE,
+					rgroup->shares[ctlr->ctlr_id]);
 		if (prev_rgroup)
 			kref_put(&prev_rgroup->ref, release_res_group);
 		prev_rgroup = rgroup;
@@ -333,6 +356,8 @@ int unregister_controller(struct res_con
 	list_for_each_entry_reverse(rgroup, &res_groups, group_list) {
 		kref_get(&rgroup->ref);
 		read_unlock(&res_group_lock);
+		move_tasks(rgroup, ctlr, rgroup->shares[ctlr->ctlr_id],
+								NO_SHARE);
   		do_free_shares_struct(rgroup, ctlr);
 		if (prev_rgroup)
 			kref_put(&prev_rgroup->ref, release_res_group);
kernel/res_group/local.h +1 -0
Index: linux-2617-rc3/kernel/res_group/local.h
===================================================================
@@ -18,3 +18,4 @@ extern int set_controller_shares(struct 
 extern void set_shares_to_default(struct resource_group *,
 						struct res_controller *);
 extern void res_group_teardown(void);
+extern int set_res_group(pid_t, struct resource_group *);
Signature · 4 lines
----------------------------------------------------------------------
    Chandra Seetharaman               | Be careful what you choose....
              - [email protected]   |      .......you may get it.
----------------------------------------------------------------------
#7 lore raw

PATCH 7/12 Resource Groups Configfs Subsystem (RGCS)

In reply to Chandra Seetharaman

07/12 - user_interface

Create the configfs component for managing Resource groups. Hooks up with configfs. Provides functions for creating and deleting resource groups. --

 init/Kconfig              |   12 +++
 kernel/res_group/Makefile |    1 
 kernel/res_group/rgcs.c   |  162 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 175 insertions(+)
init/Kconfig +12 -0
Index: linux-2617-rc3/init/Kconfig
===================================================================
@@ -163,6 +163,18 @@ config RES_GROUPS
 	  If you say Y here, enable the Resource Group File System and at least
 	  one of the resource controllers below. Say N if you are unsure.
 
+config RGCS
+	tristate "Resource Groups Configfs Subsystem"
+	depends on RES_GROUPS
+	select CONFIGFS_FS
+	default m
+	help
+	  RGCS is the User Interface for Resource Groups. Compiling it as
+	  a module permits users to only load RGCS if they intend to use it.
+
+	  Say M if unsure, Y to save on module loading. N doesn't make sense
+	  when Resource Groups has been configured.
+
 endmenu
 config SYSCTL
 	bool "Sysctl support"
kernel/res_group/rgcs.c new file +162 -0

162 lines not on this page · raw message

kernel/res_group/Makefile +1 -0
Index: linux-2617-rc3/kernel/res_group/Makefile
===================================================================
@@ -1 +1,2 @@
 obj-y = res_group.o shares.o task.o
+obj-$(CONFIG_RGCS) += rgcs.o
Signature · 4 lines
----------------------------------------------------------------------
    Chandra Seetharaman               | Be careful what you choose....
              - [email protected]   |      .......you may get it.
----------------------------------------------------------------------
#8 lore raw

PATCH 8/12 Add attribute support to RGCS

In reply to Chandra Seetharaman

08/12 - user_interface_attr_support

Adds the basic attribute store and show functions. --

 rgcs.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 52 insertions(+), 1 deletion(-)
kernel/res_group/rgcs.c +52 -1
Index: linux-2617-rc3/kernel/res_group/rgcs.c
===================================================================
@@ -14,13 +14,21 @@
  * as published by the Free Software Foundation.
  *
  */
+#include <linux/ctype.h>
 #include <linux/module.h>
 #include <linux/configfs.h>
+#include <linux/parser.h>
 #include "local.h"
 
 static struct configfs_subsystem rgcs_subsys;
 static struct config_item_type rgcs_item_type;
 
+struct rgroup_attribute {
+	struct configfs_attribute configfs_attr;
+	ssize_t (*show)(struct resource_group *, char *);
+	int (*store)(struct resource_group *, const char *);
+};
+
 struct rgcs_rgroup {
 	char *name;
 	struct resource_group *core;
@@ -58,6 +66,42 @@ static inline struct resource_group *ite
 	return group_to_res_group(to_config_group(item));
 }
 
+static ssize_t rgcs_attr_show(struct config_item *item,
+	      		      struct configfs_attribute *attr, char *buf)
+{
+	struct rgroup_attribute *rgroup_attr;
+	struct resource_group *rgroup = item_to_res_group(item);
+
+	rgroup_attr = container_of(attr, struct rgroup_attribute,
+							configfs_attr);
+	return rgroup_attr->show(rgroup, buf);
+}
+
+static ssize_t rgcs_attr_store(struct config_item *item,
+		       struct configfs_attribute *attr, const char *buf,
+		       size_t count)
+{
+	char *filtered_buf, *p;
+	ssize_t rc;
+	struct rgroup_attribute *rgroup_attr;
+	struct resource_group *rgroup = item_to_res_group(item);
+
+	rgroup_attr = container_of(attr, struct rgroup_attribute,
+							configfs_attr);
+	filtered_buf = kzalloc(count + 1, GFP_KERNEL);
+	if (!filtered_buf)
+		return -ENOMEM;
+	strncpy(filtered_buf, buf, count);
+	for (p = filtered_buf; isprint(*p); ++p)
+		;
+	*p = '\0';
+	rc = rgroup_attr->store(rgroup, filtered_buf);
+	kfree(filtered_buf);
+	if (rc)
+		return rc;
+	return count;
+}
+
 /*
  * This is the function that is called when a 'mkdir' command
  * is issued under our filesystem
@@ -119,17 +163,24 @@ static void rgcs_rgroup_release_item(str
 }
 
 static struct configfs_item_operations rgcs_rgroup_item_ops = {
-	.release	= rgcs_rgroup_release_item,
+	.release		= rgcs_rgroup_release_item,
+	.show_attribute		= rgcs_attr_show,
+	.store_attribute	= rgcs_attr_store,
 };
 
 static struct configfs_group_operations rgcs_rgroup_group_ops = {
 	.make_group     = make_rgcs_rgroup,
 };
 
+static struct configfs_attribute *rgroup_attrs[] = {
+	NULL
+};
+
 static struct config_item_type rgcs_item_type = {
 	.ct_owner	= THIS_MODULE,
 	.ct_item_ops    = &rgcs_rgroup_item_ops,
 	.ct_group_ops	= &rgcs_rgroup_group_ops,
+	.ct_attrs       = rgroup_attrs
 };
 
 static struct configfs_subsystem rgcs_subsys = {
Signature · 4 lines
----------------------------------------------------------------------
    Chandra Seetharaman               | Be careful what you choose....
              - [email protected]   |      .......you may get it.
----------------------------------------------------------------------
#9 lore raw

PATCH 9/12 Add stats file support to RGCS

In reply to Chandra Seetharaman

09/12 - user_interface_stats

Adds attr_store and attr_show support for stats file. --

 rgcs.c |  112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 110 insertions(+), 2 deletions(-)
kernel/res_group/rgcs.c +110 -2
Index: linux-2617-rc3/kernel/res_group/rgcs.c
===================================================================
@@ -20,8 +20,102 @@
 #include <linux/parser.h>
 #include "local.h"
 
-static struct configfs_subsystem rgcs_subsys;
-static struct config_item_type rgcs_item_type;
+#define RES_STRING "res"
+
+static ssize_t show_stats(struct resource_group *rgroup, char *buf)
+{
+	int i, j = 0, rc = 0;
+	size_t buf_size = PAGE_SIZE-1; /* allow only PAGE_SIZE # of bytes */
+	struct res_controller *ctlr;
+	struct res_shares *shares;
+
+	for (i = 0; i < MAX_RES_CTLRS; i++, j = 0) {
+		if (buf_size <= 0)
+			break;
+		ctlr = get_controller_by_id(i);
+		if (!ctlr)
+			 continue;
+		shares = get_controller_shares(rgroup, ctlr);
+		if (shares && ctlr->show_stats)
+			j = ctlr->show_stats(shares, buf, buf_size);
+		put_controller(ctlr);
+		rc += j;
+		buf += j;
+		buf_size -= j;
+	}
+	if (i < MAX_RES_CTLRS)
+		rc = -ENOSPC;
+	return rc;
+}
+
+enum parse_token_t {
+	parse_res_type, parse_err
+};
+
+static match_table_t parse_tokens = {
+	{parse_res_type, RES_STRING"=%s"},
+	{parse_err, NULL}
+};
+
+static int stats_parse(const char *options,
+				char **resname, char **remaining_line)
+{
+	char *p, *str;
+	int rc = -EINVAL;
+
+	if (!options)
+		return -EINVAL;
+
+	while ((p = strsep((char **)&options, ",")) != NULL) {
+		substring_t args[MAX_OPT_ARGS];
+		int token;
+
+		if (!*p)
+			continue;
+		token = match_token(p, parse_tokens, args);
+		if (token == parse_res_type) {
+			*resname = match_strdup(args);
+			str = p + strlen(p) + 1;
+			*remaining_line = kmalloc(strlen(str) + 1, GFP_KERNEL);
+			if (*remaining_line == NULL) {
+				kfree(*resname);
+				*resname = NULL;
+				rc = -ENOMEM;
+			} else {
+				strcpy(*remaining_line, str);
+				rc = 0;
+			}
+			break;
+		}
+	}
+	return rc;
+}
+
+static int reset_stats(struct resource_group *rgroup, const char *str)
+{
+	int rc;
+	char *resname = NULL, *statstr = NULL;
+	struct res_controller *ctlr;
+	struct res_shares *shares;
+
+	rc = stats_parse(str, &resname, &statstr);
+	if (rc)
+		return rc;
+
+	ctlr = get_controller_by_name(resname);
+	if (!ctlr) {
+		rc = -EINVAL;
+		goto done;
+	}
+	shares = get_controller_shares(rgroup, ctlr);
+	if (shares && ctlr->reset_stats)
+		rc = ctlr->reset_stats(shares, statstr);
+	put_controller(ctlr);
+done:
+	kfree(resname);
+	kfree(statstr);
+	return rc;
+}
 
 struct rgroup_attribute {
 	struct configfs_attribute configfs_attr;
@@ -29,6 +123,19 @@ struct rgroup_attribute {
 	int (*store)(struct resource_group *, const char *);
 };
 
+struct rgroup_attribute stats_attr = {
+	.configfs_attr = {
+		.ca_name = "stats",
+		.ca_owner = THIS_MODULE,
+		.ca_mode = S_IRUGO | S_IWUSR
+	},
+	.show = show_stats,
+	.store = reset_stats
+};
+
+static struct configfs_subsystem rgcs_subsys;
+static struct config_item_type rgcs_item_type;
+
 struct rgcs_rgroup {
 	char *name;
 	struct resource_group *core;
@@ -173,6 +280,7 @@ static struct configfs_group_operations 
 };
 
 static struct configfs_attribute *rgroup_attrs[] = {
+	&stats_attr.configfs_attr,
 	NULL
 };
 
Signature · 4 lines
----------------------------------------------------------------------
    Chandra Seetharaman               | Be careful what you choose....
              - [email protected]   |      .......you may get it.
----------------------------------------------------------------------
#10 lore raw

PATCH 10/12 Add shares file support to RGCS

In reply to Chandra Seetharaman

10/12 - user_interface_shares

Adds attr_store and attr_show support for shares file. --

 rgcs.c |  136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 136 insertions(+)
kernel/res_group/rgcs.c +136 -0
Index: linux-2617-rc3/kernel/res_group/rgcs.c
===================================================================
@@ -21,6 +21,9 @@
 #include "local.h"
 
 #define RES_STRING "res"
+#define MIN_SHARES_STRING "min_shares"
+#define MAX_SHARES_STRING "max_shares"
+#define CHILD_SHARES_DIVISOR_STRING "child_shares_divisor"
 
 static ssize_t show_stats(struct resource_group *rgroup, char *buf)
 {
@@ -117,6 +120,128 @@ done:
 	return rc;
 }
 
+
+enum share_token_t {
+	MIN_SHARES_TOKEN,
+	MAX_SHARES_TOKEN,
+	CHILD_SHARES_DIVISOR_TOKEN,
+	RESOURCE_TYPE_TOKEN,
+	ERROR_TOKEN
+};
+
+/* Token matching for parsing input to this magic file */
+static match_table_t shares_tokens = {
+	{RESOURCE_TYPE_TOKEN, RES_STRING"=%s"},
+	{MIN_SHARES_TOKEN, MIN_SHARES_STRING"=%d"},
+	{MAX_SHARES_TOKEN, MAX_SHARES_STRING"=%d"},
+	{CHILD_SHARES_DIVISOR_TOKEN, CHILD_SHARES_DIVISOR_STRING"=%d"},
+	{ERROR_TOKEN, NULL}
+};
+
+static int shares_parse(const char *options, char **resname,
+					struct res_shares *shares)
+{
+	char *p;
+	int option, rc = -EINVAL;
+
+	*resname = NULL;
+	if (!options)
+		goto done;
+	while ((p = strsep((char **)&options, ",")) != NULL) {
+		substring_t args[MAX_OPT_ARGS];
+		int token;
+
+		if (!*p)
+			continue;
+		token = match_token(p, shares_tokens, args);
+		switch (token) {
+		case RESOURCE_TYPE_TOKEN:
+			if (*resname)
+				goto done;
+			*resname = match_strdup(args);
+			break;
+		case MIN_SHARES_TOKEN:
+			if (match_int(args, &option))
+				goto done;
+			shares->min_shares = option;
+			break;
+		case MAX_SHARES_TOKEN:
+			if (match_int(args, &option))
+				goto done;
+			shares->max_shares = option;
+			break;
+		case CHILD_SHARES_DIVISOR_TOKEN:
+			if (match_int(args, &option))
+				goto done;
+			shares->child_shares_divisor = option;
+			break;
+		default:
+			goto done;
+		}
+	}
+	rc = 0;
+done:
+	if (rc) {
+		kfree(*resname);
+		*resname = NULL;
+	}
+	return rc;
+}
+
+static int set_shares(struct resource_group *rgroup, const char *str)
+{
+	char *resname = NULL;
+	int rc;
+	struct res_controller *ctlr;
+	struct res_shares shares = {
+		.min_shares = SHARE_UNCHANGED,
+		.max_shares = SHARE_UNCHANGED,
+		.child_shares_divisor = SHARE_UNCHANGED,
+	};
+
+	rc = shares_parse(str, &resname, &shares);
+	if (!rc) {
+		ctlr = get_controller_by_name(resname);
+		if (ctlr) {
+			rc = set_controller_shares(rgroup, ctlr, &shares);
+			put_controller(ctlr);
+		} else
+			rc = -EINVAL;
+		kfree(resname);
+	}
+	return rc;
+}
+
+static ssize_t show_shares(struct resource_group *rgroup, char *buf)
+{
+	int i;
+	ssize_t j, rc = 0, bufsize = PAGE_SIZE;
+	struct res_shares *shares;
+	struct res_controller *ctlr;
+
+	for (i = 0; i < MAX_RES_CTLRS; i++) {
+		ctlr = get_controller_by_id(i);
+		if (!ctlr)
+			continue;
+		shares = get_controller_shares(rgroup, ctlr);
+		if (shares) {
+			if (bufsize <= 0)
+				break;
+			j = snprintf(buf, bufsize, "%s=%s,%s=%d,%s=%d,%s=%d\n",
+				RES_STRING, ctlr->name,
+				MIN_SHARES_STRING, shares->min_shares,
+				MAX_SHARES_STRING, shares->max_shares,
+				CHILD_SHARES_DIVISOR_STRING,
+				shares->child_shares_divisor);
+			rc += j; buf += j; bufsize -= j;
+		}
+		put_controller(ctlr);
+	}
+	if (i < MAX_RES_CTLRS)
+		rc = -ENOSPC;
+	return rc;
+}
+
 struct rgroup_attribute {
 	struct configfs_attribute configfs_attr;
 	ssize_t (*show)(struct resource_group *, char *);
@@ -133,6 +258,16 @@ struct rgroup_attribute stats_attr = {
 	.store = reset_stats
 };
 
+struct rgroup_attribute shares_attr = {
+	.configfs_attr = {
+		.ca_name = "shares",
+		.ca_owner = THIS_MODULE,
+		.ca_mode = S_IRUGO | S_IWUSR
+	},
+	.show = show_shares,
+	.store = set_shares
+};
+
 static struct configfs_subsystem rgcs_subsys;
 static struct config_item_type rgcs_item_type;
 
@@ -281,6 +416,7 @@ static struct configfs_group_operations 
 
 static struct configfs_attribute *rgroup_attrs[] = {
 	&stats_attr.configfs_attr,
+	&shares_attr.configfs_attr,
 	NULL
 };
 
Signature · 4 lines
----------------------------------------------------------------------
    Chandra Seetharaman               | Be careful what you choose....
              - [email protected]   |      .......you may get it.
----------------------------------------------------------------------
#11 lore raw

PATCH 11/12 Add members file support to RGCS

In reply to Chandra Seetharaman

11/12 - user_interface_members

Adds attr_store and attr_show support for members file. --

 rgcs.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+)
kernel/res_group/rgcs.c +49 -0
Index: linux-2617-rc3/kernel/res_group/rgcs.c
===================================================================
@@ -242,6 +242,43 @@ static ssize_t show_shares(struct resour
 	return rc;
 }
 
+/*
+ * Given a buffer with a pid in it, add the task with that pid to the
+ * resource group. Ignores entire buffer after the first pid is parsed.
+ */
+static int add_member(struct resource_group *rgroup, const char *str)
+{
+	pid_t pid;
+
+	pid = (pid_t) simple_strtol(str, NULL, 0);
+	if (pid <= 0)
+		return -EINVAL; /* Not a valid pid */
+	return set_res_group(pid, rgroup);
+}
+
+/*
+ * Lists pids of tasks that belong to the given rgroup.
+ */
+static ssize_t show_members(struct resource_group *rgroup, char *buf)
+{
+	ssize_t i, rc = 0, bufsize = PAGE_SIZE;
+	struct task_struct *tsk;
+
+	spin_lock(&rgroup->group_lock);
+	list_for_each_entry(tsk, &rgroup->task_list, member_list) {
+		if (bufsize <= 0) {
+			rc = -ENOSPC;
+			break;
+		}
+		if (!tsk->pid)	/* Ignore swappers */
+			continue;
+		i = snprintf(buf, bufsize, "%ld\n", (long)tsk->pid);
+		buf += i; rc += i; bufsize -= i;
+	}
+	spin_unlock(&rgroup->group_lock);
+	return rc;
+}
+
 struct rgroup_attribute {
 	struct configfs_attribute configfs_attr;
 	ssize_t (*show)(struct resource_group *, char *);
@@ -268,6 +305,17 @@ struct rgroup_attribute shares_attr = {
 	.store = set_shares
 };
 
+struct rgroup_attribute members_attr = {
+	.configfs_attr = {
+		.ca_name = "members",
+		.ca_owner = THIS_MODULE,
+		.ca_mode = S_IRUGO | S_IWUSR
+	},
+	.show = show_members,
+	.store = add_member
+};
+
+
 static struct configfs_subsystem rgcs_subsys;
 static struct config_item_type rgcs_item_type;
 
@@ -417,6 +465,7 @@ static struct configfs_group_operations 
 static struct configfs_attribute *rgroup_attrs[] = {
 	&stats_attr.configfs_attr,
 	&shares_attr.configfs_attr,
+	&members_attr.configfs_attr,
 	NULL
 };
 
Signature · 4 lines
----------------------------------------------------------------------
    Chandra Seetharaman               | Be careful what you choose....
              - [email protected]   |      .......you may get it.
----------------------------------------------------------------------
#12 lore raw

PATCH 12/12 Documentation for Resource Groups

In reply to Chandra Seetharaman

12/12 - res_groups_docs

Documentation describing important Resource Groups components such as resource group, shares, controllers, and the configfs based user interface. --

 res_groups_basics  |   71 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 res_groups_install |   29 +++++++++++++++++++++
 res_groups_usage   |   53 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 153 insertions(+)
Documentation/res_groups/res_groups_basics new file +71 -0
Index: linux-2617-rc3/Documentation/res_groups/res_groups_basics
===================================================================
@@ -0,0 +1,71 @@
+Resource Groups Basics
+-------------
+A brief review of Resoruce Groups concepts and terminology will help make
+installation and testing easier. For more details, please visit
+http://ckrm.sf.net.
+
+Concept:
+User defines a resource group, attaches some amount of resources to
+the resource group, and associates tasks with that resource group. Tasks
+belonging to that resource group will be bound by the amount of resource
+that is assigned to that group.
+
+User interface for the Resource Groups is through configfs. Resource group
+is depicted as as a directory. Hierarchy of resource groups can be
+created in which children of a resource group share resources allotted to
+the parent. Tasks can be attached to any resource group which is at any level.
+There is no correlation between parent-child relationship of tasks and
+the parent-child relationship of the resource groups they belong to.
+
+During fork(), resource group is inherited by a task. A privileged user can
+reassign a task to any resource group.
+
+Characteristics of a resource group can be accessed/changed through the
+following files under the directory representing the resource group:
+
+shares:  allows changing shares of different resources managed by the
+         resource group
+stats:   shows statistics associated with each resources managed by the
+         resource group
+members: allows assignment of tasks to a resource group and shows tasks
+         that are assigned to a resource group.
+
+Resource allocations of a resource group is resource group to the amount
+of resources available to the resource group's parent.
+Resource allocations for a resource group is controlled by the parameters:
+
+min_shares: Minimum amount shares that can be allocated by a resource group. A
+            special value of DONT_CARE(-3) means that there is no minimum
+	    shares of a resource is specified. This resource group may not get
+	    any resource if the system is running short on resources.
+max_shares: Specifies the maximum amount of resource that is allowed to be
+           allocated by a resource group. A special value DONT_CARE(-3) mean
+	   that there is no specific limit is specified, this resource group
+	   can get all the resources available.
+child_shares_divisor: total guarantee that is allowed among the children of
+           this resource group. In other words, the sum of "guarantee"s of all
+	   children of this resource group cannot exit this number.
+
+Any of these parameter can have a special value, UNSUPPORTED(-2) meaning
+that the specific controller does not support this parameter. User's
+request to change the value will be ignored.
+
+None of this parameters neither absolute nor have any units associated with
+them. These are just numbers that are used to calculate the absolute number
+of resource available for a specific resource group.
+
+Absolute amount of minimum shares available for a resource group is
+calculuated as:
+
+	absolute minimum shares = (parent's absolute amount of resource) *
+		(resource group's min_shares / parent's child_shares_divisor)
+
+Maximum shares is also calculated in the same way.
+
+Root resource group is allocated all the resources available in the system.
+In other words absolute amount of resource available for the root resource
+group is same as that of what is available in the system.
+
+min_shares and max_shares are related to the parent, these values on
+the root resource group have no effect. Similarly, child_shares_divisor
+is related to children, and hence it has no effect on leaf resource groups.
Documentation/res_groups/res_groups_install new file +29 -0
Index: linux-2617-rc3/Documentation/res_groups/res_groups_install
===================================================================
@@ -0,0 +1,29 @@
+1. Configure
+
+Select appropriate configuration options:
+
+   Enable configfs filesystem:
+   File systems --->
+     Pseudo filesystems --->
+       <M> Userspace-driven configuration filesystem (EXPERIMENTAL)
+
+   Enable Resource Group components:
+   General Setup --->
+     Resource Groups --->
+        [*] Resource Groups
+        <M> Resource Groups Configfs Subsystem (User API)
+        [*]     Number of Tasks Resource Manager
+
+
+2. Build, boot the kernel
+
+3. Enable rgcs
+
+    # insmod <patchestree>/fs/configfs/configfs.ko # if compiled as module
+    # insmod <patchedtree>/kernel/res_config/rgcs.ko # if compiled in as module
+    # mount -t configfs none /config
+
+    This will create the directory /config/res_groups which is the root of
+    classes.
+
+4. Work with class hierarchy as explained in the file res_groups_usage
Documentation/res_groups/res_groups_usage new file +53 -0

53 lines not on this page · raw message

Signature · 4 lines
----------------------------------------------------------------------
    Chandra Seetharaman               | Be careful what you choose....
              - [email protected]   |      .......you may get it.
----------------------------------------------------------------------
#5 lore raw

PATCH 5/12 Init and clear resource group info in task

In reply to Chandra Seetharaman

05/12 - tasksupport_fork_exit_init

Initializes and clears Resource Group specific information in a task at fork() and exit().
Inititalizes Resource Groups (called from start_kernel)
--

 include/linux/res_group.h    |    7 +++++
 init/main.c                  |    2 +
 kernel/exit.c                |    2 +
 kernel/fork.c                |    2 +
 kernel/res_group/local.h     |    1 
 kernel/res_group/res_group.c |   11 +++++++++
 kernel/res_group/task.c      |   52 +++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 77 insertions(+)
kernel/exit.c +2 -0
Index: linux-2617-rc3/kernel/exit.c
===================================================================
@@ -35,6 +35,7 @@
 #include <linux/futex.h>
 #include <linux/compat.h>
 #include <linux/pipe_fs_i.h>
+#include <linux/res_group.h>
 
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
@@ -731,6 +732,7 @@ static void exit_notify(struct task_stru
 	struct task_struct *t;
 	struct list_head ptrace_dead, *_p, *_n;
 
+	clear_task_res_group(tsk);
 	if (signal_pending(tsk) && !(tsk->signal->flags & SIGNAL_GROUP_EXIT)
 	    && !thread_group_empty(tsk)) {
 		/*
kernel/fork.c +2 -0
Index: linux-2617-rc3/kernel/fork.c
===================================================================
@@ -44,6 +44,7 @@
 #include <linux/rmap.h>
 #include <linux/acct.h>
 #include <linux/cn_proc.h>
+#include <linux/res_group.h>
 
 #include <asm/pgtable.h>
 #include <asm/pgalloc.h>
@@ -1215,6 +1216,7 @@ static task_t *copy_process(unsigned lon
 	total_forks++;
 	spin_unlock(&current->sighand->siglock);
 	write_unlock_irq(&tasklist_lock);
+	init_task_res_group(p);
 	proc_fork_connector(p);
 	return p;
 
init/main.c +2 -0
Index: linux-2617-rc3/init/main.c
===================================================================
@@ -47,6 +47,7 @@
 #include <linux/rmap.h>
 #include <linux/mempolicy.h>
 #include <linux/key.h>
+#include <linux/res_group.h>
 
 #include <asm/io.h>
 #include <asm/bugs.h>
@@ -541,6 +542,7 @@ asmlinkage void __init start_kernel(void
 	proc_root_init();
 #endif
 	cpuset_init();
+	res_group_init();
 
 	check_bugs();
 
kernel/res_group/res_group.c +11 -0
Index: linux-2617-rc3/kernel/res_group/res_group.c
===================================================================
@@ -231,6 +231,7 @@ int free_res_group(struct resource_group
 		return -EBUSY;
 	}
 	spin_unlock(&rgroup->group_lock);
+	move_tasks_to_parent(rgroup);
 	kref_put(&rgroup->ref, release_res_group);
 	return 0;
 }
@@ -392,6 +393,16 @@ void res_group_teardown(void)
 	}
 }
 
+void res_group_init(void)
+{
+	write_lock(&res_group_lock);
+	list_add_tail(&default_res_group.group_list, &res_groups);
+	write_unlock(&res_group_lock);
+	kref_init(&default_res_group.ref);
+	init_task.res_group = &default_res_group;
+	init_task_res_group(&init_task);
+}
+
 EXPORT_SYMBOL_GPL(register_controller);
 EXPORT_SYMBOL_GPL(unregister_controller);
 EXPORT_SYMBOL_GPL(get_controller_by_name);
kernel/res_group/task.c +52 -0

56 lines not on this page · raw message

include/linux/res_group.h +7 -0
Index: linux-2617-rc3/include/linux/res_group.h
===================================================================
@@ -94,5 +94,12 @@ struct resource_group {
 	struct list_head children;	/* head of children */
 };
 
+extern void init_task_res_group(struct task_struct *);
+extern void clear_task_res_group(struct task_struct *);
+extern void res_group_init(void);
+#else /* CONFIG_RES_GROUPS */
+static inline void init_task_res_group(struct task_struct *tsk) { }
+static inline void clear_task_res_group(struct task_struct *tsk) { }
+static inline void res_group_init(void) { }
 #endif /* CONFIG_RES_GROUPS */
 #endif /* _LINUX_RES_GROUP_H */
kernel/res_group/local.h +1 -0
Index: linux-2617-rc3/kernel/res_group/local.h
===================================================================
@@ -19,3 +19,4 @@ extern void set_shares_to_default(struct
 						struct res_controller *);
 extern void res_group_teardown(void);
 extern int set_res_group(pid_t, struct resource_group *);
+extern void move_tasks_to_parent(struct resource_group *);
Signature · 4 lines
----------------------------------------------------------------------
    Chandra Seetharaman               | Be careful what you choose....
              - [email protected]   |      .......you may get it.
----------------------------------------------------------------------