From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [RFC] vfs: don't bother clearing close_on_exec bit for unused fds
Date: Wed, 04 Nov 2015 00:13:41 +0100 [thread overview]
Message-ID: <878u6ed6ca.fsf@rasmusvillemoes.dk> (raw)
In-Reply-To: <CA+55aFxGD0aftAb49X1G-f79WCD8znkeQX0bSfDVDjBiUCQ2fQ@mail.gmail.com> (Linus Torvalds's message of "Tue, 3 Nov 2015 14:45:01 -0800")
On Tue, Nov 03 2015, Linus Torvalds <torvalds@linux-foundation.org> wrote:
> On Tue, Nov 3, 2015 at 1:41 AM, Rasmus Villemoes
> <linux@rasmusvillemoes.dk> wrote:
>>
>> I'm sure I've missed something, hence the RFC. But if not, there's
>> probably also a few memsets which become redundant. And the
>> __set_close_on_exec part should probably be its own patch...
>
> The patch looks fine to me. I'm not sure the __set_close_on_exec part
> even makes sense, because if you set that bit, it usually really *is*
> clear before, so testing it beforehand is just pointless. And if
> somebody really keeps setting the bit, they are doing something stupid
> anyway..
So that's true for the lifetime of a single fd where no-one of course
does fcntl(fd, FD_CLOEXEC) more than once. But the scenario I was
thinking of was when fds get recycled. open(, O_CLOEXEC) => 5, close(5),
open(, O_CLOEXEC) => 5; in that case, letting the close_on_exec bit keep
its value avoids dirtying the cache line on all subsequent allocations
of fd 5 (for example, had Eric's app been using *_CLOEXEC for all its
open's, socket's etc. there wouldn't have been any gain by adding the
conditional to __clear_close_on_exec, but I'd expect to see a similar
gain by doing the symmetric thing). Again, this is assuming that almost
all fd allocations either do or do not apply CLOEXEC - after a while,
->close_on_exec would reach a steady-state where no bits get flipped
anymore.
The "usually really *is* clear" only holds when we do "bother clearing
close_on_exec bit for unused fds", which is what I suggest we don't :-)
I don't think either state of the bit in close_on_exec is more or less
'up-to-date' when its buddy in open_fds is not set.
Rasmus
next prev parent reply other threads:[~2015-11-03 23:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-03 9:41 [RFC] vfs: don't bother clearing close_on_exec bit for unused fds Rasmus Villemoes
2015-11-03 22:45 ` Linus Torvalds
2015-11-03 23:13 ` Rasmus Villemoes [this message]
2015-11-04 1:31 ` Eric Dumazet
2015-11-04 10:59 ` Rasmus Villemoes
2015-11-04 12:33 ` Eric Dumazet
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=878u6ed6ca.fsf@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox