Commit ef228cb1 authored by Marc G. Fournier's avatar Marc G. Fournier

From: Keith Parks <emkxp01@mtcc.demon.co.uk>

OK, The votes are in for the NOFILES limit.

With the exception of Next, for which I've not yet heard, all supported platforms
seem to have the sysconf() call.


port           supported	default	Source.
aix            yes		2000	darrenk@insightdist.com
alpha          yes		4096	mjl@wwx.vip.at
BSD44_derived  yes		64	scrappy@hub.org
bsdi           yes		???	maillist@candle.pha.pa.us
dgux           yes		???	geek@andrew.cmu.edu
hpux           yes		60	emkxp01@mtcc.demon.co.uk
i386_solaris   yes		64	emkxp01@mtcc.demon.co.uk
irix5          yes		200	martin@biochem.uc.ac.uk
linux          yes		256	emkxp01@mtcc.demon.co.uk
next           ????		???
sparc_solaris  yes		64	emkxp01@mtcc.demon.co.uk
sunos4         yes		64	emkxp01@mtcc.demon.co.uk
svr4           yes		64	chicks@chicks.net
ultrix4        yes		64	erik@sockdev.uni-c.dk

So here's a patch that I think will do the job.
(I assume Next will have sysconf() but if not just add MISSING_SYSCONF to
 the config.h file )

