diff options
Diffstat (limited to 'fs/file_table.c')
-rw-r--r-- | fs/file_table.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/fs/file_table.c b/fs/file_table.c index 5ad0eca6eea2..bbeeac6efa1a 100644 --- a/fs/file_table.c +++ b/fs/file_table.c | |||
@@ -32,11 +32,16 @@ struct files_stat_struct files_stat = { | |||
32 | /* public. Not pretty! */ | 32 | /* public. Not pretty! */ |
33 | __cacheline_aligned_in_smp DEFINE_SPINLOCK(files_lock); | 33 | __cacheline_aligned_in_smp DEFINE_SPINLOCK(files_lock); |
34 | 34 | ||
35 | /* SLAB cache for file structures */ | ||
36 | static struct kmem_cache *filp_cachep __read_mostly; | ||
37 | |||
35 | static struct percpu_counter nr_files __cacheline_aligned_in_smp; | 38 | static struct percpu_counter nr_files __cacheline_aligned_in_smp; |
36 | 39 | ||
37 | static inline void file_free_rcu(struct rcu_head *head) | 40 | static inline void file_free_rcu(struct rcu_head *head) |
38 | { | 41 | { |
39 | struct file *f = container_of(head, struct file, f_u.fu_rcuhead); | 42 | struct file *f = container_of(head, struct file, f_u.fu_rcuhead); |
43 | |||
44 | put_cred(f->f_cred); | ||
40 | kmem_cache_free(filp_cachep, f); | 45 | kmem_cache_free(filp_cachep, f); |
41 | } | 46 | } |
42 | 47 | ||
@@ -94,7 +99,7 @@ int proc_nr_files(ctl_table *table, int write, struct file *filp, | |||
94 | */ | 99 | */ |
95 | struct file *get_empty_filp(void) | 100 | struct file *get_empty_filp(void) |
96 | { | 101 | { |
97 | struct task_struct *tsk; | 102 | const struct cred *cred = current_cred(); |
98 | static int old_max; | 103 | static int old_max; |
99 | struct file * f; | 104 | struct file * f; |
100 | 105 | ||
@@ -118,12 +123,10 @@ struct file *get_empty_filp(void) | |||
118 | if (security_file_alloc(f)) | 123 | if (security_file_alloc(f)) |
119 | goto fail_sec; | 124 | goto fail_sec; |
120 | 125 | ||
121 | tsk = current; | ||
122 | INIT_LIST_HEAD(&f->f_u.fu_list); | 126 | INIT_LIST_HEAD(&f->f_u.fu_list); |
123 | atomic_long_set(&f->f_count, 1); | 127 | atomic_long_set(&f->f_count, 1); |
124 | rwlock_init(&f->f_owner.lock); | 128 | rwlock_init(&f->f_owner.lock); |
125 | f->f_uid = tsk->fsuid; | 129 | f->f_cred = get_cred(cred); |
126 | f->f_gid = tsk->fsgid; | ||
127 | eventpoll_init_file(f); | 130 | eventpoll_init_file(f); |
128 | /* f->f_version: 0 */ | 131 | /* f->f_version: 0 */ |
129 | return f; | 132 | return f; |
@@ -397,7 +400,12 @@ too_bad: | |||
397 | void __init files_init(unsigned long mempages) | 400 | void __init files_init(unsigned long mempages) |
398 | { | 401 | { |
399 | int n; | 402 | int n; |
400 | /* One file with associated inode and dcache is very roughly 1K. | 403 | |
404 | filp_cachep = kmem_cache_create("filp", sizeof(struct file), 0, | ||
405 | SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL); | ||
406 | |||
407 | /* | ||
408 | * One file with associated inode and dcache is very roughly 1K. | ||
401 | * Per default don't use more than 10% of our memory for files. | 409 | * Per default don't use more than 10% of our memory for files. |
402 | */ | 410 | */ |
403 | 411 | ||