Sam*_*mpo 11 linux limit open-files files
在 Linux 中可以配置的最大打开文件数是否有(技术或实际)限制?如果将其配置为非常大的数字(例如 1-100M),是否会产生一些不利影响?
我在这里考虑使用服务器,而不是嵌入式系统。使用大量打开文件的程序当然会消耗内存并且速度很慢,但是如果限制配置得比所需的大得多(例如,仅配置消耗的内存),我对不利影响很感兴趣。
小智 10
I suspect the main reason for the limit is to avoid excess memory consumption (each open file descriptor uses kernel memory). It also serves as a safeguard against buggy applications leaking file descriptors and consuming system resources.
But given how absurdly much RAM modern systems have compared to systems 10 years ago, I think the defaults today are quite low.
2011 年,Linux 上文件描述符的默认硬限制从 1024 增加到 4096。
某些软件(例如 MongoDB)使用的文件描述符比默认限制多得多。MongoDB 人员建议将此限制提高到 64,000。rlimit_nofile
对于某些应用程序,我使用了300,000。
只要您将软限制保持在默认值 (1024),增加硬限制可能是相当安全的。程序必须调用setrlimit()
才能将其限制提高到软限制之上,并且仍然受到硬限制的限制。
另请参阅一些相关问题:
从技术上讲,它仅限于 unsigned long (C Lang) 的最大值,即 4,294,967,295
参考:fs.h
文件
/* And dynamically-tunable limits and defaults: */
struct files_stat_struct {
unsigned long nr_files; /* read only */
unsigned long nr_free_files; /* read only */
unsigned long max_files; /* tunable THIS IS OUR VALUE */
};
Run Code Online (Sandbox Code Playgroud)