git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] refs: sync loose refs to disk before committing them

From
Jeff King <peff@peff.net>
Date
Nov 5, 2021, 09:34 UTC
Message-ID
<YYT6tDyfBbwot2br@coredump.intra.peff.net>
In-Reply-To
<nycvar.QRO.7.76.6.2111051010070.56@tvgsbejvaqbjf.bet>
On Fri, Nov 05, 2021 at 10:12:25AM +0100, Johannes Schindelin wrote:
Show 7 quoted lines
> > So this will definitely hurt at edge / pathological cases.
> 
> Ouch.
> 
> I wonder whether this could be handled similarly to the
> `core.fsyncObjectFiles=batch` mode that has been proposed in
> https://lore.kernel.org/git/pull.1076.v8.git.git.1633366667.gitgitgadget@gmail.com/
Yeah, that was along the lines I was thinking.

I hadn't really looked at the details of the batch-fsync there. The big trick seems to be doing a pagecache writeback for each file, and then stimulating an actual disk write (by fsyncing a tempfile) after the batch is done.

That would be pretty easy to do for the refs (it's git_fsync() while closing each file where Patrick is calling fsync(), followed by a single do_batch_fsync() after everything is closed but before we rename).

Show 5 quoted lines
> Essentially, we would have to find a better layer to do this, where we
> can synchronize after a potentially quite large number of ref updates has
> happened. That would definitely be a different layer than the file-based
> refs backend, of course, and would probably apply in a different way to
> other refs backends.

We do have the concept of a ref_transaction, so that would be the natural place for it. Not every caller uses it, though, because it implies atomicity of the transaction (so some may do a sequence of N independent transactions, because they don't want failure of one to impact others). I think that could be changed, if the ref_transaction learned about non-atomicity, but it may take some surgery.

I expect that reftables would similarly benefit; it is probably much more efficient to write a table slice with N entries than it is to write N slices, even before accounting for fsync(). And once doing that, then the fsync() part becomes trivial.

-Peff
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 14 of 34 in “refs: sync loose refs to disk before committing them”
  1. refs: sync loose refs to disk before committing themPatrick Steinhardt, Nov 4, 2021
  2. Ævar Arnfjörð BjarmasonNov 4, 2021
  3. Patrick SteinhardtNov 4, 2021
  4. Junio C HamanoNov 4, 2021
  5. Neeraj SinghNov 4, 2021
  6. Junio C HamanoNov 5, 2021
  7. Jeff KingNov 5, 2021
  8. Ævar Arnfjörð BjarmasonNov 5, 2021
  9. Jeff KingNov 5, 2021
  10. Jeff KingNov 5, 2021
  11. Jeff KingNov 5, 2021
  12. Johannes SchindelinNov 5, 2021
  13. Patrick SteinhardtNov 5, 2021
  14. Jeff KingNov 5, 2021
  15. Patrick SteinhardtNov 9, 2021
  16. Jeff KingNov 10, 2021
  17. Patrick SteinhardtNov 10, 2021
  18. 0/3 refs: sync loose refs to disk before committing themPatrick Steinhardt, Nov 10, 2021
  19. 1/3 wrapper: handle EINTR in `git_fsync()`Patrick Steinhardt, Nov 10, 2021
  20. Johannes SchindelinNov 10, 2021
  21. Ævar Arnfjörð BjarmasonNov 10, 2021
  22. 2/3 wrapper: provide function to sync directoriesPatrick Steinhardt, Nov 10, 2021
  23. Ævar Arnfjörð BjarmasonNov 10, 2021
  24. 3/3 refs: add configuration to enable flushing of refsPatrick Steinhardt, Nov 10, 2021
  25. Ævar Arnfjörð BjarmasonNov 10, 2021
  26. Neeraj SinghNov 10, 2021
  27. Ævar Arnfjörð BjarmasonNov 10, 2021
  28. Neeraj SinghNov 11, 2021
  29. Patrick SteinhardtNov 11, 2021
  30. Patrick SteinhardtNov 11, 2021
  31. Neeraj SinghNov 11, 2021
  32. Johannes SchindelinNov 10, 2021
  33. Jeff KingNov 10, 2021
  34. Patrick SteinhardtNov 11, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.