git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Cc: "Michael Haggerty" <mhagger@alum.mit.edu>,
	"Junio C Hamano" <gitster@pobox.com>,
	"Torsten Bögershausen" <tboegi@web.de>,
	"Johannes Sixt" <j6t@kdbg.org>,
	"Shawn O. Pearce" <spearce@spearce.org>,
	mlevedahl@gmail.com, dpotapov@gmail.com,
	"GIT Mailing-list" <git@vger.kernel.org>
Subject: Re: [RFC/PATCH 0/1] cygwin: Remove the Win32 l/stat() functions
Date: Wed, 26 Jun 2013 18:35:52 -0400	[thread overview]
Message-ID: <20130626223552.GA12785@sigill.intra.peff.net> (raw)
In-Reply-To: <51CB610C.7050501@ramsay1.demon.co.uk>

On Wed, Jun 26, 2013 at 10:45:48PM +0100, Ramsay Jones wrote:

> > This patch adds some *extra* cache invalidation that was heretofore
> > missing.  If stat() is broken it could
> > 
> > (a) cause a false positive, resulting in some unnecessary cache
> > invalidation and re-reading of packed-refs, which will hurt performance
> > but not correctness; or
> > 
> > (b) cause a false negative, in which case the stale cache might be used
> > for reading (but not writing), just as was *always* the case before this
> > patch.
> > 
> > As far as I understand, the concern for cygwin is (a).  I will leave it
> > to others to measure and/or decide whether the performance loss is too
> > grave to endure until the cygwin stat() situation is fixed.
> 
> Hmm, I'm not sure I understand ... However, I can confirm that the
> 'mh/ref-races' branch in next is broken on cygwin. (i.e. it is not
> just a speed issue; it provokes fatal errors).

I think Michael's assessment above is missing one thing. It is true that
a false positive is just a performance problem in most cases, as we
unnecessarily reload the file, thinking it has changed.

However, when we have taken a lock on the file, there is an additional
safety measure: if we find the file is changed, we abort, as that should
never happen (it means somebody else modified the file while we had it
locked). But of course Cygwin's false positive here triggers the safety
valve, and we die without even realizing that nothing changed.

In theory we can drop the safety valve; it should never actually happen.
But I'd like to keep it there for working systems. Perhaps it is worth
doing something like this:

diff --git a/refs.c b/refs.c
index 4302206..7cac42d 100644
--- a/refs.c
+++ b/refs.c
@@ -1080,6 +1080,16 @@ static struct packed_ref_cache *get_packed_ref_cache(struct ref_cache *refs)
 		packed_refs_file = git_path("packed-refs");
 
 	if (refs->packed &&
+#ifdef STAT_VALIDITY_GIVES_FALSE_POSITIVES
+	    /*
+	     * If we get false positives from our stat calls on this platform,
+	     * then we must assume that once we have locked the packed-refs
+	     * file it does not change. Otherwise it looks like somebody else
+	     * has changed it out from under us (while we have it locked!), and
+	     * we die().
+	     */
+	    !refs->packed->lock &&
+#endif
 	    !stat_validity_check(&refs->packed->validity, packed_refs_file))
 		clear_packed_ref_cache(refs);
 

and then we can add that define to Cygwin in the Makefile. I verified
the issue on Linux by "breaking" stat_validity_check to always return 0
(i.e., to always give a false positive that the file has changed, which
is what Cygwin is doing).

I am curious how often Cygwin gives us the false positive. If it is
every time, then the check is not doing much good at all. Is it possible
for you to instrument stat_validity_check to report how often it does or
does not do anything useful?

-Peff

  reply	other threads:[~2013-06-26 22:36 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <51C5FD28.1070004@ramsay1.demon.co.uk>
     [not found] ` <51C7A875.6020205@gmail.com>
     [not found]   ` <7va9mf6txq.fsf@alter.siamese.dyndns.org>
2013-06-25 19:23     ` [RFC/PATCH 0/1] cygwin: Remove the Win32 l/stat() functions Johannes Sixt
2013-06-25 20:23       ` Torsten Bögershausen
2013-06-25 21:18       ` Junio C Hamano
2013-06-26 14:19         ` Torsten Bögershausen
2013-06-26 21:54           ` Ramsay Jones
2013-06-27 15:19             ` Torsten Bögershausen
2013-06-27 23:18               ` Ramsay Jones
2013-06-27  2:37           ` Mark Levedahl
     [not found] ` <51C6BC4B.9030905@web.de>
     [not found]   ` <51C8BF2C.2050203@ramsay1.demon.co.uk>
     [not found]     ` <7vy59y4w3r.fsf@alter.siamese.dyndns.org>
2013-06-26 21:39       ` Ramsay Jones
     [not found]       ` <51C94425.7050006@alum.mit.edu>
2013-06-26 21:45         ` Ramsay Jones
2013-06-26 22:35           ` Jeff King [this message]
2013-06-26 22:43             ` Jeff King
2013-06-27 22:58               ` Ramsay Jones
2013-06-28  2:31                 ` Mark Levedahl
2013-06-27  5:51             ` Michael Haggerty
2013-06-27 19:58               ` Jeff King
2013-06-27 21:04                 ` Junio C Hamano
2013-06-27 23:09               ` Ramsay Jones
2013-06-30 17:28                 ` Ramsay Jones
2013-06-30 19:50                   ` Junio C Hamano
2013-07-04 18:18                     ` Ramsay Jones
2013-07-09 11:02                   ` Torsten Bögershausen
2013-07-11 17:31                     ` Ramsay Jones
2013-06-27 22:17             ` Ramsay Jones

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=20130626223552.GA12785@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=dpotapov@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=mhagger@alum.mit.edu \
    --cc=mlevedahl@gmail.com \
    --cc=ramsay@ramsay1.demon.co.uk \
    --cc=spearce@spearce.org \
    --cc=tboegi@web.de \
    /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).