Linux的/proc/sys/fs/file max決定了當前內核可以打開的最大的文件句柄數。 查看當前的值: 這個值在kernel的文檔里是這樣描述的: 意思是file max一般為記憶體大小(KB)的10%來計算,如果使用shell,可以這樣計算: 一般我們不需要主動設置這個值,除非這個值確實較 ...
Linux的/proc/sys/fs/file-max決定了當前內核可以打開的最大的文件句柄數。
查看當前的值:
cat /proc/sys/fs/file-max
這個值在kernel的文檔里是這樣描述的:
The value in file-max denotes the maximum number of file handles that the
Linux kernel will allocate. When you get a lot of error messages about running
out of file handles, you might want to raise this limit. The default value is
10% of RAM in kilobytes. To change it, just write the new number into the
file:
意思是file-max一般為記憶體大小(KB)的10%來計算,如果使用shell,可以這樣計算:
grep -r MemTotal /proc/meminfo | awk '{printf("%d",$2/10)}'
一般我們不需要主動設置這個值,除非這個值確實較小(可能有各種其他原因導致file-max沒有設置為記憶體的10%)
如何查看當前kernel的句柄:
cat /proc/sys/fs/file-nr
file-nr在內核文檔里得解釋如下:
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.