diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2010-10-26 17:22:44 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-26 19:52:15 -0400 |
commit | 518de9b39e854542de59bfb8b9f61c8f7ecf808b (patch) | |
tree | 06cd1dd303a1526501783589ec61696570c0ffa8 /fs/file_table.c | |
parent | 571428be550fbe37160596995e96ad398873fcbd (diff) |
fs: allow for more than 2^31 files
Robin Holt tried to boot a 16TB system and found af_unix was overflowing
a 32bit value :
<quote>
We were seeing a failure which prevented boot. The kernel was incapable
of creating either a named pipe or unix domain socket. This comes down
to a common kernel function called unix_create1() which does:
atomic_inc(&unix_nr_socks);
if (atomic_read(&unix_nr_socks) > 2 * get_max_files())
goto out;
The function get_max_files() is a simple return of files_stat.max_files.
files_stat.max_files is a signed integer and is computed in
fs/file_table.c's files_init().
n = (mempages * (PAGE_SIZE / 1024)) / 10;
files_stat.max_files = n;
In our case, mempages (total_ram_pages) is approx 3,758,096,384
(0xe0000000). That leaves max_files at approximately 1,503,238,553.
This causes 2 * get_max_files() to integer overflow.
</quote>
Fix is to let /proc/sys/fs/file-nr & /proc/sys/fs/file-max use long
integers, and change af_unix to use an atomic_long_t instead of atomic_t.
get_max_files() is changed to return an unsigned long. get_nr_files() is
changed to return a long.
unix_nr_socks is changed from atomic_t to atomic_long_t, while not
strictly needed to address Robin problem.
Before patch (on a 64bit kernel) :
# echo 2147483648 >/proc/sys/fs/file-max
# cat /proc/sys/fs/file-max
-18446744071562067968
After patch:
# echo 2147483648 >/proc/sys/fs/file-max
# cat /proc/sys/fs/file-max
2147483648
# cat /proc/sys/fs/file-nr
704 0 2147483648
Reported-by: Robin Holt <holt@sgi.com>
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Acked-by: David Miller <davem@davemloft.net>
Reviewed-by: Robin Holt <holt@sgi.com>
Tested-by: Robin Holt <holt@sgi.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@lst.de>
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 | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/fs/file_table.c b/fs/file_table.c index a04bdd81c11c..c3dee381f1b4 100644 --- a/fs/file_table.c +++ b/fs/file_table.c | |||
@@ -60,7 +60,7 @@ static inline void file_free(struct file *f) | |||
60 | /* | 60 | /* |
61 | * Return the total number of open files in the system | 61 | * Return the total number of open files in the system |
62 | */ | 62 | */ |
63 | static int get_nr_files(void) | 63 | static long get_nr_files(void) |
64 | { | 64 | { |
65 | return percpu_counter_read_positive(&nr_files); | 65 | return percpu_counter_read_positive(&nr_files); |
66 | } | 66 | } |
@@ -68,7 +68,7 @@ static int get_nr_files(void) | |||
68 | /* | 68 | /* |
69 | * Return the maximum number of open files in the system | 69 | * Return the maximum number of open files in the system |
70 | */ | 70 | */ |
71 | int get_max_files(void) | 71 | unsigned long get_max_files(void) |
72 | { | 72 | { |
73 | return files_stat.max_files; | 73 | return files_stat.max_files; |
74 | } | 74 | } |
@@ -82,7 +82,7 @@ int proc_nr_files(ctl_table *table, int write, | |||
82 | void __user *buffer, size_t *lenp, loff_t *ppos) | 82 | void __user *buffer, size_t *lenp, loff_t *ppos) |
83 | { | 83 | { |
84 | files_stat.nr_files = get_nr_files(); | 84 | files_stat.nr_files = get_nr_files(); |
85 | return proc_dointvec(table, write, buffer, lenp, ppos); | 85 | return proc_doulongvec_minmax(table, write, buffer, lenp, ppos); |
86 | } | 86 | } |
87 | #else | 87 | #else |
88 | int proc_nr_files(ctl_table *table, int write, | 88 | int proc_nr_files(ctl_table *table, int write, |
@@ -105,7 +105,7 @@ int proc_nr_files(ctl_table *table, int write, | |||
105 | struct file *get_empty_filp(void) | 105 | struct file *get_empty_filp(void) |
106 | { | 106 | { |
107 | const struct cred *cred = current_cred(); | 107 | const struct cred *cred = current_cred(); |
108 | static int old_max; | 108 | static long old_max; |
109 | struct file * f; | 109 | struct file * f; |
110 | 110 | ||
111 | /* | 111 | /* |
@@ -140,8 +140,7 @@ struct file *get_empty_filp(void) | |||
140 | over: | 140 | over: |
141 | /* Ran out of filps - report that */ | 141 | /* Ran out of filps - report that */ |
142 | if (get_nr_files() > old_max) { | 142 | if (get_nr_files() > old_max) { |
143 | printk(KERN_INFO "VFS: file-max limit %d reached\n", | 143 | pr_info("VFS: file-max limit %lu reached\n", get_max_files()); |
144 | get_max_files()); | ||
145 | old_max = get_nr_files(); | 144 | old_max = get_nr_files(); |
146 | } | 145 | } |
147 | goto fail; | 146 | goto fail; |
@@ -487,7 +486,7 @@ retry: | |||
487 | 486 | ||
488 | void __init files_init(unsigned long mempages) | 487 | void __init files_init(unsigned long mempages) |
489 | { | 488 | { |
490 | int n; | 489 | unsigned long n; |
491 | 490 | ||
492 | filp_cachep = kmem_cache_create("filp", sizeof(struct file), 0, | 491 | filp_cachep = kmem_cache_create("filp", sizeof(struct file), 0, |
493 | SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL); | 492 | SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL); |
@@ -498,9 +497,7 @@ void __init files_init(unsigned long mempages) | |||
498 | */ | 497 | */ |
499 | 498 | ||
500 | n = (mempages * (PAGE_SIZE / 1024)) / 10; | 499 | n = (mempages * (PAGE_SIZE / 1024)) / 10; |
501 | files_stat.max_files = n; | 500 | files_stat.max_files = max_t(unsigned long, n, NR_FILE); |
502 | if (files_stat.max_files < NR_FILE) | ||
503 | files_stat.max_files = NR_FILE; | ||
504 | files_defer_init(); | 501 | files_defer_init(); |
505 | lg_lock_init(files_lglock); | 502 | lg_lock_init(files_lglock); |
506 | percpu_counter_init(&nr_files, 0); | 503 | percpu_counter_init(&nr_files, 0); |