From: Oleg Nesterov <oleg@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>, Salman <sqazi@google.com>
Cc: mingo@elte.hu, linux-kernel@vger.kernel.org,
peterz@infradead.org, tytso@google.com,
torvalds@linux-foundation.org, walken@google.com
Subject: [PATCH 1/1] pids: alloc_pidmap: remove the unnecessary boundary checks
Date: Tue, 15 Jun 2010 20:35:56 +0200 [thread overview]
Message-ID: <20100615183556.GB24577@redhat.com> (raw)
In-Reply-To: <20100615183525.GA24577@redhat.com>
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>
---
kernel/pid.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
--- 35-rc2/kernel/pid.c~PID_CLEANUP 2010-06-15 19:33:14.000000000 +0200
+++ 35-rc2/kernel/pid.c 2010-06-15 19:52:03.000000000 +0200
@@ -169,7 +169,12 @@ static int alloc_pidmap(struct pid_names
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_names
}
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;
prev parent reply other threads:[~2010-06-15 18:37 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-11 17:17 [PATCH] Fix a race in pid generation that causes pids to be reused immediately Salman
2010-06-11 17:44 ` Linus Torvalds
2010-06-11 22:49 ` Salman
2010-06-11 23:07 ` Linus Torvalds
2010-06-14 23:58 ` Andrew Morton
2010-06-15 0:56 ` tytso
2010-06-15 1:55 ` Andrew Morton
2010-06-15 3:26 ` Paul Mackerras
2010-06-15 4:21 ` Andrew Morton
2010-06-15 4:38 ` Eric Dumazet
2010-06-15 6:57 ` Benjamin Herrenschmidt
2010-06-15 7:25 ` Paul Mackerras
2010-06-15 12:56 ` tytso
2010-06-15 13:06 ` Kyle McMartin
2010-06-15 14:35 ` Peter Zijlstra
2010-06-15 19:37 ` Andrew Morton
2010-06-15 18:35 ` [PATCH 0/1] (Was: Fix a race in pid generation that causes pids to be reused immediately.) Oleg Nesterov
2010-06-15 18:35 ` Oleg Nesterov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100615183556.GB24577@redhat.com \
--to=oleg@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=sqazi@google.com \
--cc=torvalds@linux-foundation.org \
--cc=tytso@google.com \
--cc=walken@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox