All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: dhowells@redhat.com, Christian Brauner <christian@brauner.io>,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-api@vger.kernel.org, jannh@google.com, fweimer@redhat.com,
	oleg@redhat.com, tglx@linutronix.de,
	torvalds@linux-foundation.org, arnd@arndb.de, shuah@kernel.org,
	tkjos@android.com, ldv@altlinux.org, miklos@szeredi.hu,
	linux-alpha@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org,
	linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org,
	linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	linux-s390@vger.kernel.org, linux-sh@vger.kernel.org,
	sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org,
	linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org,
	x86@kernel.org
Subject: Re: [PATCH 1/2] open: add close_range()
Date: Tue, 21 May 2019 16:30:27 +0000	[thread overview]
Message-ID: <28114.1558456227@warthog.procyon.org.uk> (raw)
In-Reply-To: <20190521150006.GJ17978@ZenIV.linux.org.uk>

Al Viro <viro@zeniv.linux.org.uk> 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

WARNING: multiple messages have this Message-ID (diff)
From: David Howells <dhowells@redhat.com>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: dhowells@redhat.com, Christian Brauner <christian@brauner.io>,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-api@vger.kernel.org, jannh@google.com, fweimer@redhat.com,
	oleg@redhat.com, tglx@linutronix.de,
	torvalds@linux-foundation.org, arnd@arndb.de, shuah@kernel.org,
	tkjos@android.com, ldv@altlinux.org, miklos@szeredi.hu,
	linux-alpha@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org,
	linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org,
	linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	linux-s390@vger.kernel.org, linux-sh@vger.kernel.org,
	sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org,
	linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org,
	x86@kernel.org
Subject: Re: [PATCH 1/2] open: add close_range()
Date: Tue, 21 May 2019 17:30:27 +0100	[thread overview]
Message-ID: <28114.1558456227@warthog.procyon.org.uk> (raw)
In-Reply-To: <20190521150006.GJ17978@ZenIV.linux.org.uk>

Al Viro <viro@zeniv.linux.org.uk> 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

WARNING: multiple messages have this Message-ID (diff)
From: dhowells at redhat.com (David Howells)
Subject: [PATCH 1/2] open: add close_range()
Date: Tue, 21 May 2019 17:30:27 +0100	[thread overview]
Message-ID: <28114.1558456227@warthog.procyon.org.uk> (raw)
In-Reply-To: <20190521150006.GJ17978@ZenIV.linux.org.uk>

Al Viro <viro at zeniv.linux.org.uk> 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

WARNING: multiple messages have this Message-ID (diff)
From: dhowells@redhat.com (David Howells)
Subject: [PATCH 1/2] open: add close_range()
Date: Tue, 21 May 2019 17:30:27 +0100	[thread overview]
Message-ID: <28114.1558456227@warthog.procyon.org.uk> (raw)
Message-ID: <20190521163027.dgyrVXvd4xaSpfYhWhlKVZ0BdozDdZW422sYMGdKRTU@z> (raw)
In-Reply-To: <20190521150006.GJ17978@ZenIV.linux.org.uk>

Al Viro <viro@zeniv.linux.org.uk> 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

WARNING: multiple messages have this Message-ID (diff)
From: David Howells <dhowells@redhat.com>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-ia64@vger.kernel.org, linux-sh@vger.kernel.org,
	oleg@redhat.com, dhowells@redhat.com,
	linux-kselftest@vger.kernel.org, sparclinux@vger.kernel.org,
	shuah@kernel.org, linux-arch@vger.kernel.org,
	linux-s390@vger.kernel.org, miklos@szeredi.hu, x86@kernel.org,
	torvalds@linux-foundation.org,
	Christian Brauner <christian@brauner.io>,
	linux-mips@vger.kernel.org, linux-xtensa@linux-xtensa.org,
	tkjos@android.com, arnd@arndb.de, jannh@google.com,
	linux-m68k@lists.linux-m68k.org, tglx@linutronix.de,
	ldv@altlinux.org, linux-arm-kernel@lists.infradead.org,
	fweimer@redhat.com, linux-parisc@vger.kernel.org,
	linux-api@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-alpha@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH 1/2] open: add close_range()
