Sungju's Slow Life

Personal journal


How many files can be opened on my linux machine at a time?

Basically, each process has a limit as 1024. You can check and change this with ulimit command.

However, it does not change the overall counts of opened files on the machine. This is done with /proc/sys/fs/files-max.

This file’s value is set dynamically with available memory on the boot time, but, you change this later.

Related stuff for this tunnable varialbe is located at the fs/file_table.c


348void __init files_init(unsigned long mempages)
349{
350 int n;
351 /* One file with associated inode and dcache is very roughly 1K.
352 * Per default don't use more than 10% of our memory for files.
353 */
354
355 n = (mempages * (PAGE_SIZE / 1024)) / 10;
356 files_stat.max_files = n;
357 if (files_stat.max_files < NR_FILE)
358 files_stat.max_files = NR_FILE;
359 files_defer_init();
360 percpu_counter_init(&nr_files, 0);
361}
362

It basically set to spent less than 10% of the available memory.



Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About Me

A software engineer who loves any technologies that makes life easier. That’s why I love Linux and Mac at the same time.

Newsletter

%d bloggers like this: