How does RHEL 5 (Linux kernel 2.6.18) determine the default fs.file-max setting

max-file-descriptorsrhel5

If fs.file-max is not set in /etc/sysctl.conf on RHEL 5 or its derivatives, how does the kernel determine the default value? Is there a formula used to set the fs.file-max value based on the amount of system RAM? I checked a number of random RHEL servers running the same OS level, but with different hardware configurations, and cat /proc/sys/fs/file-max shows different values on each system.

Best Answer

I'll answer my own question: the Linux 2.6 kernel sets the open file limit to 10% of the available memory.

Source: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=fs/file_table.c

 488 void __init files_init(unsigned long mempages)
 489 { 
 490         int n; 
 491 
 492         filp_cachep = kmem_cache_create("filp", sizeof(struct file), 0,
 493                         SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL);
 494 
 495         /*
 496          * One file with associated inode and dcache is very roughly 1K.
 497          * Per default don't use more than 10% of our memory for files. 
 498          */ 
 499 
 500         n = (mempages * (PAGE_SIZE / 1024)) / 10;
 501         files_stat.max_files = n; 
 502         if (files_stat.max_files < NR_FILE)
 503                 files_stat.max_files = NR_FILE;
 504         files_defer_init();
 505         lg_lock_init(files_lglock);
 506         percpu_counter_init(&nr_files, 0);
 507 }