From: Ingo Molnar <mingo@elte.hu>
To: Anton Blanchard <anton@samba.org>
Cc: linux-kernel@vger.kernel.org,
viro@parcelfarce.linux.theplanet.co.uk, wli@holomorphy.com
Subject: Re: /proc/sys/kernel/pid_max issues
Date: Sun, 12 Sep 2004 11:39:43 +0200 [thread overview]
Message-ID: <20040912093943.GA10356@elte.hu> (raw)
In-Reply-To: <20040912085609.GK32755@krispykreme>
[-- Attachment #1: Type: text/plain, Size: 1967 bytes --]
* Anton Blanchard <anton@samba.org> wrote:
> I tried creating 100,000 threads just for the hell of it. I was
> surprised that it appears to have worked even with pid_max set at 32k.
>
> It seems if we are above pid_max we wrap back to RESERVED_PIDS at the
> start of alloc_pidmap but do not enforce this upper limit. I guess
> every call of alloc_pidmap above 32k was wrapping back to
> RESERVED_PIDS, walking the allocated space then allocating off the
> end.
yeah. Does the attached patch fix it?
> Just as an aside, does it make sense to remove the pidmap allocator
> and use the IDR allocator now its there?
might make sense - needs benchmarking. In particular the performance of
kill(pid, 0) [PID lookup] should be benchmarked on the cycle level, and
the combined performance of pthread_create()+pthread_exit().
> Now once I had managed to allocate those 100,000 threads, I noticed
> this:
>
> 18446744071725383682 dr-xr-xr-x 3 root root 0 Sep 12 08:10 100796
>
> Strange huh. Turns out we allocate inodes in proc via:
>
> #define fake_ino(pid,ino) (((pid)<<16)|(ino))
>
> With 32bit inodes we are screwed once pids go over 64k arent we?
indeed.
i'm wondering, dont we have a similar problem with PROC_TID_FD_DIR
already? Running some simple code that opens 1 million files gives:
[root@saturn root]# ulimit -n 1000000
[root@saturn root]# ./open-fds 1000000
999997 fds opened
[root@saturn root]# cd /proc/2333/fd/
[root@saturn fd]# ls -li | grep 153028253
153028253 lrwx------ 1 root root 64 Sep 12 11:18 165533 -> /dev/pts/0
153028253 lrwx------ 1 root root 64 Sep 12 11:18 362141 -> /dev/pts/0
153028253 lrwx------ 1 root root 64 Sep 12 11:18 427677 -> /dev/pts/0
153028253 lrwx------ 1 root root 64 Sep 12 11:18 624285 -> /dev/pts/0
153028253 lrwx------ 1 root root 64 Sep 12 11:19 689821 -> /dev/pts/0
153028253 lrwx------ 1 root root 64 Sep 12 11:18 99997 -> /dev/pts/0
[...]
plenty of overlap in the #ino space.
Ingo
[-- Attachment #2: pid-max-fix.patch --]
[-- Type: text/plain, Size: 515 bytes --]
--- linux/kernel/pid.c.orig
+++ linux/kernel/pid.c
@@ -103,7 +103,7 @@ int alloc_pidmap(void)
pidmap_t *map;
pid = last_pid + 1;
- if (pid >= pid_max)
+ if (unlikely(pid >= pid_max))
pid = RESERVED_PIDS;
offset = pid & BITS_PER_PAGE_MASK;
@@ -116,6 +116,10 @@ int alloc_pidmap(void)
* slowpath and that fixes things up.
*/
return_pid:
+ if (unlikely(pid >= pid_max)) {
+ clear_bit(offset, map->page);
+ goto failure;
+ }
atomic_dec(&map->nr_free);
last_pid = pid;
return pid;
next prev parent reply other threads:[~2004-09-12 9:41 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-12 8:56 /proc/sys/kernel/pid_max issues Anton Blanchard
2004-09-12 9:36 ` William Lee Irwin III
2004-09-12 9:51 ` Ingo Molnar
2004-09-12 9:58 ` William Lee Irwin III
2004-09-12 10:10 ` William Lee Irwin III
2004-09-12 10:13 ` Ingo Molnar
2004-09-12 10:43 ` William Lee Irwin III
2004-09-12 10:45 ` William Lee Irwin III
2004-09-12 11:08 ` William Lee Irwin III
2004-09-12 11:20 ` Ingo Molnar
2004-09-12 17:13 ` William Lee Irwin III
2004-09-12 18:02 ` Chris Wedgwood
2004-09-12 23:06 ` William Lee Irwin III
2004-09-13 1:46 ` [pidhashing] rewrite alloc_pidmap() William Lee Irwin III
2004-09-12 9:39 ` Ingo Molnar [this message]
2004-09-12 9:43 ` /proc/sys/kernel/pid_max issues William Lee Irwin III
2004-09-12 12:18 ` Arjan van de Ven
2004-09-12 12:30 ` Anton Blanchard
2004-09-12 12:44 ` Arjan van de Ven
2004-09-12 13:34 ` Anton Blanchard
2004-09-12 13:41 ` Ingo Molnar
-- strict thread matches above, loose matches on Subject: below --
2004-09-13 3:20 Albert Cahalan
2004-09-13 7:42 ` William Lee Irwin III
2004-09-13 14:11 ` Albert Cahalan
2004-09-13 14:27 ` William Lee Irwin III
2004-09-13 14:51 ` Herbert Poetzl
2004-09-14 2:13 ` William Lee Irwin III
2004-09-23 13:13 ` Pavel Machek
2004-09-24 16:02 ` Martin Mares
2004-09-23 13:11 ` Pavel Machek
2004-09-13 7:57 ` Ingo Molnar
2004-09-13 13:54 ` Albert Cahalan
2004-09-13 14:24 ` William Lee Irwin III
2004-09-13 14:54 ` Albert Cahalan
2004-09-14 2:02 ` William Lee Irwin III
2004-09-14 15:32 ` Ingo Molnar
2004-09-18 18:32 ` Pavel Machek
2004-09-23 13:18 ` Pavel Machek
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=20040912093943.GA10356@elte.hu \
--to=mingo@elte.hu \
--cc=anton@samba.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@parcelfarce.linux.theplanet.co.uk \
--cc=wli@holomorphy.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