From: Andrew Morton <akpm@linux-foundation.org>
To: "Raphael S. Carvalho" <raphael.scarv@gmail.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
"Serge E. Hallyn" <serge@hallyn.com>,
Serge Hallyn <serge.hallyn@canonical.com>,
"David S. Miller" <davem@davemloft.net>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] kernel/pid.c: Improve flow of a loop inside alloc_pidmap.
Date: Mon, 11 Mar 2013 14:57:34 -0700 [thread overview]
Message-ID: <20130311145734.b7a068a782e787facd285a80@linux-foundation.org> (raw)
In-Reply-To: <1363036736-14209-1-git-send-email-raphael.scarv@gmail.com>
On Mon, 11 Mar 2013 18:18:56 -0300 "Raphael S. Carvalho" <raphael.scarv@gmail.com> wrote:
> From: Raphael S.Carvalho <raphael.scarv@gmail.com>
>
> Notes: find_next_offset searches for an available "cleaned bit"
> in the respective pid bitmap (page), so returns the offset if found,
> otherwise it returns a value equals to BITS_PER_PAGE.
>
> For example, suppose find_next_offset didn't find any available
> bit, so there's no purpose to call mk_pid (Wasteful Cpu Cycles).
>
> Therefore, I found it could be better to call mk_pid after
> the checking (offset < BITS_PER_PAGE) returned sucessfully!
> Another point: If (offset < BITS_PER_PAGE) results in a "failure",
> then mk_pid would be called again afterwards.
>
> ...
>
> --- a/kernel/pid.c
> +++ b/kernel/pid.c
> @@ -190,8 +190,8 @@ static int alloc_pidmap(struct pid_namespace *pid_ns)
> return pid;
> }
> offset = find_next_offset(map, offset);
> - pid = mk_pid(pid_ns, map, offset);
> - } while (offset < BITS_PER_PAGE && pid < pid_max);
> + } while (offset < BITS_PER_PAGE &&
> + (pid = mk_pid(pid_ns, map, offset)) < pid_max);
> }
> if (map < &pid_ns->pidmap[(pid_max-1)/BITS_PER_PAGE]) {
> ++map;
Looks OK. But I think it's simpler and more straightforward to do it
this way?
for ( ; ; ) {
if (!test_and_set_bit(offset, map->page)) {
atomic_dec(&map->nr_free);
set_last_pid(pid_ns, last, pid);
return pid;
}
offset = find_next_offset(map, offset);
if (offset >= BITS_PER_PAGE)
break;
pid = mk_pid(pid_ns, map, offset);
if (pid >= pid_max)
break;
}
next prev parent reply other threads:[~2013-03-11 21:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-11 21:18 Raphael S. Carvalho
2013-03-11 21:57 ` Andrew Morton [this message]
2013-03-11 22:01 ` Raphael S Carvalho
-- strict thread matches above, loose matches on Subject: below --
2013-03-08 23:07 Raphael S.Carvalho
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=20130311145734.b7a068a782e787facd285a80@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=davem@davemloft.net \
--cc=ebiederm@xmission.com \
--cc=linux-kernel@vger.kernel.org \
--cc=raphael.scarv@gmail.com \
--cc=serge.hallyn@canonical.com \
--cc=serge@hallyn.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
all inboxes | Powered by JetHome®