diff options
Diffstat (limited to 'fs/file_table.c')
-rw-r--r-- | fs/file_table.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/fs/file_table.c b/fs/file_table.c index 7f9d407c7595..ad17e05ebf95 100644 --- a/fs/file_table.c +++ b/fs/file_table.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/hardirq.h> | 25 | #include <linux/hardirq.h> |
26 | #include <linux/task_work.h> | 26 | #include <linux/task_work.h> |
27 | #include <linux/ima.h> | 27 | #include <linux/ima.h> |
28 | #include <linux/swap.h> | ||
28 | 29 | ||
29 | #include <linux/atomic.h> | 30 | #include <linux/atomic.h> |
30 | 31 | ||
@@ -308,19 +309,24 @@ void put_filp(struct file *file) | |||
308 | } | 309 | } |
309 | } | 310 | } |
310 | 311 | ||
311 | void __init files_init(unsigned long mempages) | 312 | void __init files_init(void) |
312 | { | 313 | { |
313 | unsigned long n; | ||
314 | |||
315 | filp_cachep = kmem_cache_create("filp", sizeof(struct file), 0, | 314 | filp_cachep = kmem_cache_create("filp", sizeof(struct file), 0, |
316 | SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL); | 315 | SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL); |
316 | percpu_counter_init(&nr_files, 0, GFP_KERNEL); | ||
317 | } | ||
317 | 318 | ||
318 | /* | 319 | /* |
319 | * One file with associated inode and dcache is very roughly 1K. | 320 | * One file with associated inode and dcache is very roughly 1K. Per default |
320 | * Per default don't use more than 10% of our memory for files. | 321 | * do not use more than 10% of our memory for files. |
321 | */ | 322 | */ |
323 | void __init files_maxfiles_init(void) | ||
324 | { | ||
325 | unsigned long n; | ||
326 | unsigned long memreserve = (totalram_pages - nr_free_pages()) * 3/2; | ||
327 | |||
328 | memreserve = min(memreserve, totalram_pages - 1); | ||
329 | n = ((totalram_pages - memreserve) * (PAGE_SIZE / 1024)) / 10; | ||
322 | 330 | ||
323 | n = (mempages * (PAGE_SIZE / 1024)) / 10; | ||
324 | files_stat.max_files = max_t(unsigned long, n, NR_FILE); | 331 | files_stat.max_files = max_t(unsigned long, n, NR_FILE); |
325 | percpu_counter_init(&nr_files, 0, GFP_KERNEL); | ||
326 | } | 332 | } |