diff options
author | Mel Gorman <mgorman@suse.de> | 2015-08-06 18:46:20 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-08-06 21:39:40 -0400 |
commit | 4248b0da460839e30eaaad78992b9a1dd3e63e21 (patch) | |
tree | 795b2e5253b15d6a75a4a0dc0d8fe13b50a6060e /fs/file_table.c | |
parent | d3cd131d935ab3bab700491edbbd7cad4040ce50 (diff) |
fs, file table: reinit files_stat.max_files after deferred memory initialisation
Dave Hansen reported the following;
My laptop has been behaving strangely with 4.2-rc2. Once I log
in to my X session, I start getting all kinds of strange errors
from applications and see this in my dmesg:
VFS: file-max limit 8192 reached
The problem is that the file-max is calculated before memory is fully
initialised and miscalculates how much memory the kernel is using. This
patch recalculates file-max after deferred memory initialisation. Note
that using memory hotplug infrastructure would not have avoided this
problem as the value is not recalculated after memory hot-add.
4.1: files_stat.max_files = 6582781
4.2-rc2: files_stat.max_files = 8192
4.2-rc2 patched: files_stat.max_files = 6562467
Small differences with the patch applied and 4.1 but not enough to matter.
Signed-off-by: Mel Gorman <mgorman@suse.de>
Reported-by: Dave Hansen <dave.hansen@intel.com>
Cc: Nicolai Stange <nicstange@gmail.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Alex Ng <alexng@microsoft.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
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 | } |