[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <878u6ed6ca.fsf@rasmusvillemoes.dk>
Date: Wed, 04 Nov 2015 00:13:41 +0100
From: Rasmus Villemoes <linux@...musvillemoes.dk>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Alexander Viro <viro@...iv.linux.org.uk>,
linux-fsdevel <linux-fsdevel@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [RFC] vfs: don't bother clearing close_on_exec bit for unused fds
On Tue, Nov 03 2015, Linus Torvalds <torvalds@...ux-foundation.org> wrote:
> On Tue, Nov 3, 2015 at 1:41 AM, Rasmus Villemoes
> <linux@...musvillemoes.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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists