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 /include | |
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 'include')
-rw-r--r-- | include/linux/file.h | 2 | ||||
-rw-r--r-- | include/linux/fs.h | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/include/linux/file.h b/include/linux/file.h index 6b2fb032416c..3fcddff56bc4 100644 --- a/include/linux/file.h +++ b/include/linux/file.h @@ -13,6 +13,7 @@ struct file; extern void fput(struct file *); +extern void fput_many(struct file *, unsigned int); struct file_operations; struct vfsmount; @@ -44,6 +45,7 @@ static inline void fdput(struct fd 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 unsigned long __fdget(unsigned int fd); extern unsigned long __fdget_raw(unsigned int fd); diff --git a/include/linux/fs.h b/include/linux/fs.h index b6a955ba6173..86f884e78b6b 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -942,7 +942,9 @@ static inline struct file *get_file(struct file *f) atomic_long_inc(&f->f_count); return f; } -#define get_file_rcu(x) atomic_long_inc_not_zero(&(x)->f_count) +#define get_file_rcu_many(x, cnt) \ + atomic_long_add_unless(&(x)->f_count, (cnt), 0) +#define get_file_rcu(x) get_file_rcu_many((x), 1) #define fput_atomic(x) atomic_long_add_unless(&(x)->f_count, -1, 1) #define file_count(x) atomic_long_read(&(x)->f_count) |