Date: Tue, 21 May 2019 17:30:27 +0100	[thread overview]
Message-ID: <28114.1558456227@warthog.procyon.org.uk> (raw)
In-Reply-To: <20190521150006.GJ17978@ZenIV.linux.org.uk>

Al Viro <viro@zeniv.linux.org.uk> 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

WARNING: multiple messages have this Message-ID (diff)
From: David Howells <dhowells@redhat.com>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-ia64@vger.kernel.org, linux-sh@vger.kernel.org,
	oleg@redhat.com, dhowells@redhat.com,
	linux-kselftest@vger.kernel.org, sparclinux@vger.kernel.org,
	shuah@kernel.org, linux-arch@vger.kernel.org,
	linux-s390@vger.kernel.org, miklos@szeredi.hu, x86@kernel.org,
	torvalds@linux-foundation.org,
	Christian Brauner <christian@brauner.io>,
	linux-mips@vger.kernel.org, linux-xtensa@linux-xtensa.org,
	tkjos@android.com, arnd@arndb.de, jannh@google.com,
	linux-m68k@lists.linux-m68k.org, tglx@linutronix.de,
	ldv@altlinux.org, linux-arm-kernel@lists.infradead.org,
	fweimer@redhat.com, linux-parisc@vger.kernel.org,
	linux-api@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-alpha@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH 1/2] open: add close_range()
Date: Tue, 21 May 2019 17:30:27 +0100	[thread overview]
Message-ID: <28114.1558456227@warthog.procyon.org.uk> (raw)
In-Reply-To: <20190521150006.GJ17978@ZenIV.linux.org.uk>

Al Viro <viro@zeniv.linux.org.uk> 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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2019-05-21 16:30 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-21 11:34 [PATCH 1/2] open: add close_range() Christian Brauner
2019-05-21 11:34 ` Christian Brauner
2019-05-21 11:34 ` Christian Brauner
2019-05-21 11:34 ` Christian Brauner
2019-05-21 11:34 ` Christian Brauner
2019-05-21 11:34 ` Christian Brauner
2019-05-21 11:34 ` christian
2019-05-21 11:34 ` Christian Brauner
2019-05-21 11:34 ` [PATCH 2/2] tests: add close_range() tests Christian Brauner
2019-05-21 11:34   ` Christian Brauner
2019-05-21 11:34   ` Christian Brauner
2019-05-21 11:34   ` Christian Brauner
2019-05-21 11:34   ` christian
2019-05-21 11:34   ` Christian Brauner
2019-05-21 12:09 ` [PATCH 1/2] open: add close_range() Florian Weimer
2019-05-21 12:09   ` Florian Weimer
2019-05-21 12:09   ` Florian Weimer
2019-05-21 12:09   ` Florian Weimer
2019-05-21 12:09   ` Florian Weimer
2019-05-21 12:09   ` fweimer
2019-05-21 12:09   ` Florian Weimer
2019-05-21 13:04   ` Christian Brauner
2019-05-21 13:04     ` Christian Brauner
2019-05-21 13:04     ` Christian Brauner
2019-05-21 13:04     ` Christian Brauner
2019-05-21 13:04     ` Christian Brauner
2019-05-21 13:04     ` christian
2019-05-21 13:04     ` Christian Brauner
2019-05-21 13:10     ` Florian Weimer
2019-05-21 13:10       ` Florian Weimer
2019-05-21 13:10       ` Florian Weimer
2019-05-21 13:10       ` Florian Weimer
2019-05-21 13:10       ` fweimer
2019-05-21 13:10       ` Florian Weimer
2019-05-21 13:18       ` Christian Brauner
2019-05-21 13:18         ` Christian Brauner
2019-05-21 13:18         ` Christian Brauner
2019-05-21 13:18         ` Christian Brauner
2019-05-21 13:18         ` christian
2019-05-21 13:18         ` Christian Brauner
2019-05-21 13:23       ` Christian Brauner
2019-05-21 13:23         ` Christian Brauner
2019-05-21 13:23         ` Christian Brauner
2019-05-21 13:23         ` christian
2019-05-21 13:23         ` Christian Brauner
2019-05-21 13:23         ` Christian Brauner
2019-05-21 13:07 ` Marc Gonzalez
2019-05-21 13:12   ` Christian Brauner
2019-05-21 13:39 ` Rasmus Villemoes
2019-05-21 15:00 ` Al Viro
2019-05-21 15:00   ` Al Viro
2019-05-21 15:00   ` Al Viro
2019-05-21 15:00   ` Al Viro
2019-05-21 15:00   ` viro
2019-05-21 15:00   ` Al Viro
2019-05-21 16:53   ` Christian Brauner
2019-05-21 16:53     ` Christian Brauner
2019-05-21 16:53     ` Christian Brauner
2019-05-21 16:53     ` Christian Brauner
2019-05-21 16:53     ` christian
2019-05-21 16:53     ` Christian Brauner
2019-05-21 16:30 ` David Howells [this message]
2019-05-21 16:30   ` David Howells
2019-05-21 16:30   ` David Howells
2019-05-21 16:30   ` David Howells
2019-05-21 16:30   ` dhowells
2019-05-21 16:30   ` David Howells
2019-05-21 16:41   ` Christian Brauner
2019-05-21 16:41     ` Christian Brauner
2019-05-21 16:41     ` Christian Brauner
2019-05-21 16:41     ` Christian Brauner
2019-05-21 16:41     ` christian
2019-05-21 16:41     ` Christian Brauner
2019-05-21 20:23     ` Linus Torvalds
2019-05-21 20:23       ` Linus Torvalds
2019-05-21 20:23       ` Linus Torvalds
2019-05-21 20:23       ` Linus Torvalds
2019-05-21 20:23       ` Linus Torvalds
2019-05-21 20:23       ` torvalds
2019-05-21 20:23       ` Linus Torvalds
2019-05-21 20:23       ` Linus Torvalds
2019-05-22  8:12       ` Christian Brauner
2019-05-22  8:12         ` Christian Brauner
2019-05-22  8:12         ` Christian Brauner
2019-05-22  8:12         ` Christian Brauner
2019-05-22  8:12         ` Christian Brauner
2019-05-22  8:12         ` Christian Brauner
2019-05-22  8:12         ` christian
2019-05-22  8:12         ` Christian Brauner
2019-05-21 19:20   ` Al Viro
2019-05-21 19:20     ` Al Viro
2019-05-21 19:20     ` Al Viro
2019-05-21 19:20     ` Al Viro
2019-05-21 19:20     ` viro
2019-05-21 19:20     ` Al Viro
2019-05-21 19:59     ` Matthew Wilcox
2019-05-21 19:59       ` Matthew Wilcox
2019-05-21 19:59       ` Matthew Wilcox
2019-05-21 19:59       ` willy
2019-05-21 19:59       ` Matthew Wilcox
2019-05-21 19:59       ` Matthew Wilcox
2019-05-24 20:32 ` Michael Tirado

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=28114.1558456227@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=arnd@arndb.de \
    --cc=christian@brauner.io \
    --cc=fweimer@redhat.com \
    --cc=jannh@google.com \
    --cc=ldv@altlinux.org \
    --cc=linux-alpha@vger.kernel.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-ia64@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-m68k@lists.linux-m68k.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-parisc@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=linux-xtensa@linux-xtensa.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=miklos@szeredi.hu \
    --cc=oleg@redhat.com \
    --cc=shuah@kernel.org \
    --cc=sparclinux@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tkjos@android.com \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.