Commit 81132a39 authored by Gou Hao's avatar Gou Hao Committed by Al Viro

fs: remove fget_many and fput_many interface

These two interface were added in 091141a4 commit,
but now there is no place to call them.

The only user of fput/fget_many() was removed in commit
62906e89 ("io_uring: remove file batch-get optimisation").

A user of get_file_rcu_many() were removed in commit
f0735310 ("init: add an init_dup helper").

And replace atomic_long_sub/add to atomic_long_dec/inc
can improve performance.

Here are the test results of unixbench:

Cmd: ./Run -c 64 context1

Without patch:
System Benchmarks Partial Index              BASELINE       RESULT    INDEX
Pipe-based Context Switching                   4000.0    2798407.0   6996.0
                                                                   ========
System Benchmarks Index Score (Partial Only)                         6996.0

With patch:
System Benchmarks Partial Index              BASELINE       RESULT    INDEX
Pipe-based Context Switching                   4000.0    3486268.8   8715.7
                                                                   ========
System Benchmarks Index Score (Partial Only)                         8715.7
Signed-off-by: default avatarGou Hao <gouhao@uniontech.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 4329490a
...@@ -871,7 +871,7 @@ void do_close_on_exec(struct files_struct *files) ...@@ -871,7 +871,7 @@ void do_close_on_exec(struct files_struct *files)
} }
static inline struct file *__fget_files_rcu(struct files_struct *files, static inline struct file *__fget_files_rcu(struct files_struct *files,
unsigned int fd, fmode_t mask, unsigned int refs) unsigned int fd, fmode_t mask)
{ {
for (;;) { for (;;) {
struct file *file; struct file *file;
...@@ -897,10 +897,9 @@ static inline struct file *__fget_files_rcu(struct files_struct *files, ...@@ -897,10 +897,9 @@ static inline struct file *__fget_files_rcu(struct files_struct *files,
* Such a race can take two forms: * Such a race can take two forms:
* *
* (a) the file ref already went down to zero, * (a) the file ref already went down to zero,
* and get_file_rcu_many() fails. Just try * and get_file_rcu() fails. Just try again:
* again:
*/ */
if (unlikely(!get_file_rcu_many(file, refs))) if (unlikely(!get_file_rcu(file)))
continue; continue;
/* /*
...@@ -909,11 +908,11 @@ static inline struct file *__fget_files_rcu(struct files_struct *files, ...@@ -909,11 +908,11 @@ static inline struct file *__fget_files_rcu(struct files_struct *files,
* pointer having changed, because it always goes * pointer having changed, because it always goes
* hand-in-hand with 'fdt'. * hand-in-hand with 'fdt'.
* *
* If so, we need to put our refs and try again. * If so, we need to put our ref and try again.
*/ */
if (unlikely(rcu_dereference_raw(files->fdt) != fdt) || if (unlikely(rcu_dereference_raw(files->fdt) != fdt) ||
unlikely(rcu_dereference_raw(*fdentry) != file)) { unlikely(rcu_dereference_raw(*fdentry) != file)) {
fput_many(file, refs); fput(file);
continue; continue;
} }
...@@ -926,37 +925,31 @@ static inline struct file *__fget_files_rcu(struct files_struct *files, ...@@ -926,37 +925,31 @@ static inline struct file *__fget_files_rcu(struct files_struct *files,
} }
static struct file *__fget_files(struct files_struct *files, unsigned int fd, static struct file *__fget_files(struct files_struct *files, unsigned int fd,
fmode_t mask, unsigned int refs) fmode_t mask)
{ {
struct file *file; struct file *file;
rcu_read_lock(); rcu_read_lock();
file = __fget_files_rcu(files, fd, mask, refs); file = __fget_files_rcu(files, fd, mask);
rcu_read_unlock(); rcu_read_unlock();
return file; return file;
} }
static inline struct file *__fget(unsigned int fd, fmode_t mask, static inline struct file *__fget(unsigned int fd, fmode_t mask)
unsigned int refs)
{
return __fget_files(current->files, fd, mask, refs);
}
struct file *fget_many(unsigned int fd, unsigned int refs)
{ {
return __fget(fd, FMODE_PATH, refs); return __fget_files(current->files, fd, mask);
} }
struct file *fget(unsigned int fd) struct file *fget(unsigned int fd)
{ {
return __fget(fd, FMODE_PATH, 1); return __fget(fd, FMODE_PATH);
} }
EXPORT_SYMBOL(fget); EXPORT_SYMBOL(fget);
struct file *fget_raw(unsigned int fd) struct file *fget_raw(unsigned int fd)
{ {
return __fget(fd, 0, 1); return __fget(fd, 0);
} }
EXPORT_SYMBOL(fget_raw); EXPORT_SYMBOL(fget_raw);
...@@ -966,7 +959,7 @@ struct file *fget_task(struct task_struct *task, unsigned int fd) ...@@ -966,7 +959,7 @@ struct file *fget_task(struct task_struct *task, unsigned int fd)
task_lock(task); task_lock(task);
if (task->files) if (task->files)
file = __fget_files(task->files, fd, 0, 1); file = __fget_files(task->files, fd, 0);
task_unlock(task); task_unlock(task);
return file; return file;
...@@ -1035,7 +1028,7 @@ static unsigned long __fget_light(unsigned int fd, fmode_t mask) ...@@ -1035,7 +1028,7 @@ static unsigned long __fget_light(unsigned int fd, fmode_t mask)
return 0; return 0;
return (unsigned long)file; return (unsigned long)file;
} else { } else {
file = __fget(fd, mask, 1); file = __fget(fd, mask);
if (!file) if (!file)
return 0; return 0;
return FDPUT_FPUT | (unsigned long)file; return FDPUT_FPUT | (unsigned long)file;
......
...@@ -368,9 +368,9 @@ EXPORT_SYMBOL_GPL(flush_delayed_fput); ...@@ -368,9 +368,9 @@ EXPORT_SYMBOL_GPL(flush_delayed_fput);
static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput); static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
void fput_many(struct file *file, unsigned int refs) void fput(struct file *file)
{ {
if (atomic_long_sub_and_test(refs, &file->f_count)) { if (atomic_long_dec_and_test(&file->f_count)) {
struct task_struct *task = current; struct task_struct *task = current;
if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) { if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) {
...@@ -389,11 +389,6 @@ void fput_many(struct file *file, unsigned int refs) ...@@ -389,11 +389,6 @@ void fput_many(struct file *file, unsigned int refs)
} }
} }
void fput(struct file *file)
{
fput_many(file, 1);
}
/* /*
* synchronous analog of fput(); for kernel threads that might be needed * synchronous analog of fput(); for kernel threads that might be needed
* in some umount() (and thus can't use flush_delayed_fput() without * in some umount() (and thus can't use flush_delayed_fput() without
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
struct file; struct file;
extern void fput(struct file *); extern void fput(struct file *);
extern void fput_many(struct file *, unsigned int);
struct file_operations; struct file_operations;
struct task_struct; struct task_struct;
...@@ -47,7 +46,6 @@ static inline void fdput(struct fd fd) ...@@ -47,7 +46,6 @@ static inline void fdput(struct fd fd)
} }
extern struct file *fget(unsigned int fd); extern struct file *fget(unsigned int fd);
extern struct file *fget_many(unsigned int fd, unsigned int refs);
extern struct file *fget_raw(unsigned int fd); extern struct file *fget_raw(unsigned int fd);
extern struct file *fget_task(struct task_struct *task, unsigned int fd); extern struct file *fget_task(struct task_struct *task, unsigned int fd);
extern unsigned long __fdget(unsigned int fd); extern unsigned long __fdget(unsigned int fd);
......
...@@ -981,9 +981,7 @@ static inline struct file *get_file(struct file *f) ...@@ -981,9 +981,7 @@ static inline struct file *get_file(struct file *f)
atomic_long_inc(&f->f_count); atomic_long_inc(&f->f_count);
return f; return f;
} }
#define get_file_rcu_many(x, cnt) \ #define get_file_rcu(x) atomic_long_inc_not_zero(&(x)->f_count)
atomic_long_add_unless(&(x)->f_count, (cnt), 0)
#define get_file_rcu(x) get_file_rcu_many((x), 1)
#define file_count(x) atomic_long_read(&(x)->f_count) #define file_count(x) atomic_long_read(&(x)->f_count)
#define MAX_NON_LFS ((1UL<<31) - 1) #define MAX_NON_LFS ((1UL<<31) - 1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment