/proc/sys/fs/file-max


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.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM