| Subject | Re: [PATCH] nextfd(2) | From | Eric Dumazet <> | Date | Sun, 01 Apr 2012 17:43:25 +0200 |
| |
On Sun, 2012-04-01 at 15:57 +0300, Alexey Dobriyan wrote:
> + > +/* Return first opened file descriptor which is >= than the argument. */ > +SYSCALL_DEFINE1(nextfd, unsigned int, fd) > +{ > + struct files_struct *files = current->files; > + struct fdtable *fdt; > + > + rcu_read_lock(); > + fdt = files_fdtable(files); > + while (fd < fdt->max_fds) { > + struct file *file; > + > + file = rcu_dereference_check_fdtable(files, fdt->fd[fd]); > + if (file) { > + rcu_read_unlock(); > + return fd; > + } > + fd++; > + } > + rcu_read_unlock(); > + return -ESRCH; > +}
Interesting idea but what about using fdt->open_fds bitmap to have a fast search and less cache pollution ?
alloc_fd(start, flags) uses find_next_zero_bit(), you could use find_next_bit().
|