From: Li Zefan <lizf@cn.fujitsu.com>
To: Paul Menage <menage@google.com>
Cc: balbir@linux.vnet.ibm.com, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, containers@lists.linux-foundation.org,
kamezawa.hiroyu@jp.fujitsu.com
Subject: Re: [PATCH 8/9] [RFC] Example multi-bindable subsystem: a per-cgroup notes field
Date: Fri, 03 Jul 2009 16:58:03 +0800 [thread overview]
Message-ID: <4A4DC81B.3050608@cn.fujitsu.com> (raw)
In-Reply-To: <20090702021133.14469.35140.stgit@menage.mtv.corp.google.com>
Paul Menage wrote:
> [RFC] Example multi-bindable subsystem: a per-cgroup notes field
>
> As an example of a multiply-bindable subsystem, this patch introduces
> the "info" subsystem, which provides a single file, "info.notes", in
> which user-space middleware can store an arbitrary (by default up to
> one page) binary string representing configuration data about that
> cgroup. This reduces the need to keep additional state outside the
> cgroup filesystem. The maximum notes size for a hierarchy can be set
> by updating the "info.size" file in the root cgroup.
>
> Signed-off-by: Paul Menage <menage@google.com>
>
> ---
>
> include/linux/cgroup_subsys.h | 6 ++
> init/Kconfig | 9 +++
> kernel/Makefile | 1
> kernel/info_cgroup.c | 133 +++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 149 insertions(+), 0 deletions(-)
> create mode 100644 kernel/info_cgroup.c
>
> diff --git a/include/linux/cgroup_subsys.h b/include/linux/cgroup_subsys.h
> index f78605e..5dfea38 100644
> --- a/include/linux/cgroup_subsys.h
> +++ b/include/linux/cgroup_subsys.h
> @@ -60,3 +60,9 @@ SUBSYS(net_cls)
> #endif
>
> /* */
> +
> +#ifdef CONFIG_CGROUP_INFO
> +MULTI_SUBSYS(info)
> +#endif
> +
> +/* */
> diff --git a/init/Kconfig b/init/Kconfig
> index d904d6c..3bd4685 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -604,6 +604,15 @@ config CGROUP_MEM_RES_CTLR_SWAP
> Now, memory usage of swap_cgroup is 2 bytes per entry. If swap page
> size is 4096bytes, 512k per 1Gbytes of swap.
>
> +config CGROUP_INFO
> + bool "Simple application-specific info cgroup subsystem"
> + depends on CGROUPS
> + help
> + Provides a simple cgroups subsystem with an "info.notes"
> + field, which can be used by middleware to store
> + application-specific configuration data about a cgroup. Can
> + be mounted on multiple hierarchies at once.
> +
> endif # CGROUPS
>
> config MM_OWNER
> diff --git a/kernel/Makefile b/kernel/Makefile
> index 7ffdc16..e713a67 100644
> --- a/kernel/Makefile
> +++ b/kernel/Makefile
> @@ -61,6 +61,7 @@ obj-$(CONFIG_CGROUPS) += cgroup.o
> obj-$(CONFIG_CGROUP_FREEZER) += cgroup_freezer.o
> obj-$(CONFIG_CPUSETS) += cpuset.o
> obj-$(CONFIG_CGROUP_NS) += ns_cgroup.o
> +obj-$(CONFIG_CGROUP_INFO) += info_cgroup.o
> obj-$(CONFIG_UTS_NS) += utsname.o
> obj-$(CONFIG_USER_NS) += user_namespace.o
> obj-$(CONFIG_PID_NS) += pid_namespace.o
> diff --git a/kernel/info_cgroup.c b/kernel/info_cgroup.c
> new file mode 100644
> index 0000000..34cfdb8
> --- /dev/null
> +++ b/kernel/info_cgroup.c
> @@ -0,0 +1,133 @@
> +/*
> + * info_cgroup.c - simple cgroup providing a "notes" field
> + */
> +
> +#include "linux/cgroup.h"
> +#include "linux/err.h"
> +#include "linux/seq_file.h"
> +
#include <linux/xxx>
And I got compile error, because of missing
#include <linux/uaccess.h>
> +struct info_cgroup {
> + struct cgroup_subsys_state css;
> + /* notes string for this cgroup */
> + const char *notes;
> + size_t len;
> + /*
> + * size limit for notes in this hierarchy. Only relevant for
> + * the root cgroup. Not synchronized since it's a single word
> + * value and writes to it never depend on previously read
> + * values.
> + */
> + size_t max_len;
If it's not per cgroup, it can be a global value.
But why not make it per cgroup?
> + spinlock_t lock;
> +};
> +
> +static inline struct info_cgroup *cg_info(struct cgroup *cg)
> +{
> + return container_of(cgroup_subsys_state(cg, info_subsys_id),
> + struct info_cgroup, css);
> +}
> +
> +static struct cgroup_subsys_state *info_create(struct cgroup_subsys *ss,
> + struct cgroup *cg)
> +{
> + struct info_cgroup *info = kzalloc(sizeof(*info), GFP_KERNEL);
newline needed
> + if (!info)
> + return ERR_PTR(-ENOMEM);
> + spin_lock_init(&info->lock);
> + if (!cg->parent)
> + info->max_len = PAGE_SIZE;
> + return &info->css;
> +}
> +
> +static void info_destroy(struct cgroup_subsys *ss, struct cgroup *cont)
> +{
> + struct info_cgroup *css = cg_info(cont);
newline needed
> + kfree(css->notes);
> + kfree(css);
> +}
> +
> +
> +static int info_read(struct cgroup *cont,
> + struct cftype *cft,
> + struct seq_file *seq)
> +{
> + struct info_cgroup *css = cg_info(cont);
newline needed
> + spin_lock(&css->lock);
> + if (css->notes)
> + seq_write(seq, css->notes, css->len);
> + spin_unlock(&css->lock);
> + return 0;
> +}
> +
> +/*
> + * Use a custom write function so that we can handle binary data
> + */
> +
> +static ssize_t info_write(struct cgroup *cgrp, struct cftype *cft,
> + struct file *file,
> + const char __user *userbuf,
> + size_t nbytes, loff_t *unused_ppos) {
> + struct info_cgroup *css = cg_info(cgrp);
> + char *notes = NULL;
newline needed
> + if (nbytes > cg_info(cgrp->top_cgroup)->max_len)
> + return -E2BIG;
> + if (nbytes) {
> + notes = kmalloc(nbytes, GFP_USER);
> + if (!notes)
> + return -ENOMEM;
> + if (copy_from_user(notes, userbuf, nbytes))
missing kfree(notes)
> + return -EFAULT;
> + }
> +
> + spin_lock(&css->lock);
> + kfree(css->notes);
> + css->notes = notes;
> + css->len = nbytes;
> + spin_unlock(&css->lock);
> + return nbytes;
> +}
> +
> +static u64 notes_size_read(struct cgroup *cont, struct cftype *cft)
> +{
> + struct info_cgroup *css = cg_info(cont);
> + return css->max_len;
> +}
> +
> +static int notes_size_write(struct cgroup *cont, struct cftype *cft, u64 val)
> +{
> + struct info_cgroup *css = cg_info(cont);
> + css->max_len = val;
> + return 0;
> +}
> +
> +static struct cftype info_files[] = {
> + {
> + .name = "notes",
> + .read_seq_string = info_read,
> + .write = info_write,
> + },
> +};
> +
> +static struct cftype info_root_files[] = {
> + {
> + .name = "size",
> + .read_u64 = notes_size_read,
> + .write_u64 = notes_size_write,
> + },
> +};
> +
> +static int info_populate(struct cgroup_subsys *ss, struct cgroup *cont)
> +{
> + if (!cont->parent)
> + cgroup_add_files(cont, ss, info_root_files,
> + ARRAY_SIZE(info_root_files));
> + return cgroup_add_files(cont, ss, info_files, ARRAY_SIZE(info_files));
> +}
> +
> +struct cgroup_subsys info_subsys = {
> + .name = "info",
> + .create = info_create,
> + .destroy = info_destroy,
> + .populate = info_populate,
> + .subsys_id = info_subsys_id,
> +};
>
>
>
next prev parent reply other threads:[~2009-07-03 8:57 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-02 2:10 [PATCH 0/9] [RFC] CGroup Hierarchy Extensions Paul Menage
2009-07-02 2:11 ` [PATCH 5/9] [RFC] Remove cgroup_subsys.root pointer Paul Menage
[not found] ` <20090702021118.14469.2107.stgit-u3IScbYxn0zHt/MElyovVYaSKrA+ACpX0E9HWUfgJXw@public.gmane.org>
2009-07-02 9:04 ` Louis Rilling
2009-07-02 9:04 ` Louis Rilling
2009-07-02 9:32 ` Paul Menage
2009-07-02 9:32 ` Paul Menage
2009-07-02 2:11 ` [PATCH 8/9] [RFC] Example multi-bindable subsystem: a per-cgroup notes field Paul Menage
[not found] ` <20090702021133.14469.35140.stgit-u3IScbYxn0zHt/MElyovVYaSKrA+ACpX0E9HWUfgJXw@public.gmane.org>
2009-07-02 2:48 ` KAMEZAWA Hiroyuki
2009-07-02 2:48 ` KAMEZAWA Hiroyuki
2009-07-02 2:56 ` Paul Menage
2009-07-02 3:17 ` KAMEZAWA Hiroyuki
[not found] ` <6599ad830907011956i33769d5ek5401e93553d75c59-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-02 3:17 ` KAMEZAWA Hiroyuki
2009-07-02 7:22 ` Paul Menage
2009-07-02 7:22 ` Paul Menage
[not found] ` <20090702114829.df04c885.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2009-07-02 2:56 ` Paul Menage
2009-07-03 8:58 ` Li Zefan
2009-07-03 8:58 ` Li Zefan [this message]
2009-07-14 0:49 ` Paul Menage
[not found] ` <4A4DC81B.3050608-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2009-07-14 0:49 ` Paul Menage
[not found] ` <20090702020624.14469.47066.stgit-u3IScbYxn0zHt/MElyovVYaSKrA+ACpX0E9HWUfgJXw@public.gmane.org>
2009-07-02 2:10 ` [PATCH 1/9] [RFC] Support named cgroups hierarchies Paul Menage
2009-07-02 2:10 ` Paul Menage
2009-07-02 2:28 ` KAMEZAWA Hiroyuki
[not found] ` <20090702112814.ddf0c280.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2009-07-02 2:49 ` Paul Menage
2009-07-02 2:49 ` Paul Menage
2009-07-03 1:51 ` Li Zefan
[not found] ` <6599ad830907011949h13598e36m45b85ae76900b90a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-03 1:51 ` Li Zefan
2009-07-02 8:09 ` Louis Rilling
2009-07-02 8:19 ` Paul Menage
2009-07-02 8:19 ` Paul Menage
2009-07-02 8:24 ` Louis Rilling
[not found] ` <6599ad830907020119g68abedbeu19ef46f32c4f6f3d-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-02 8:24 ` Louis Rilling
[not found] ` <20090702021057.14469.37548.stgit-u3IScbYxn0zHt/MElyovVYaSKrA+ACpX0E9HWUfgJXw@public.gmane.org>
2009-07-02 2:28 ` KAMEZAWA Hiroyuki
2009-07-02 8:09 ` Louis Rilling
2009-07-03 2:32 ` Li Zefan
2009-07-03 2:32 ` Li Zefan
[not found] ` <4A4D6DC4.10708-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2009-07-13 23:39 ` Paul Menage
2009-07-13 23:39 ` Paul Menage
2009-07-02 2:11 ` [PATCH 2/9] [RFC]Move the cgroup debug subsys into cgroup.c to access internal state Paul Menage
2009-07-02 2:11 ` Paul Menage
2009-07-02 2:11 ` [PATCH 3/9] [RFC] Add a back-pointer from struct cg_cgroup_link to struct cgroup Paul Menage
2009-07-02 2:11 ` Paul Menage
[not found] ` <20090702021108.14469.39645.stgit-u3IScbYxn0zHt/MElyovVYaSKrA+ACpX0E9HWUfgJXw@public.gmane.org>
2009-07-03 7:07 ` Li Zefan
2009-07-03 7:07 ` Li Zefan
2009-07-21 23:48 ` Paul Menage
[not found] ` <4A4DAE21.4000806-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2009-07-21 23:48 ` Paul Menage
2009-07-02 2:11 ` [PATCH 4/9] [RFC] Allow cgroup hierarchies to be created with no bound subsystems Paul Menage
2009-07-02 2:11 ` Paul Menage
[not found] ` <20090702021113.14469.2703.stgit-u3IScbYxn0zHt/MElyovVYaSKrA+ACpX0E9HWUfgJXw@public.gmane.org>
2009-07-03 7:57 ` Li Zefan
2009-07-03 7:57 ` Li Zefan
[not found] ` <4A4DB9E4.9060500-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2009-07-21 23:31 ` Paul Menage
2009-07-21 23:31 ` Paul Menage
2009-07-02 2:11 ` [PATCH 5/9] [RFC] Remove cgroup_subsys.root pointer Paul Menage
2009-07-02 2:11 ` [PATCH 6/9] [RFC] Remove the cgroup_subsys.bind callback Paul Menage
2009-07-02 2:11 ` Paul Menage
2009-07-02 2:11 ` [PATCH 7/9] [RFC] Support multiply-bindable cgroup subsystems Paul Menage
2009-07-02 2:11 ` Paul Menage
[not found] ` <20090702021128.14469.3360.stgit-u3IScbYxn0zHt/MElyovVYaSKrA+ACpX0E9HWUfgJXw@public.gmane.org>
2009-07-02 2:45 ` KAMEZAWA Hiroyuki
2009-07-02 2:45 ` KAMEZAWA Hiroyuki
[not found] ` <20090702114555.b7253edf.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2009-07-02 2:52 ` Paul Menage
2009-07-02 2:52 ` Paul Menage
2009-07-02 3:16 ` KAMEZAWA Hiroyuki
[not found] ` <20090702121626.7676c7d4.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2009-07-02 5:04 ` Paul Menage
2009-07-02 5:04 ` Paul Menage
[not found] ` <6599ad830907011952t2e698e77j1e8dba21402bc9a9-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-02 3:16 ` KAMEZAWA Hiroyuki
2009-07-03 8:36 ` Li Zefan
2009-07-03 8:36 ` Li Zefan
2009-07-02 2:11 ` [PATCH 8/9] [RFC] Example multi-bindable subsystem: a per-cgroup notes field Paul Menage
2009-07-02 2:11 ` [PATCH 9/9] [RFC] Example multi-bindable subsystem: a max-depth controller Paul Menage
2009-07-02 2:11 ` 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=4A4DC81B.3050608@cn.fujitsu.com \
--to=lizf@cn.fujitsu.com \
--cc=akpm@linux-foundation.org \
--cc=balbir@linux.vnet.ibm.com \
--cc=containers@lists.linux-foundation.org \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.