diff options
author | Raphael S. Carvalho <raphael.scarv@gmail.com> | 2013-04-30 18:28:26 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-04-30 20:04:07 -0400 |
commit | 8db049b3d666b3676ff4a976e03c14de302bf9fa (patch) | |
tree | 74d5e5c8e25b451e983e66cb1e2a41cbf8e1b4f1 /kernel/pid.c | |
parent | c75aaa8ed03eb1312ed2990f1a716b2b9cc0df42 (diff) |
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 <raphael.scarv@gmail.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Serge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/pid.c')
-rw-r--r-- | kernel/pid.c | 8 |
1 files changed, 6 insertions, 2 deletions
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) | |||
183 | break; | 183 | break; |
184 | } | 184 | } |
185 | if (likely(atomic_read(&map->nr_free))) { | 185 | if (likely(atomic_read(&map->nr_free))) { |
186 | do { | 186 | for ( ; ; ) { |
187 | if (!test_and_set_bit(offset, map->page)) { | 187 | if (!test_and_set_bit(offset, map->page)) { |
188 | atomic_dec(&map->nr_free); | 188 | atomic_dec(&map->nr_free); |
189 | set_last_pid(pid_ns, last, pid); | 189 | set_last_pid(pid_ns, last, pid); |
190 | return pid; | 190 | return pid; |
191 | } | 191 | } |
192 | offset = find_next_offset(map, offset); | 192 | offset = find_next_offset(map, offset); |
193 | if (offset >= BITS_PER_PAGE) | ||
194 | break; | ||
193 | pid = mk_pid(pid_ns, map, offset); | 195 | pid = mk_pid(pid_ns, map, offset); |
194 | } while (offset < BITS_PER_PAGE && pid < pid_max); | 196 | if (pid >= pid_max) |
197 | break; | ||
198 | } | ||
195 | } | 199 | } |
196 | if (map < &pid_ns->pidmap[(pid_max-1)/BITS_PER_PAGE]) { | 200 | if (map < &pid_ns->pidmap[(pid_max-1)/BITS_PER_PAGE]) { |
197 | ++map; | 201 | ++map; |