]> git.karo-electronics.de Git - mv-sheeva.git/commitdiff
pids: alloc_pidmap: remove the unnecessary boundary checks
authorOleg Nesterov <oleg@redhat.com>
Wed, 11 Aug 2010 01:03:17 +0000 (18:03 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 11 Aug 2010 15:59:20 +0000 (08:59 -0700)
alloc_pidmap() calculates max_scan so that if the initial offset != 0 we
inspect the first map->page twice.  This is correct, we want to find the
unused bits < offset in this bitmap block.  Add the comment.

But it doesn't make any sense to stop the find_next_offset() loop when we
are looking into this map->page for the second time.  We have already
already checked the bits >= offset during the first attempt, it is fine to
do this again, no matter if we succeed this time or not.

Remove this hard-to-understand code.  It optimizes the very unlikely case
when we are going to fail, but slows down the more likely case.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Cc: Salman Qazi <sqazi@google.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Sukadev Bhattiprolu <sukadev@us.ibm.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
kernel/pid.c

index fbbd5f6b6f2f19cd9d18dcb713b1daa4bedf0737..d55c6fb8d087a24a2d462886dfe1fc53bf9deced 100644 (file)
@@ -169,7 +169,12 @@ static int alloc_pidmap(struct pid_namespace *pid_ns)
                pid = RESERVED_PIDS;
        offset = pid & BITS_PER_PAGE_MASK;
        map = &pid_ns->pidmap[pid/BITS_PER_PAGE];
-       max_scan = (pid_max + BITS_PER_PAGE - 1)/BITS_PER_PAGE - !offset;
+       /*
+        * If last_pid points into the middle of the map->page we
+        * want to scan this bitmap block twice, the second time
+        * we start with offset == 0 (or RESERVED_PIDS).
+        */
+       max_scan = DIV_ROUND_UP(pid_max, BITS_PER_PAGE) - !offset;
        for (i = 0; i <= max_scan; ++i) {
                if (unlikely(!map->page)) {
                        void *page = kzalloc(PAGE_SIZE, GFP_KERNEL);
@@ -196,15 +201,7 @@ static int alloc_pidmap(struct pid_namespace *pid_ns)
                                }
                                offset = find_next_offset(map, offset);
                                pid = mk_pid(pid_ns, map, offset);
-                       /*
-                        * find_next_offset() found a bit, the pid from it
-                        * is in-bounds, and if we fell back to the last
-                        * bitmap block and the final block was the same
-                        * as the starting point, pid is before last_pid.
-                        */
-                       } while (offset < BITS_PER_PAGE && pid < pid_max &&
-                                       (i != max_scan || pid < last ||
-                                           !((last+1) & BITS_PER_PAGE_MASK)));
+                       } while (offset < BITS_PER_PAGE && pid < pid_max);
                }
                if (map < &pid_ns->pidmap[(pid_max-1)/BITS_PER_PAGE]) {
                        ++map;