From: Tejun Heo <tj@kernel.org>
To: Aleksa Sarai <cyphar@cyphar.com>
Cc: lizefan@huawei.com, mingo@redhat.com, peterz@infradead.org,
richard@nod.at, fweisbec@gmail.com, linux-kernel@vger.kernel.org,
cgroups@vger.kernel.org
Subject: Re: [PATCH v8 3/4] cgroups: allow a cgroup subsystem to reject a fork
Date: Wed, 1 Apr 2015 12:02:58 -0400 [thread overview]
Message-ID: <20150401160258.GP9974@htj.duckdns.org> (raw)
In-Reply-To: <1427878641-5273-4-git-send-email-cyphar@cyphar.com>
Hello, Aleksa.
On Wed, Apr 01, 2015 at 07:57:20PM +1100, Aleksa Sarai wrote:
> +struct cgroup_fork_state {
> + void *ss_state[CGROUP_SUBSYS_COUNT];
> +};
Can we collect the subsystems which require pre/post fork callbacks to
the front in group_subsys.h and do do CGROUP_SUBSYS_FORK_COUNT (or
whatever) instead? Then, we don't need all these subsys bitmasks
either we can just test the index against that and be done with it.
> +
> +/**
> + * cgroup_cfs_alloc - allocates an empty cgroup_fork_state
> + */
> +struct cgroup_fork_state *cgroup_cfs_alloc(void)
> +{
> + struct cgroup_fork_state *cfs;
> +
> + cfs = kzalloc(sizeof(struct cgroup_fork_state), GFP_KERNEL);
> + if (!cfs)
> + return ERR_PTR(-ENOMEM);
> +
> + return cfs;
> +}
Just make it a void * array and put it on stack. Abstraction at this
level doesn't serve any purpose. No controller code is gonna see this
anyway.
> +int cgroup_can_fork(struct task_struct *child, struct cgroup_fork_state *cfs)
> +{
> + struct cgroup_subsys *ss;
> + int i, j, retval;
> +
> + for_each_subsys_which(need_canfork_callback, ss, i) {
> + retval = ss->can_fork(child, &cfs->ss_state[i]);
> + if (retval)
> + goto out_revert;
> + }
> +
> + return 0;
> +
> +out_revert:
> + for_each_subsys_which(need_cancelfork_callback, ss, j) {
> + if (j >= i)
> + break;
> + ss->cancel_fork(child, &cfs->ss_state[i]);
cancel_fork() has no reason to update the opaque pointer. No reason
to pass pointer of it.
> +void cgroup_cancel_fork(struct task_struct *child, struct cgroup_fork_state *cfs)
> +{
> + struct cgroup_subsys *ss;
> + int i;
> +
> + for_each_subsys_which(need_cancelfork_callback, ss, i) {
> + void **state = NULL;
> +
> + /*
> + * Only if %ss has a can_fork() callback is %cfs->ss_state[i] meaningful
I don't think we do %var, do we? % is used for macros and consts.
> + * -- otherwise just pass a NULL.
> + */
> + if (need_canfork_callback & (1 << i))
> + state = &cfs->ss_state[i];
> +
> + ss->cancel_fork(child, &cfs->ss_state[i]);
Ditto, just pass the pointer itself.
> @@ -5241,8 +5346,18 @@ void cgroup_post_fork(struct task_struct *child)
> * css_set; otherwise, @child might change state between ->fork()
> * and addition to css_set.
> */
> - for_each_subsys_which(need_fork_callback, ss, i)
> - ss->fork(child);
> + for_each_subsys_which(need_fork_callback, ss, i) {
> + void **state = NULL;
> +
> + /*
> + * Only if %ss has a can_fork() callback is %old_cfs->ss_state[i]
> + * meaningful -- otherwise just pass a NULL.
> + */
Again, if you just passed the pointer, you wouldn't need the above.
Just clear the array on init and pass in whatever value is in there.
> + if (need_canfork_callback & (1 << i))
> + state = &old_cfs->ss_state[i];
> +
> + ss->fork(child, state);
> + }
> }
Thanks.
--
tejun
next prev parent reply other threads:[~2015-04-01 16:03 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-01 8:57 [PATCH v8 0/4] cgroups: add pids subsystem Aleksa Sarai
2015-04-01 8:57 ` [PATCH v8 1/4] cgroups: use bitmask to filter for_each_subsys Aleksa Sarai
2015-04-01 8:57 ` [PATCH v8 2/4] cgroups: replace explicit ss_mask checking with for_each_subsys_which Aleksa Sarai
2015-04-01 8:57 ` [PATCH v8 3/4] cgroups: allow a cgroup subsystem to reject a fork Aleksa Sarai
2015-04-01 16:02 ` Tejun Heo [this message]
2015-04-02 23:42 ` Aleksa Sarai
2015-04-06 15:05 ` Tejun Heo
2015-04-07 13:47 ` Aleksa Sarai
2015-04-07 14:00 ` Tejun Heo
2015-04-01 8:57 ` [PATCH v8 4/4] cgroups: implement the PIDs subsystem Aleksa Sarai
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=20150401160258.GP9974@htj.duckdns.org \
--to=tj@kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=cyphar@cyphar.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=richard@nod.at \
/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;
as well as URLs for NNTP newsgroup(s).