Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitef228cb

Browse files
committed
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 platformsseem to have the sysconf() call.port supporteddefaultSource.aix yes2000darrenk@insightdist.comalpha yes4096mjl@wwx.vip.atBSD44_derived yes64scrappy@hub.orgbsdi yes???maillist@candle.pha.pa.usdgux yes???geek@andrew.cmu.eduhpux yes60emkxp01@mtcc.demon.co.uki386_solaris yes64emkxp01@mtcc.demon.co.ukirix5 yes200martin@biochem.uc.ac.uklinux yes256emkxp01@mtcc.demon.co.uknext ???????sparc_solaris yes64emkxp01@mtcc.demon.co.uksunos4 yes64emkxp01@mtcc.demon.co.uksvr4 yes64chicks@chicks.netultrix4 yes64erik@sockdev.uni-c.dkSo 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.
1 parent2595785 commitef228cb

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed

‎src/backend/storage/file/fd.c

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 1994, Regents of the University of California
77
*
88
* IDENTIFICATION
9-
* $Id: fd.c,v 1.12 1996/12/28 22:44:14 momjian Exp $
9+
* $Id: fd.c,v 1.13 1997/01/13 01:25:29 scrappy Exp $
1010
*
1111
* NOTES:
1212
*
@@ -52,21 +52,6 @@
5252
#include"utils/palloc.h"
5353
#include"storage/fd.h"
5454

55-
#if defined(NEED_NOFILE_KLUDGE)
56-
/*
57-
* the SunOS 4 NOFILE is a lie, because the default limit is *not* the
58-
* maximum number of file descriptors you can have open.
59-
*
60-
* we have to either use this number (the default dtablesize) or
61-
* explicitly call setrlimit(RLIMIT_NOFILE, NOFILE).
62-
*
63-
* this braindamage apparently also affects solaris 2.X as well
64-
*/
65-
#include<sys/user.h>
66-
#undef NOFILE
67-
#defineNOFILE NOFILE_IN_U
68-
#endif/* NEED_NOFILE_KLUDGE */
69-
7055
/*
7156
* Problem: Postgres does a system(ld...) to do dynamic loading. This
7257
* will open several extra files in addition to those used by
@@ -81,23 +66,21 @@
8166
* equivalent, the OS must still open several files to perform the
8267
* dynamic loading. Keep this here.)
8368
*/
69+
#ifndefRESERVE_FOR_LD
8470
#defineRESERVE_FOR_LD 10
71+
#endif
8572

8673
/*
87-
* If we are using weird storage managers, we may need to keep real
88-
* file descriptors open so that the jukebox server doesn't think we
89-
* have gone away (and no longer care about a platter or file that
90-
* we've been using). This might be an actual file descriptor for a
91-
* local jukebox interface that uses paths, or a socket connection for
92-
* a network jukebox server. Since we can't be opening and closing
93-
* these descriptors at whim, we must make allowances for them.
74+
* We need to ensure that we have at least some file descriptors
75+
* available to postgreSQL after we've reserved the ones for LD,
76+
* so we set that value here.
77+
*
78+
* I think 10 is an apropriate value so that's what it'll be
79+
* for now.
9480
*/
95-
#ifdefHP_JUKEBOX
96-
#defineRESERVE_FOR_JB 25
97-
#defineMAXFILES ((NOFILE - RESERVE_FOR_LD) - RESERVE_FOR_JB)
98-
#else/* HP_JUKEBOX */
99-
#defineMAXFILES (NOFILE - RESERVE_FOR_LD)
100-
#endif/* HP_JUKEBOX */
81+
#ifndefFD_MINFREE
82+
#defineFD_MINFREE 10
83+
#endif
10184

10285
/* Debugging.... */
10386

@@ -197,6 +180,7 @@ static void FreeVfd(File file);
197180
staticintFileAccess(Filefile);
198181
staticFilefileNameOpenFile(FileNamefileName,intfileFlags,intfileMode);
199182
staticchar*filepath(char*filename);
183+
staticlongpg_nofile(void);
200184

201185
int
202186
pg_fsync(intfd)
@@ -206,6 +190,30 @@ pg_fsync(int fd)
206190
}
207191
#definefsync pg_fsync
208192

193+
long
194+
pg_nofile(void)
195+
{
196+
staticlongno_files=0;
197+
198+
if (no_files==0) {
199+
#if defined(MISSING_SYSCONF)
200+
no_files= (long)NOFILE;
201+
#else
202+
no_files=sysconf(_SC_OPEN_MAX);
203+
if (no_files==-1) {
204+
elog(DEBUG,"pg_nofile: Unable to get _SC_OPEN_MAX using sysconf() using (%d)",NOFILE);
205+
no_files= (long)NOFILE;
206+
}
207+
#endif/* MISSING_SYSCONF */
208+
}
209+
210+
if ((no_files-RESERVE_FOR_LD)<FD_MINFREE)
211+
elog(FATAL,"pg_nofile: insufficient File Descriptors in postmaster to start backend (%ld).\n"
212+
" O/S allows %ld, Postmaster reserves %d, We need %d (MIN) after that.",
213+
no_files-RESERVE_FOR_LD,no_files,RESERVE_FOR_LD,FD_MINFREE);
214+
returnno_files-RESERVE_FOR_LD;
215+
}
216+
209217
#if defined(FDDEBUG)
210218
staticvoid
211219
_dump_lru()
@@ -374,7 +382,7 @@ AssertLruRoom()
374382
DO_DB(printf("DEBUG: AssertLruRoom (FreeFd = %d)\n",
375383
FreeFd));
376384

377-
if (FreeFd <=0||nfile >=MAXFILES) {
385+
if (FreeFd <=0||nfile >=pg_nofile()) {
378386
/* We supposedly are using more vfds than we want to be. First
379387
assert that there is at least one used vfd in the ring.
380388
*/
@@ -550,7 +558,7 @@ fileNameOpenFile(FileName fileName,
550558
file=AllocateVfd();
551559
vfdP=&VfdCache[file];
552560

553-
if (nfile >=MAXFILES|| (FreeFd==0&&osRanOut)) {
561+
if (nfile >=pg_nofile()|| (FreeFd==0&&osRanOut)) {
554562
AssertLruRoom();
555563
}
556564

@@ -858,7 +866,7 @@ AllocateFile()
858866
}
859867
close(fd);
860868
++allocatedFiles;
861-
fdleft=MAXFILES-allocatedFiles;
869+
fdleft=pg_nofile()-allocatedFiles;
862870
if (fdleft<6) {
863871
elog(DEBUG,"warning: few usable file descriptors left (%d)",fdleft);
864872
}

‎src/include/config.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
# defineHAVE_TZSET
103103
# defineNEED_UNION_SEMUN
104104
# define SYSV_DIRENT
105-
# defineNEED_NOFILE_KLUDGE
106105
# defineSB_PAD 56
107106
# defineHAS_TEST_AND_SET
108107
typedefunsignedcharslock_t;
@@ -172,7 +171,6 @@ typedef unsigned char slock_t;
172171

173172
#if defined(sunos4)
174173
# defineUSE_POSIX_TIME
175-
# defineNEED_NOFILE_KLUDGE
176174
# defineSB_PAD 56
177175
# undef HAVE_MEMMOVE
178176
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp