From: Jerome Marchand <jmarchan@redhat.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Vasiliy Kulikov <segoon@openwall.com>,
Balbir Singh <bsingharora@gmail.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] taskstats: add_del_listener() shouldn't use the wrong node
Date: Thu, 21 Jul 2011 14:28:48 +0200 [thread overview]
Message-ID: <4E281B80.2050606@redhat.com> (raw)
In-Reply-To: <20110720190019.GA21753@redhat.com>
On 07/20/2011 09:00 PM, Oleg Nesterov wrote:
> 1. 26c4caea "don't allow duplicate entries in listener mode"
> changed add_del_listener(REGISTER) so that "next_cpu:" can
> reuse the listener allocated for the previous cpu, this
> doesn't look exactly right even if minor.
That construction is somewhat unusual. I agree that this code looks cleaner
and probably reduces the risk that someone in the future misunderstand the
code.
>
> Change the code to kfree() in the already-registered case,
> this case is unlikely anyway so the extra kmalloc_node()
> shouldn't hurt but looke more correct and clean.
>
> 2. use the plain list_for_each_entry() instead of _safe() to
> scan listeners->list.
>
> 3. Remove the unneeded INIT_LIST_HEAD(&s->list), we are going
> to list_add(&s->list).
>
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: Jerome Marchand <jmarchan@redhat.com>
> ---
>
> kernel/taskstats.c | 16 +++++++---------
> 1 file changed, 7 insertions(+), 9 deletions(-)
>
> --- ts/kernel/taskstats.c~1_cleanup 2011-07-03 16:27:57.000000000 +0200
> +++ ts/kernel/taskstats.c 2011-07-20 19:35:38.000000000 +0200
> @@ -291,30 +291,28 @@ static int add_del_listener(pid_t pid, c
> if (!cpumask_subset(mask, cpu_possible_mask))
> return -EINVAL;
>
> - s = NULL;
> if (isadd == REGISTER) {
> for_each_cpu(cpu, mask) {
> - if (!s)
> - s = kmalloc_node(sizeof(struct listener),
> - GFP_KERNEL, cpu_to_node(cpu));
> + s = kmalloc_node(sizeof(struct listener),
> + GFP_KERNEL, cpu_to_node(cpu));
> if (!s)
> goto cleanup;
> +
> s->pid = pid;
> - INIT_LIST_HEAD(&s->list);
> s->valid = 1;
>
> listeners = &per_cpu(listener_array, cpu);
> down_write(&listeners->sem);
> - list_for_each_entry_safe(s2, tmp, &listeners->list, list) {
> + list_for_each_entry(s2, &listeners->list, list) {
> if (s2->pid == pid)
> - goto next_cpu;
> + goto exists;
> }
> list_add(&s->list, &listeners->list);
> s = NULL;
> -next_cpu:
> +exists:
> up_write(&listeners->sem);
> + kfree(s); /* nop if NULL */
> }
> - kfree(s);
> return 0;
> }
>
>
next prev parent reply other threads:[~2011-07-21 12:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-20 18:59 [PATCH 0/2] 26c4caea "don't allow duplicate entries in listener mode" fix Oleg Nesterov
2011-07-20 19:00 ` [PATCH 1/2] taskstats: add_del_listener() shouldn't use the wrong node Oleg Nesterov
2011-07-20 19:50 ` Vasiliy Kulikov
2011-07-21 12:28 ` Jerome Marchand [this message]
2011-07-20 19:00 ` [PATCH 2/2] taskstats: add_del_listener() should ignore !valid listener's Oleg Nesterov
2011-07-20 19:46 ` Vasiliy Kulikov
2011-07-20 21:01 ` Oleg Nesterov
2011-07-21 12:50 ` Vasiliy Kulikov
2011-07-21 14:29 ` Oleg Nesterov
2011-07-21 15:49 ` Balbir Singh
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=4E281B80.2050606@redhat.com \
--to=jmarchan@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=bsingharora@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=segoon@openwall.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox