History

fs: add fget_many() and fput_many()

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.

Jens Axboe committed 7 years ago

Commit 091141a1 parent def596e4 files · +22 −8Browse files

Showing the changes to include/linux (2 of 4 files). Show all

Unified · Split

2 files
  1. include/linux/file.h +2 −0
  2. include/linux/fs.h +3 −1
include/linux/file.h+2−0
@@ -13,6 +13,7 @@ · 12 unmodified lines
13struct file;13struct file;
14 14
15extern void fput(struct file *);15extern void fput(struct file *);
16extern void fput_many(struct file *, unsigned int);
16 17
17struct file_operations;18struct file_operations;
18struct vfsmount;19struct vfsmount;
@@ -44,6 +45,7 @@ static inline void fdput(struct fd fd) · 25 unmodified lines
44}45}
45 46
46extern struct file *fget(unsigned int fd);47extern struct file *fget(unsigned int fd);
48extern struct file *fget_many(unsigned int fd, unsigned int refs);
47extern struct file *fget_raw(unsigned int fd);49extern struct file *fget_raw(unsigned int fd);
48extern unsigned long __fdget(unsigned int fd);50extern unsigned long __fdget(unsigned int fd);
49extern unsigned long __fdget_raw(unsigned int fd);51extern unsigned long __fdget_raw(unsigned int fd);
include/linux/fs.h+3−1
@@ -952,7 +952,9 @@ static inline struct file *get_file(struct file *f) · 951 unmodified lines
952 atomic_long_inc(&f->f_count);952 atomic_long_inc(&f->f_count);
953 return f;953 return f;
954}954}
955#define get_file_rcu(x) atomic_long_inc_not_zero(&(x)->f_count)955#define get_file_rcu_many(x, cnt) \
956 atomic_long_add_unless(&(x)->f_count, (cnt), 0)
957#define get_file_rcu(x) get_file_rcu_many((x), 1)
956#define fput_atomic(x) atomic_long_add_unless(&(x)->f_count, -1, 1)958#define fput_atomic(x) atomic_long_add_unless(&(x)->f_count, -1, 1)
957#define file_count(x) atomic_long_read(&(x)->f_count)959#define file_count(x) atomic_long_read(&(x)->f_count)
958 960

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t