Re: Too-many-files errors on OS X

From: Larry Rosenman <ler(at)lerctr(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Kevin Brown <kevin(at)sysexperts(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Too-many-files errors on OS X
Date: 2004-02-23 10:49:02
Message-ID: 29880000.1077533342@lerlaptop.lerctr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

--On Sunday, February 22, 2004 23:00:31 -0500 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
wrote:

> Kevin Brown <kevin(at)sysexperts(dot)com> writes:
>> I wasn't able to test on HP-UX
>
> I get the same result on HPUX, after whacking the test program around
> a bit: no change in the number of files we can open. Confirmations on
> other platforms please, anyone?
>
> For anyone else who has problems getting it to compile, try copying
> the relevant version of pg_dlopen from src/backend/port/dynloader/.
> I attach the code I actually ran on HPUX.
>
> regards, tom lane
>
On FreeBSD 5:

$ ./eatfds3 /usr/local/lib/libpq.so /usr/lib/libm.so
dup() failed: Too many open files
Was able to use 7146 file descriptors
dup() failed: Too many open files
Was able to use 7146 file descriptors after opening 2 shared libs
$

On UnixWare 7.1.4:
$ ./eatfds3 /usr/lib/libpq.so.3 /usr/lib/libm.so.1
dup() failed: Too many open files
Was able to use 2045 file descriptors
dup() failed: Too many open files
Was able to use 2045 file descriptors after opening 2 shared libs
$

I had to hack on the code some more for FreeBSD:
(the realloc call needed the multiplication). I ran this same code
on UnixWare.

$ cat eatfds3.c
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <dlfcn.h>
// these seem to be needed on HPUX:
//#include <a.out.h>
//#include <dl.h>

int *fd;
int size = 3072;

void *
pg_dlopen(char *filename)
{
/*
* Use BIND_IMMEDIATE so that undefined symbols cause a failure
return
* from shl_load(), rather than an abort() later on when we attempt
to
* call the library!
*/
caddr_t handle = dlopen(filename,
RTLD_LAZY);

return (void *) handle;
}

int eatallfds(void) {
int i = 0;
int j, myfd;

while (1) {
myfd = dup(0);
if (myfd < 0) {
fprintf (stderr, "dup() failed: %s\n",
strerror(errno));
break;
}
if (i >= size) {
size *= 2;
fd = realloc(fd, size * sizeof(*fd));
if (fd == NULL) {
fprintf (stderr, "Can't allocate: %s\n",
strerror(errno));
fprintf (stderr, "Had used %d
descriptors\n",
i);
exit(1);
}
}
fd[i++] = myfd;
}
for (j = 0 ; j < i ; ++j) {
close(fd[j]);
}
return i;
}

int main (int argc, char *argv[]) {
int n, na;
int i;
void *addr;

size = 3072;
fd = malloc((size + 1) * sizeof(*fd));
if (fd == NULL) {
fprintf (stderr, "Can't allocate: %s\n", strerror(errno));
return 1;
}
n = eatallfds();
printf ("Was able to use %d file descriptors\n", n);

na = 0;
for (i = 1 ; i < argc ; ++i) {
addr = pg_dlopen(argv[i]);
if (addr != NULL) na++;
}
n = eatallfds();
printf ("Was able to use %d file descriptors after opening %d
shared libs\n", n, na);
return 0;
}

$

--
Larry Rosenman http://www.lerctr.org/~ler
Phone: +1 972-414-9812 E-Mail: ler(at)lerctr(dot)org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dave Cramer 2004-02-23 12:41:18 Re: Pl/Java - next step?
Previous Message Ramanujam H S Iyengar 2004-02-23 10:47:19 Stop rescan of inner relation in NestLoop ?