Thanks,
Keith.
parent 2595785b
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Id: fd.c,v 1.12 1996/12/28 22:44:14 momjian Exp $ * $Id: fd.c,v 1.13 1997/01/13 01:25:29 scrappy Exp $
* *
* NOTES: * NOTES:
* *
...@@ -52,21 +52,6 @@ ...@@ -52,21 +52,6 @@
#include "utils/palloc.h" #include "utils/palloc.h"
#include "storage/fd.h" #include "storage/fd.h"
#if defined(NEED_NOFILE_KLUDGE)
/*
* the SunOS 4 NOFILE is a lie, because the default limit is *not* the
* maximum number of file descriptors you can have open.
*
* we have to either use this number (the default dtablesize) or
* explicitly call setrlimit(RLIMIT_NOFILE, NOFILE).
*
* this braindamage apparently also affects solaris 2.X as well
*/
#include <sys/user.h>
#undef NOFILE
#define NOFILE NOFILE_IN_U
#endif /* NEED_NOFILE_KLUDGE */
/* /*
* Problem: Postgres does a system(ld...) to do dynamic loading. This * Problem: Postgres does a system(ld...) to do dynamic loading. This
* will open several extra files in addition to those used by * will open several extra files in addition to those used by
...@@ -81,23 +66,21 @@ ...@@ -81,23 +66,21 @@
* equivalent, the OS must still open several files to perform the * equivalent, the OS must still open several files to perform the
* dynamic loading. Keep this here.) * dynamic loading. Keep this here.)
*/ */
#ifndef RESERVE_FOR_LD
#define RESERVE_FOR_LD 10 #define RESERVE_FOR_LD 10
#endif
/* /*
* If we are using weird storage managers, we may need to keep real * We need to ensure that we have at least some file descriptors
* file descriptors open so that the jukebox server doesn't think we * available to postgreSQL after we've reserved the ones for LD,
* have gone away (and no longer care about a platter or file that * so we set that value here.
* we've been using). This might be an actual file descriptor for a *
* local jukebox interface that uses paths, or a socket connection for * I think 10 is an apropriate value so that's what it'll be
* a network jukebox server. Since we can't be opening and closing * for now.
* these descriptors at whim, we must make allowances for them.
*/ */
#ifdef HP_JUKEBOX #ifndef FD_MINFREE
#define RESERVE_FOR_JB 25 #define FD_MINFREE 10
#define MAXFILES ((NOFILE - RESERVE_FOR_LD) - RESERVE_FOR_JB) #endif
#else /* HP_JUKEBOX */
#define MAXFILES (NOFILE - RESERVE_FOR_LD)
#endif /* HP_JUKEBOX */
/* Debugging.... */ /* Debugging.... */
...@@ -197,6 +180,7 @@ static void FreeVfd(File file); ...@@ -197,6 +180,7 @@ static void FreeVfd(File file);
static int FileAccess(File file); static int FileAccess(File file);
static File fileNameOpenFile(FileName fileName, int fileFlags, int fileMode); static File fileNameOpenFile(FileName fileName, int fileFlags, int fileMode);
static char *filepath(char *filename); static char *filepath(char *filename);
static long pg_nofile(void);
int int
pg_fsync(int fd) pg_fsync(int fd)
...@@ -206,6 +190,30 @@ pg_fsync(int fd) ...@@ -206,6 +190,30 @@ pg_fsync(int fd)
} }
#define fsync pg_fsync #define fsync pg_fsync
long
pg_nofile(void)
{
static long no_files = 0;
if (no_files == 0) {
#if defined(MISSING_SYSCONF)
no_files = (long)NOFILE;
#else
no_files = sysconf(_SC_OPEN_MAX);
if (no_files == -1) {
elog(DEBUG,"pg_nofile: Unable to get _SC_OPEN_MAX using sysconf() using (%d)", NOFILE);
no_files = (long)NOFILE;
}
#endif /* MISSING_SYSCONF */
}
if ((no_files - RESERVE_FOR_LD) < FD_MINFREE)
elog(FATAL,"pg_nofile: insufficient File Descriptors in postmaster to start backend (%ld).\n"
" O/S allows %ld, Postmaster reserves %d, We need %d (MIN) after that.",
no_files - RESERVE_FOR_LD, no_files, RESERVE_FOR_LD, FD_MINFREE);
return no_files - RESERVE_FOR_LD;
}
#if defined(FDDEBUG) #if defined(FDDEBUG)
static void static void
_dump_lru() _dump_lru()
...@@ -374,7 +382,7 @@ AssertLruRoom() ...@@ -374,7 +382,7 @@ AssertLruRoom()
DO_DB(printf("DEBUG: AssertLruRoom (FreeFd = %d)\n", DO_DB(printf("DEBUG: AssertLruRoom (FreeFd = %d)\n",
FreeFd)); FreeFd));
if (FreeFd <= 0 || nfile >= MAXFILES) { if (FreeFd <= 0 || nfile >= pg_nofile()) {
/* We supposedly are using more vfds than we want to be. First /* We supposedly are using more vfds than we want to be. First
assert that there is at least one used vfd in the ring. assert that there is at least one used vfd in the ring.
*/ */
...@@ -550,7 +558,7 @@ fileNameOpenFile(FileName fileName, ...@@ -550,7 +558,7 @@ fileNameOpenFile(FileName fileName,
file = AllocateVfd(); file = AllocateVfd();
vfdP = &VfdCache[file]; vfdP = &VfdCache[file];
if (nfile >= MAXFILES || (FreeFd == 0 && osRanOut)) { if (nfile >= pg_nofile() || (FreeFd == 0 && osRanOut)) {
AssertLruRoom(); AssertLruRoom();
} }
...@@ -858,7 +866,7 @@ AllocateFile() ...@@ -858,7 +866,7 @@ AllocateFile()
} }
close(fd); close(fd);
++allocatedFiles; ++allocatedFiles;
fdleft = MAXFILES - allocatedFiles; fdleft = pg_nofile() - allocatedFiles;
if (fdleft < 6) { if (fdleft < 6) {
elog(DEBUG,"warning: few usable file descriptors left (%d)", fdleft); elog(DEBUG,"warning: few usable file descriptors left (%d)", fdleft);
} }
......
...@@ -102,7 +102,6 @@ ...@@ -102,7 +102,6 @@
# define HAVE_TZSET # define HAVE_TZSET
# define NEED_UNION_SEMUN # define NEED_UNION_SEMUN
# define SYSV_DIRENT # define SYSV_DIRENT
# define NEED_NOFILE_KLUDGE
# define SB_PAD 56 # define SB_PAD 56
# define HAS_TEST_AND_SET # define HAS_TEST_AND_SET
typedef unsigned char slock_t; typedef unsigned char slock_t;
...@@ -172,7 +171,6 @@ typedef unsigned char slock_t; ...@@ -172,7 +171,6 @@ typedef unsigned char slock_t;
#if defined(sunos4) #if defined(sunos4)
# define USE_POSIX_TIME # define USE_POSIX_TIME
# define NEED_NOFILE_KLUDGE
# define SB_PAD 56 # define SB_PAD 56
# undef HAVE_MEMMOVE # undef HAVE_MEMMOVE
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment