Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1261955

Re: [RFC] vfs: don't bother clearing close_on_exec bit for unused fds

Path csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod
From Rasmus Villemoes <linux@rasmusvillemoes.dk>
Newsgroups linux.kernel
Subject Re: [RFC] vfs: don't bother clearing close_on_exec bit for unused fds
Date Wed, 04 Nov 2015 00:20:02 +0100
Message-ID <qqT1U-RQ-15@gated-at.bofh.it> (permalink)
References <qqGo3-WT-43@gated-at.bofh.it> <qqSyS-sc-9@gated-at.bofh.it>
X-Original-To Linus Torvalds <torvalds@linux-foundation.org>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:organization:references:date:in-reply-to :message-id:user-agent:mime-version:content-type; bh=fQdxcQS4sJzLu7YI72QrAYgQIfGU73xOCVq2v0Dxv0E=; b=T2efw/7MWJbxnT472baSrqWIUWY2FA2GVRMPJLu20pCI9OWGQR3wJeVBzvwHxh1yf7 /Gnsyyyw+h/jXDi6VMLk54szlZn6pWSjzUZgRzCwODhm3wp0qsQgSpok4JOqyhJI1xv7 f33OttVfJvaCey76kEmLWJ0U+Seic3568T3oM=
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:organization:references:date :in-reply-to:message-id:user-agent:mime-version:content-type; bh=fQdxcQS4sJzLu7YI72QrAYgQIfGU73xOCVq2v0Dxv0E=; b=WhqIJreqqw6Rfu+MWCrUgNwKcASTINRFQn/fTGCd75fyHAoUZqZ8jiDOAIuc9crVeZ QxQp84lha2Lase+VuRCvxdhEiQdAVY1DsJJqVXqRijJ4pGJrttQUIzjxLroav2lqGMCM Hjqm7LzSJTIhCggurKjDQujQ0GBDjYWPxSM0krBPWj7pNpDNG1fMAZo3rDhtCqv5wVIC Z5rgRCcWPuEXU8+LsbYQU8LxhPBWgsq99Q6eDQBngOzYKcP2PknEX+CwIUc6Qknb9rP8 pVdE+pto0VoLPNLjLOhOjQO7UctJwqYgr/kujW9Pjihk18PtBK4ZxxWowCP249LCNj4k tvrg==
X-Gm-Message-State ALoCoQmTmKpRQEb1gXdhSKPyN3fG9+ytjJCjtBIVOnv7oV/I9PUxrf5Vhgs15jVLIGTPDUhZHYsR
X-Received by 10.194.129.135 with SMTP id nw7mr32113707wjb.148.1446592423333; Tue, 03 Nov 2015 15:13:43 -0800 (PST)
Organization D03
X-Hashcash 1:20:151103:linux-fsdevel@vger.kernel.org::T3EXTEskfFPn7btO:0000000000000000000000000000000021Vl
X-Hashcash 1:20:151103:linux-kernel@vger.kernel.org::yr07aeHKmZ3R59/D:0000000000000000000000000000000004zee
X-Hashcash 1:20:151103:torvalds@linux-foundation.org::KWVMhk/KYACXbLke:000000000000000000000000000000006Bai
X-Hashcash 1:20:151103:viro@zeniv.linux.org.uk::MY1vZmOFge4rs1TZ:000000000000000000000000000000000000009X2I
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)
MIME-Version 1.0
Content-Type text/plain
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 40
X-Original-Cc Alexander Viro <viro@zeniv.linux.org.uk>, linux-fsdevel <linux-fsdevel@vger.kernel.org>, Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
X-Original-Date Wed, 04 Nov 2015 00:13:41 +0100
X-Original-Message-ID <878u6ed6ca.fsf@rasmusvillemoes.dk>
X-Original-References <1446543679-28849-1-git-send-email-linux@rasmusvillemoes.dk> <CA+55aFxGD0aftAb49X1G-f79WCD8znkeQX0bSfDVDjBiUCQ2fQ@mail.gmail.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1261955

Show key headers only | View raw


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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RFC] vfs: don't bother clearing close_on_exec bit for unused fds Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-11-03 10:50 +0100
  Re: [RFC] vfs: don't bother clearing close_on_exec bit for unused fds Linus Torvalds <torvalds@linux-foundation.org> - 2015-11-03 23:50 +0100
    Re: [RFC] vfs: don't bother clearing close_on_exec bit for unused fds Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-11-04 00:20 +0100
  Re: [RFC] vfs: don't bother clearing close_on_exec bit for unused  fds Eric Dumazet <eric.dumazet@gmail.com> - 2015-11-04 02:40 +0100
    Re: [RFC] vfs: don't bother clearing close_on_exec bit for unused fds Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-11-04 12:00 +0100
      Re: [RFC] vfs: don't bother clearing close_on_exec bit for unused  fds Eric Dumazet <eric.dumazet@gmail.com> - 2015-11-04 13:40 +0100

csiph-web