From: Raphael S. Carvalho Date: Tue, 30 Apr 2013 22:28:26 +0000 (-0700) Subject: kernel/pid.c: improve flow of a loop inside alloc_pidmap. X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=8db049b3d666b3676ff4a976e03c14de302bf9fa;p=GitHub%2Fexynos8895%2Fandroid_kernel_samsung_universal8895.git 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: Raphael S. Carvalho Cc: "Eric W. Biederman" Cc: Serge Hallyn Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/kernel/pid.c b/kernel/pid.c index 047dc6264638..8147bdf22f36 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -183,15 +183,19 @@ static int alloc_pidmap(struct pid_namespace *pid_ns) break; } if (likely(atomic_read(&map->nr_free))) { - do { + 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); - } while (offset < BITS_PER_PAGE && pid < pid_max); + if (pid >= pid_max) + break; + } } if (map < &pid_ns->pidmap[(pid_max-1)/BITS_PER_PAGE]) { ++map;