Upper limit of file descriptor in Linux

后端 未结 2 836
一生所求
一生所求 2021-02-05 19:38

what is the upper limit of file-descriptor that can be used in any Linux system (specifically ubuntu 10.04)?

I am using Ubuntu 10.04 (64-bit) and my CPU architecture fo

相关标签:
2条回答
  • 2021-02-05 19:56

    You want to look at /proc/sys/fs/file-max instead.

    From the recent linux/Documentation/sysctl/fs.txt:

    file-max and file-nr:

    The kernel allocates file handles dynamically, but as yet it doesn't free them again.

    The value in file-max denotes the maximum number of file- handles that the Linux kernel will allocate. When you get lots of error messages about running out of file handles, you might want to increase this limit.

    Historically, the three values in file-nr denoted the number of allocated file handles, the number of allocated but unused file handles, and the maximum number of file handles. Linux 2.6 always reports 0 as the number of free file handles -- this is not an error, it just means that the number of allocated file handles exactly matches the number of used file handles.

    Attempts to allocate more file descriptors than file-max are reported with printk, look for "VFS: file-max limit reached".

    The 2.6 kernel uses a rule of thumb to set file-max based on the amount of memory in the system. A snippet from fs/file_table.c in the 2.6 kernel:

    /*
     * One file with associated inode and dcache is very roughly 1K.
     * Per default don't use more than 10% of our memory for files. 
     */ 
    
    n = (mempages * (PAGE_SIZE / 1024)) / 10;
    files_stat.max_files = max_t(unsigned long, n, NR_FILE);
    

    The files_stat.max_files is the setting of fs.file-max. This ends up being about 100 for every 1MB of ram.(10%)

    0 讨论(0)
  • 2021-02-05 20:10

    Each file descriptor takes up some kernel memory, so at some point you'll exhaust it. That being said, up to a hundred thousand file descriptors are not unheard of for server deployments where event-based (epoll on Linux) server architectures are used. So 400k is not completely unreasonable.

    For the second questions, see /proc/PID/fd/ or /proc/PID/fdinfo directories.

    0 讨论(0)
提交回复
热议问题