Skip to content

Commit 8db049b

Browse files
raphaelsctorvalds
authored andcommitted
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>
1 parent c75aaa8 commit 8db049b

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎kernel/pid.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,19 @@ static int alloc_pidmap(struct pid_namespace *pid_ns)
183183
break;
184184
}
185185
if (likely(atomic_read(&map->nr_free))) {
186-
do {
186+
for ( ; ; ) {
187187
if (!test_and_set_bit(offset, map->page)) {
188188
atomic_dec(&map->nr_free);
189189
set_last_pid(pid_ns, last, pid);
190190
return pid;
191191
}
192192
offset = find_next_offset(map, offset);
193+
if (offset >= BITS_PER_PAGE)
194+
break;
193195
pid = mk_pid(pid_ns, map, offset);
194-
} while (offset < BITS_PER_PAGE && pid < pid_max);
196+
if (pid >= pid_max)
197+
break;
198+
}
195199
}
196200
if (map < &pid_ns->pidmap[(pid_max-1)/BITS_PER_PAGE]) {
197201
++map;

0 commit comments

Comments
 (0)