mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 11:11:45 -04:00
[PATCH] files: lock-free fd look-up
With the use of RCU in files structure, the look-up of files using fds can now be lock-free. The lookup is protected by rcu_read_lock()/rcu_read_unlock(). This patch changes the readers to use lock-free lookup. Signed-off-by: Maneesh Soni <[email protected]> Signed-off-by: Ravikiran Thirumalai <[email protected]> Signed-off-by: Dipankar Sarma <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
ab2af1f500
commit
b835996f62
9 changed files with 39 additions and 27 deletions
13
fs/select.c
13
fs/select.c
|
|
@ -22,6 +22,7 @@
|
|||
#include <linux/personality.h> /* for STICKY_TIMEOUTS */
|
||||
#include <linux/file.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/rcupdate.h>
|
||||
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
|
|
@ -185,9 +186,9 @@ int do_select(int n, fd_set_bits *fds, long *timeout)
|
|||
int retval, i;
|
||||
long __timeout = *timeout;
|
||||
|
||||
spin_lock(¤t->files->file_lock);
|
||||
rcu_read_lock();
|
||||
retval = max_select_fd(n, fds);
|
||||
spin_unlock(¤t->files->file_lock);
|
||||
rcu_read_unlock();
|
||||
|
||||
if (retval < 0)
|
||||
return retval;
|
||||
|
|
@ -329,8 +330,10 @@ sys_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, s
|
|||
goto out_nofds;
|
||||
|
||||
/* max_fdset can increase, so grab it once to avoid race */
|
||||
rcu_read_lock();
|
||||
fdt = files_fdtable(current->files);
|
||||
max_fdset = fdt->max_fdset;
|
||||
rcu_read_unlock();
|
||||
if (n > max_fdset)
|
||||
n = max_fdset;
|
||||
|
||||
|
|
@ -469,10 +472,14 @@ asmlinkage long sys_poll(struct pollfd __user * ufds, unsigned int nfds, long ti
|
|||
struct poll_list *head;
|
||||
struct poll_list *walk;
|
||||
struct fdtable *fdt;
|
||||
int max_fdset;
|
||||
|
||||
/* Do a sanity check on nfds ... */
|
||||
rcu_read_lock();
|
||||
fdt = files_fdtable(current->files);
|
||||
if (nfds > fdt->max_fdset && nfds > OPEN_MAX)
|
||||
max_fdset = fdt->max_fdset;
|
||||
rcu_read_unlock();
|
||||
if (nfds > max_fdset && nfds > OPEN_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
if (timeout) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue