From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@sunsite.dk
Subject: Re: unlimited file descripters causes problems for zsh-4.0.2
Date: Sun, 21 Oct 2001 19:07:27 +0000 [thread overview]
Message-ID: <1011021190727.ZM14572@candle.brasslantern.com> (raw)
In-Reply-To: <1011019175644.ZM9169@candle.brasslantern.com>
On Oct 19, 5:56pm, Bart Schaefer wrote:
}
} } What I'm more concerned about is closeallelse() in exec.c, which is going
} } to make up to several billion close() calls
}
} Here's a suggestion: Once, at startup, we scan all the way to zopenmax()
} looking for open descriptors, and set a global to the largest number we
} find.
The following patch approximately implements the above. It does not yet
change init.c to use a constant for fdtable_size, which is still needed
to prevent zsh from allocating huge amounts of memory if a descriptor
with a very large number is already open when the shell starts up.
I'm not able to test this on a machine that really implements a huge max.
number of file descriptors, so I won't commit it until someone else has
tried it.
Index: compat.c
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-4.0/Src/compat.c,v
retrieving revision 1.2
diff -c -r1.2 compat.c
--- compat.c 2001/07/10 09:05:20 1.2
+++ compat.c 2001/10/21 19:00:17
@@ -198,12 +198,32 @@
mod_export long
zopenmax(void)
{
- long openmax = sysconf(_SC_OPEN_MAX);
+ static long openmax = 0;
- if (openmax < 1)
- return OPEN_MAX;
- else
- return openmax;
+ if (openmax < 1) {
+ if ((openmax = sysconf(_SC_OPEN_MAX)) < 1) {
+ openmax = OPEN_MAX;
+ } else if (openmax > OPEN_MAX) {
+ /* On some systems, "limit descriptors unlimited" or the *
+ * equivalent will set openmax to a huge number. Unless *
+ * there actually is a file descriptor > OPEN_MAX already *
+ * open, nothing in zsh requires the true maximum, and in *
+ * fact it causes inefficiency elsewhere if we report it. *
+ * So, report the maximum of OPEN_MAX or the largest open *
+ * descriptor (is there a better way to find that?). */
+ long i, j = OPEN_MAX;
+ for (i = j; i < openmax; i += (errno != EINTR)) {
+ errno = 0;
+ if (fcntl(i, F_GETFL, 0) < 0 &&
+ (errno == EBADF || errno == EINTR))
+ continue;
+ j = i;
+ }
+ openmax = j;
+ }
+ }
+
+ return (max_zsh_fd > openmax) ? max_zsh_fd : openmax;
}
#endif
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
next prev parent reply other threads:[~2001-10-21 19:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-10-18 23:44 Matthew Braun
2001-10-19 16:40 ` Bart Schaefer
2001-10-19 17:56 ` Bart Schaefer
2001-10-21 19:07 ` Bart Schaefer [this message]
2001-10-21 20:17 ` Bart Schaefer
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=1011021190727.ZM14572@candle.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=zsh-workers@sunsite.dk \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).