lkml.org 
[lkml]   [2012]   [Apr]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] nextfd(2)
From
Date
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().






\
 
 \ /
  Last update: 2012-04-01 17:45    [from the cache]
©2003-2011 Jasper Spaans