Re: [PATCH 1/2] open: add close_range()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
- Subject: Re: [PATCH 1/2] open: add close_range()
- From: David Howells <dhowells@xxxxxxxxxx>
- Date: Tue, 21 May 2019 17:30:27 +0100
- Cc: dhowells@xxxxxxxxxx, Christian Brauner <christian@xxxxxxxxxx>, linux-kernel@xxxxxxxxxxxxxxx, linux-fsdevel@xxxxxxxxxxxxxxx, linux-api@xxxxxxxxxxxxxxx, jannh@xxxxxxxxxx, fweimer@xxxxxxxxxx, oleg@xxxxxxxxxx, tglx@xxxxxxxxxxxxx, torvalds@xxxxxxxxxxxxxxxxxxxx, arnd@xxxxxxxx, shuah@xxxxxxxxxx, tkjos@xxxxxxxxxxx, ldv@xxxxxxxxxxxx, miklos@xxxxxxxxxx, linux-alpha@xxxxxxxxxxxxxxx, linux-arm-kernel@xxxxxxxxxxxxxxxxxxx, linux-ia64@xxxxxxxxxxxxxxx, linux-m68k@xxxxxxxxxxxxxxx, linux-mips@xxxxxxxxxxxxxxx, linux-parisc@xxxxxxxxxxxxxxx, linuxppc-dev@xxxxxxxxxxxxxxxx, linux-s390@xxxxxxxxxxxxxxx, linux-sh@xxxxxxxxxxxxxxx, sparclinux@xxxxxxxxxxxxxxx, linux-xtensa@xxxxxxxxxxxxxxxx, linux-arch@xxxxxxxxxxxxxxx, linux-kselftest@xxxxxxxxxxxxxxx, x86@xxxxxxxxxx
- In-reply-to: <20190521150006.GJ17978@ZenIV.linux.org.uk>
- Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903
- References: <20190521150006.GJ17978@ZenIV.linux.org.uk> <20190521113448.20654-1-christian@brauner.io>
Al Viro <viro@xxxxxxxxxxxxxxxxxx> wrote:
> Umm... That's going to be very painful if you dup2() something to MAX_INT and
> then run that; roughly 2G iterations of bouncing ->file_lock up and down,
> without anything that would yield CPU in process.
>
> If anything, I would suggest something like
>
> fd = *start_fd;
> grab the lock
> fdt = files_fdtable(files);
> more:
> look for the next eviction candidate in ->open_fds, starting at fd
> if there's none up to max_fd
> drop the lock
> return NULL
> *start_fd = fd + 1;
> if the fscker is really opened and not just reserved
> rcu_assign_pointer(fdt->fd[fd], NULL);
> __put_unused_fd(files, fd);
> drop the lock
> return the file we'd got
> if (unlikely(need_resched()))
> drop lock
> cond_resched();
> grab lock
> fdt = files_fdtable(files);
> goto more;
>
> with the main loop being basically
> while ((file = pick_next(files, &start_fd, max_fd)) != NULL)
> filp_close(file, files);
If we can live with close_from(int first) rather than close_range(), then this
can perhaps be done a lot more efficiently by:
new = alloc_fdtable(first);
spin_lock(&files->file_lock);
old = files_fdtable(files);
copy_fds(new, old, 0, first - 1);
rcu_assign_pointer(files->fdt, new);
spin_unlock(&files->file_lock);
clear_fds(old, 0, first - 1);
close_fdt_from(old, first);
kfree_rcu(old);
David
[Index of Archives]
[Linux Kernel]
[Sparc Linux]
[DCCP]
[Linux ARM]
[Yosemite News]
[Linux SCSI]
[Linux x86_64]
[Linux for Ham Radio]