[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Opening 5000 file descriptors in linux??



Hi

Stephen Tweedie wrote:

> Two things: first of all, the default rlimit for open files is still
> 1024, so you need to raise that to use more in one process.  From bash,
> that's 
> 
> 	ulimit -Hn 100000; ulimit -n 100000

Done.

> or use the setrlimit() kernel call.
> 
> Secondly, the default FD_SET type only has space for 1024 fds in the
> bitmap, so either make sure you are using poll, or define your own,
> sufficiently large, FD_SET if you need to use select.
> 
> Other than that, all should work.

Interesting thing. Someone sent me a simple piece of code that they
were having problems with. Instead of opening /dev/null 5 million
times, they actually opened a network socket. Here is the code:

--------
#include <stdio.h>
#include <sys/socket.h>
main()
{
        int s;
        for(s = 0;; s++)
                if(socket(AF_INET,SOCK_STREAM,0) < 0)
                        break;
        printf("%d\n", s);
}
--------

This breaks much sooner than the ulimit value:

vi:~ # ./test 
508
vi:~ # ./test 
519
vi:~ # ./test 
519
<fiddle around with random things so that the system swaps>
vi:~ # ./test 
552

strace output:
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 552
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 553
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 554
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = -1 ENOBUFS (No buffer space
available)

no dmesg errors.

vi:~ # uname -a
Linux vi.qualica.com 2.2.5-ac1 #2 Sun Apr 4 14:26:31 SAST 1999 i586
unknown

If I add a second delay every 10 seconds, the system seems to free up
enough memory to get to around about 1000 filedescriptors. This points
to a resource management problem, IMHO.

I am not sure if the later ac-? patches do the same thing. I was out
of the country this last weekend.

Oskar
--
To unsubscribe, send a message with 'unsubscribe linux-mm my@address'
in the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/