Commit 8db049b3 authored by Raphael S. Carvalho's avatar Raphael S. Carvalho Committed by Linus Torvalds

kernel/pid.c: improve flow of a loop inside alloc_pidmap.

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.

[akpm@linux-foundation.org: simplify code]
Signed-off-by: default avatarRaphael S. Carvalho <raphael.scarv@gmail.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Serge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent c75aaa8e
...@@ -183,15 +183,19 @@ static int alloc_pidmap(struct pid_namespace *pid_ns) ...@@ -183,15 +183,19 @@ static int alloc_pidmap(struct pid_namespace *pid_ns)
break; break;
} }
if (likely(atomic_read(&map->nr_free))) { if (likely(atomic_read(&map->nr_free))) {
do { for ( ; ; ) {
if (!test_and_set_bit(offset, map->page)) { if (!test_and_set_bit(offset, map->page)) {
atomic_dec(&map->nr_free); atomic_dec(&map->nr_free);
set_last_pid(pid_ns, last, pid); set_last_pid(pid_ns, last, pid);
return pid; return pid;
} }
offset = find_next_offset(map, offset); offset = find_next_offset(map, offset);
if (offset >= BITS_PER_PAGE)
break;
pid = mk_pid(pid_ns, map, offset); pid = mk_pid(pid_ns, map, offset);
} while (offset < BITS_PER_PAGE && pid < pid_max); if (pid >= pid_max)
break;
}
} }
if (map < &pid_ns->pidmap[(pid_max-1)/BITS_PER_PAGE]) { if (map < &pid_ns->pidmap[(pid_max-1)/BITS_PER_PAGE]) {
++map; ++map;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment