mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 04:33:26 +02:00
vfs: make open_with_fake_path() not contribute to nr_files
Stacking file operations in overlay will store an extra open file for each overlay file opened. The overhead is just that of "struct file" which is about 256bytes, because overlay already pins an extra dentry and inode when the file is open, which add up to a much larger overhead. For fear of breaking working setups, don't start accounting the extra file. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
This commit is contained in:
@@ -52,7 +52,8 @@ static void file_free_rcu(struct rcu_head *head)
|
||||
static inline void file_free(struct file *f)
|
||||
{
|
||||
security_file_free(f);
|
||||
percpu_counter_dec(&nr_files);
|
||||
if (!(f->f_mode & FMODE_NOACCOUNT))
|
||||
percpu_counter_dec(&nr_files);
|
||||
call_rcu(&f->f_u.fu_rcuhead, file_free_rcu);
|
||||
}
|
||||
|
||||
@@ -91,34 +92,11 @@ int proc_nr_files(struct ctl_table *table, int write,
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Find an unused file structure and return a pointer to it.
|
||||
* Returns an error pointer if some error happend e.g. we over file
|
||||
* structures limit, run out of memory or operation is not permitted.
|
||||
*
|
||||
* Be very careful using this. You are responsible for
|
||||
* getting write access to any mount that you might assign
|
||||
* to this filp, if it is opened for write. If this is not
|
||||
* done, you will imbalance int the mount's writer count
|
||||
* and a warning at __fput() time.
|
||||
*/
|
||||
struct file *alloc_empty_file(int flags, const struct cred *cred)
|
||||
static struct file *__alloc_file(int flags, const struct cred *cred)
|
||||
{
|
||||
static long old_max;
|
||||
struct file *f;
|
||||
int error;
|
||||
|
||||
/*
|
||||
* Privileged users can go above max_files
|
||||
*/
|
||||
if (get_nr_files() >= files_stat.max_files && !capable(CAP_SYS_ADMIN)) {
|
||||
/*
|
||||
* percpu_counters are inaccurate. Do an expensive check before
|
||||
* we go and fail.
|
||||
*/
|
||||
if (percpu_counter_sum_positive(&nr_files) >= files_stat.max_files)
|
||||
goto over;
|
||||
}
|
||||
|
||||
f = kmem_cache_zalloc(filp_cachep, GFP_KERNEL);
|
||||
if (unlikely(!f))
|
||||
return ERR_PTR(-ENOMEM);
|
||||
@@ -138,7 +116,41 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
|
||||
f->f_flags = flags;
|
||||
f->f_mode = OPEN_FMODE(flags);
|
||||
/* f->f_version: 0 */
|
||||
percpu_counter_inc(&nr_files);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
/* Find an unused file structure and return a pointer to it.
|
||||
* Returns an error pointer if some error happend e.g. we over file
|
||||
* structures limit, run out of memory or operation is not permitted.
|
||||
*
|
||||
* Be very careful using this. You are responsible for
|
||||
* getting write access to any mount that you might assign
|
||||
* to this filp, if it is opened for write. If this is not
|
||||
* done, you will imbalance int the mount's writer count
|
||||
* and a warning at __fput() time.
|
||||
*/
|
||||
struct file *alloc_empty_file(int flags, const struct cred *cred)
|
||||
{
|
||||
static long old_max;
|
||||
struct file *f;
|
||||
|
||||
/*
|
||||
* Privileged users can go above max_files
|
||||
*/
|
||||
if (get_nr_files() >= files_stat.max_files && !capable(CAP_SYS_ADMIN)) {
|
||||
/*
|
||||
* percpu_counters are inaccurate. Do an expensive check before
|
||||
* we go and fail.
|
||||
*/
|
||||
if (percpu_counter_sum_positive(&nr_files) >= files_stat.max_files)
|
||||
goto over;
|
||||
}
|
||||
|
||||
f = __alloc_file(flags, cred);
|
||||
if (!IS_ERR(f))
|
||||
percpu_counter_inc(&nr_files);
|
||||
|
||||
return f;
|
||||
|
||||
over:
|
||||
@@ -150,6 +162,21 @@ over:
|
||||
return ERR_PTR(-ENFILE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Variant of alloc_empty_file() that doesn't check and modify nr_files.
|
||||
*
|
||||
* Should not be used unless there's a very good reason to do so.
|
||||
*/
|
||||
struct file *alloc_empty_file_noaccount(int flags, const struct cred *cred)
|
||||
{
|
||||
struct file *f = __alloc_file(flags, cred);
|
||||
|
||||
if (!IS_ERR(f))
|
||||
f->f_mode |= FMODE_NOACCOUNT;
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
/**
|
||||
* alloc_file - allocate and initialize a 'struct file'
|
||||
*
|
||||
|
Reference in New Issue
Block a user