lkml.org 
[lkml]   [2012]   [Apr]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH] nextfd(2)
    On Sun, Apr 01, 2012 at 05:43:25PM +0200, Eric Dumazet wrote:
    > 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().

    Indeed.
    I've copied code from /proc/*/fd implementation which does loop.


    \
     
     \ /
      Last update: 2012-04-01 23:35    [W:0.021 / U:89.784 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site