阅读0.11版的内核源码时,在linux-0.11/fs/pipe.c中,函数sys_pipe()里面出现了2个宏定义,NR_OPEN 与 NR_FILE。下面说明一下它们的区别:
1. NR_OPEN is the maximum number of files that can be opened by process。
NR_OPEN是一个进程可以打开的最大文件数。
A process cannot use more than NR_OPEN file descriptors.
一个进程不能使用超过NR_OPEN文件描述符。
The kernel also enforces a dynamic bound on the maximum number of file descriptors in the signal-<rlim[RLIMIT_NOFILE] structure of the process descriptor; this value is usually 1,024, but it can be raised if the process has root privileges.
2. NR_FILE is the limit on total number of files in the system at any given point in time
NR_FILE 是系统在某一给定时刻,限制的文件总数
While initializing the kernel we setup the vfs cache with
start_kernel
vfs_caches_init(num_physpages);
files_init(mempages);
fs/file_table.c says
/* 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;
this n can never be greater than NR_FILE
原文