git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Stefan Beller <sbeller@google.com>
Cc: git@vger.kernel.org, gitster@pobox.com, jrnieder@gmail.com,
	johannes.schindelin@gmail.com, Jens.Lehmann@web.de,
	ericsunshine@gmail.com, j6t@kdbg.org
Subject: Re: [PATCHv2 2/7] xread: poll on non blocking fds
Date: Thu, 17 Dec 2015 22:07:53 -0500	[thread overview]
Message-ID: <20151218030752.GA8432@sigill.intra.peff.net> (raw)
In-Reply-To: <1450224252-16833-3-git-send-email-sbeller@google.com>

On Tue, Dec 15, 2015 at 04:04:07PM -0800, Stefan Beller wrote:

> If we get an EAGAIN or EWOULDBLOCK the fd must have set O_NONBLOCK.
> As the intent of xread is to read as much as possible either until the
> fd is EOF or an actual error occurs, we can ease the feeder of the fd
> by not spinning the whole time, but rather wait for it politely by not
> busy waiting.

I'm not sure this second sentence is true. The point of xread() is to do
a single read that makes forward progress (or returns a real error), not
to read as much as we can.

The rationale seems more to me like:

  The point of xread() is to perform read() until we either get some
  data, or encounter a "real" error. We do not count EINTR or EAGAIN as
  "real" errors, as a reader trying to make forward progress would
  generally just repeat the read, so we loop for them as a convenience.

  In the case of EINTR, trying the read() again immediately is fine; a
  signal interrupted us, but there is no reason to think the read()
  would not succeed if we tried it again.

  For EAGAIN, however, we know that the fd must have set O_NONBLOCK. In
  this case reading again immediately is not likely to produce results,
  and we will chew up CPU spinning on read() calls. Instead, let's
  insert a poll() to block until we actually get data.

I also don't know that this patch necessarily needs to be part of the
parallel-fetch series anymore. We are not setting O_NONBLOCK ourselves,
and I don't think the correctness of the new strbuf_read_once() is
impacted by this. I.e., I think this optimization applies equally well
to the hundreds of existing xread() calls, should they unexpectedly be
fed an O_NONBLOCK descriptor.

That said, I do not mind it here, but I think it could be its own
separate topic if you wanted to reduce the complexity of the
parallel-fetch topic.

> We should not care if the call to poll failed, as we're in an infinite
> loop and can only get out with the correct read().

You might want to expand on "correct" here. I think you mean "can only
get out with a read() that returns data or a "real" error" (I am reusing
the terminology I introduced above; I am fine with other terminology,
depending on how you word the rest of it).

-Peff

  parent reply	other threads:[~2015-12-18  3:08 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-16  0:04 [PATCHv2 0/7] Rerolling sb/submodule-parallel-fetch for the time after 2.7 Stefan Beller
2015-12-16  0:04 ` [PATCHv2 1/7] submodule.c: write "Fetching submodule <foo>" to stderr Stefan Beller
2015-12-16  0:04 ` [PATCHv2 2/7] xread: poll on non blocking fds Stefan Beller
2015-12-17 20:12   ` Torsten Bögershausen
2015-12-17 20:22     ` Stefan Beller
2015-12-17 20:42       ` Torsten Bögershausen
2015-12-17 20:51         ` Stefan Beller
2015-12-18  3:14           ` Jeff King
2015-12-18  3:13         ` Jeff King
2015-12-18  8:50           ` Torsten Bögershausen
2015-12-18 18:12             ` Jeff King
2015-12-18  3:07   ` Jeff King [this message]
2015-12-16  0:04 ` [PATCHv2 3/7] strbuf: add strbuf_read_once to read without blocking Stefan Beller
2015-12-16  0:04 ` [PATCHv2 4/7] sigchain: add command to pop all common signals Stefan Beller
2015-12-16  0:04 ` [PATCHv2 5/7] run-command: add an asynchronous parallel child processor Stefan Beller
2015-12-16  0:04 ` [PATCHv2 6/7] fetch_populated_submodules: use new parallel job processing Stefan Beller
2015-12-16  0:04 ` [PATCHv2 7/7] submodules: allow parallel fetching, add tests and documentation Stefan Beller
2015-12-16  0:19 ` [PATCHv2 0/7] Rerolling sb/submodule-parallel-fetch for the time after 2.7 Stefan Beller
2015-12-16 20:20 ` Junio C Hamano

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20151218030752.GA8432@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=Jens.Lehmann@web.de \
    --cc=ericsunshine@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=johannes.schindelin@gmail.com \
    --cc=jrnieder@gmail.com \
    --cc=sbeller@google.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).