Skip to content

Commit 81132a3

Browse files
Gou HaoAl Viro
authored andcommitted
fs: remove fget_many and fput_many interface
These two interface were added in 091141a commit, but now there is no place to call them. The only user of fput/fget_many() was removed in commit 62906e8 ("io_uring: remove file batch-get optimisation"). A user of get_file_rcu_many() were removed in commit f073531 ("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: Gou Hao <gouhao@uniontech.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 4329490 commit 81132a3

File tree

4 files changed

+16
-32
lines changed

4 files changed

+16
-32
lines changed

fs/file.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ void do_close_on_exec(struct files_struct *files)
871871
}
872872

873873
static inline struct file *__fget_files_rcu(struct files_struct *files,
874-
unsigned int fd, fmode_t mask, unsigned int refs)
874+
unsigned int fd, fmode_t mask)
875875
{
876876
for (;;) {
877877
struct file *file;
@@ -897,10 +897,9 @@ static inline struct file *__fget_files_rcu(struct files_struct *files,
897897
* Such a race can take two forms:
898898
*
899899
* (a) the file ref already went down to zero,
900-
* and get_file_rcu_many() fails. Just try
901-
* again:
900+
* and get_file_rcu() fails. Just try again:
902901
*/
903-
if (unlikely(!get_file_rcu_many(file, refs)))
902+
if (unlikely(!get_file_rcu(file)))
904903
continue;
905904

906905
/*
@@ -909,11 +908,11 @@ static inline struct file *__fget_files_rcu(struct files_struct *files,
909908
* pointer having changed, because it always goes
910909
* hand-in-hand with 'fdt'.
911910
*
912-
* If so, we need to put our refs and try again.
911+
* If so, we need to put our ref and try again.
913912
*/
914913
if (unlikely(rcu_dereference_raw(files->fdt) != fdt) ||
915914
unlikely(rcu_dereference_raw(*fdentry) != file)) {
916-
fput_many(file, refs);
915+
fput(file);
917916
continue;
918917
}
919918

@@ -926,37 +925,31 @@ static inline struct file *__fget_files_rcu(struct files_struct *files,
926925
}
927926

928927
static struct file *__fget_files(struct files_struct *files, unsigned int fd,
929-
fmode_t mask, unsigned int refs)
928+
fmode_t mask)
930929
{
931930
struct file *file;
932931

933932
rcu_read_lock();
934-
file = __fget_files_rcu(files, fd, mask, refs);
933+
file = __fget_files_rcu(files, fd, mask);
935934
rcu_read_unlock();
936935

937936
return file;
938937
}
939938

940-
static inline struct file *__fget(unsigned int fd, fmode_t mask,
941-
unsigned int refs)
942-
{
943-
return __fget_files(current->files, fd, mask, refs);
944-
}
945-
946-
struct file *fget_many(unsigned int fd, unsigned int refs)
939+
static inline struct file *__fget(unsigned int fd, fmode_t mask)
947940
{
948-
return __fget(fd, FMODE_PATH, refs);
941+
return __fget_files(current->files, fd, mask);
949942
}
950943

951944
struct file *fget(unsigned int fd)
952945
{
953-
return __fget(fd, FMODE_PATH, 1);
946+
return __fget(fd, FMODE_PATH);
954947
}
955948
EXPORT_SYMBOL(fget);
956949

957950
struct file *fget_raw(unsigned int fd)
958951
{
959-
return __fget(fd, 0, 1);
952+
return __fget(fd, 0);
960953
}
961954
EXPORT_SYMBOL(fget_raw);
962955

@@ -966,7 +959,7 @@ struct file *fget_task(struct task_struct *task, unsigned int fd)
966959

967960
task_lock(task);
968961
if (task->files)
969-
file = __fget_files(task->files, fd, 0, 1);
962+
file = __fget_files(task->files, fd, 0);
970963
task_unlock(task);
971964

972965
return file;
@@ -1035,7 +1028,7 @@ static unsigned long __fget_light(unsigned int fd, fmode_t mask)
10351028
return 0;
10361029
return (unsigned long)file;
10371030
} else {
1038-
file = __fget(fd, mask, 1);
1031+
file = __fget(fd, mask);
10391032
if (!file)
10401033
return 0;
10411034
return FDPUT_FPUT | (unsigned long)file;

fs/file_table.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,9 @@ EXPORT_SYMBOL_GPL(flush_delayed_fput);
368368

369369
static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
370370

371-
void fput_many(struct file *file, unsigned int refs)
371+
void fput(struct file *file)
372372
{
373-
if (atomic_long_sub_and_test(refs, &file->f_count)) {
373+
if (atomic_long_dec_and_test(&file->f_count)) {
374374
struct task_struct *task = current;
375375

376376
if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) {
@@ -389,11 +389,6 @@ void fput_many(struct file *file, unsigned int refs)
389389
}
390390
}
391391

392-
void fput(struct file *file)
393-
{
394-
fput_many(file, 1);
395-
}
396-
397392
/*
398393
* synchronous analog of fput(); for kernel threads that might be needed
399394
* in some umount() (and thus can't use flush_delayed_fput() without

include/linux/file.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
struct file;
1515

1616
extern void fput(struct file *);
17-
extern void fput_many(struct file *, unsigned int);
1817

1918
struct file_operations;
2019
struct task_struct;
@@ -47,7 +46,6 @@ static inline void fdput(struct fd fd)
4746
}
4847

4948
extern struct file *fget(unsigned int fd);
50-
extern struct file *fget_many(unsigned int fd, unsigned int refs);
5149
extern struct file *fget_raw(unsigned int fd);
5250
extern struct file *fget_task(struct task_struct *task, unsigned int fd);
5351
extern unsigned long __fdget(unsigned int fd);

include/linux/fs.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -981,9 +981,7 @@ static inline struct file *get_file(struct file *f)
981981
atomic_long_inc(&f->f_count);
982982
return f;
983983
}
984-
#define get_file_rcu_many(x, cnt) \
985-
atomic_long_add_unless(&(x)->f_count, (cnt), 0)
986-
#define get_file_rcu(x) get_file_rcu_many((x), 1)
984+
#define get_file_rcu(x) atomic_long_inc_not_zero(&(x)->f_count)
987985
#define file_count(x) atomic_long_read(&(x)->f_count)
988986

989987
#define MAX_NON_LFS ((1UL<<31) - 1)

0 commit comments

Comments
 (0)