diff options
author | Jens Axboe <axboe@kernel.dk> | 2018-11-21 10:32:39 -0700 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2021-12-08 08:50:13 +0100 |
commit | 895538f9d351d3152248708a112143d4917f5a0b (patch) | |
tree | ff8d54201544f6c24f0f39b2627e9a328a874002 /fs/file_table.c | |
parent | 4f9a4d5708b5ef3de0fbf002aac97fbbf84f0226 (diff) | |
download | linux-stable-895538f9d351d3152248708a112143d4917f5a0b.tar.gz linux-stable-895538f9d351d3152248708a112143d4917f5a0b.tar.bz2 linux-stable-895538f9d351d3152248708a112143d4917f5a0b.zip |
fs: add fget_many() and fput_many()
commit 091141a42e15fe47ada737f3996b317072afcefb upstream.
Some uses cases repeatedly get and put references to the same file, but
the only exposed interface is doing these one at the time. As each of
these entail an atomic inc or dec on a shared structure, that cost can
add up.
Add fget_many(), which works just like fget(), except it takes an
argument for how many references to get on the file. Ditto fput_many(),
which can drop an arbitrary number of references to a file.
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/file_table.c')
-rw-r--r-- | fs/file_table.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/fs/file_table.c b/fs/file_table.c index e49af4caf15d..6a715639728d 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -326,9 +326,9 @@ void flush_delayed_fput(void) static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput); -void fput(struct file *file) +void fput_many(struct file *file, unsigned int refs) { - if (atomic_long_dec_and_test(&file->f_count)) { + if (atomic_long_sub_and_test(refs, &file->f_count)) { struct task_struct *task = current; if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) { @@ -347,6 +347,11 @@ void fput(struct file *file) } } +void fput(struct file *file) +{ + fput_many(file, 1); +} + /* * synchronous analog of fput(); for kernel threads that might be needed * in some umount() (and thus can't use flush_delayed_fput() without |