Upper limit of file descriptor in Linux

后端 未结 2 822
一生所求
一生所求 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%)

提交回复
热议问题