我知道/proc/sys/fs/ file -max定义了打开的文件描述符的最大数量,并且可以在运行时或引导期间设置。
然而:它的默认值是什么?在我的公司检查10台服务器给了我7个不同的值,这看起来都是随机的。
内核文档只是不断地提到可以更改该值--但不知道默认值是如何计算的。
你们中有人知道默认值是如何确定的吗?
发布于 2015-08-25 10:37:23
您在file-max
下看到的proc fs
限制是"./include/linux/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 */
};
现在,在./fs/file_table.c
中开始使用files_stat_struct
:
struct files_stat_struct files_stat = {
.max_files = NR_FILE /* This constant is 8192 */
};
现在,在前面的文件中,"./fs/file_table.c"
将具有一个函数,该函数将使真正的作业
void __init files_init(unsigned long mempages)
{
unsigned long n;
filp_cachep = kmem_cache_create("filp", sizeof(struct file), 0,
SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL);
/*
* 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;
files_stat.max_files = max_t(unsigned long, n, NR_FILE);
files_defer_init();
lg_lock_init(files_lglock);
percpu_counter_init(&nr_files, 0);
}
根据我在files_init
中看到的内容和宏max_t
,如果10%的文件内存大于8192,那么该值将被使用,除非是8192。
files_init是在内核开始执行时使用的,当调用kmem_cache_create
创建通用文件块缓存时,您需要看到标志SLAB_PANIC。
现在你需要看上去像./kernel/sysctl.c
{
.procname = "file-max",
.data = &files_stat.max_files,
.maxlen = sizeof(files_stat.max_files),
.mode = 0644,
.proc_handler = proc_doulongvec_minmax,
},
文件的最大值是10%的内存,如果你的系统有不同的内存大小,我认为这是正常的。
https://serverfault.com/questions/716578
复制相似问题