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
1313 struct file;
1414
1515 extern void fput(struct file *);
16+extern void fput_many(struct file *, unsigned int);
1617
1718 struct file_operations;
1819 struct vfsmount;
@@ -44,6 +45,7 @@ static inline void fdput(struct fd fd) · 25 unmodified lines
4445 }
4546
4647 extern struct file *fget(unsigned int fd);
48+extern struct file *fget_many(unsigned int fd, unsigned int refs);
4749 extern struct file *fget_raw(unsigned int fd);
4850 extern unsigned long __fdget(unsigned int fd);
4951 extern 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
952952 atomic_long_inc(&f->f_count);
953953 return f;
954954 }
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)
956958 #define fput_atomic(x) atomic_long_add_unless(&(x)->f_count, -1, 1)
957959 #define file_count(x) atomic_long_read(&(x)->f_count)
958960

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