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

Re: [PATCH] read-cache: avoid misaligned reads in index v4

From
Jeff King <peff@peff.net>
Date
Sep 26, 2022, 17:35 UTC
Message-ID
<YzHiyPkCgVHym3H4@coredump.intra.peff.net>
In-Reply-To
<e5954e90-6b5c-46a6-0842-b3d7d1e06b33@github.com>
On Mon, Sep 26, 2022 at 08:39:10AM -0700, Victoria Dye wrote:
Show 15 quoted lines
> > So this can just be:
> > 
> >   ce->ce_stat_data.sd_mtime.sec = get_be32(ondisk + offsetof(struct ondisk_cache_entry, mtime));
> > 
> > which is mercifully shorter.
> > 
> > Assuming we dismiss the rest of what I said as not worth it for a
> > minimal fix, I do think that simplification is worth rolling a v2.
> 
> That makes sense from a technical perspective, but I included the starting
> entry offset for readability reasons. It might be confusing to someone
> unfamiliar with C struct memory alignment to see every other 'get_be32'
> refer to the exact entry it's reading via the 'offsetof()', but have that
> information absent only for a few entries. And, the double 'offsetof()'
> would still be used by the 'mtime.nsec'/'ctime.nsec' fields anyway.

Ah, right, I wasn't looking close enough. I was thinking that you were reading the whole struct via a single function call, but of course that is not true with get_be32(), and the nsec loads just below make that obvious.

> In any case, if this patch is intended to be a short-lived change on the way
> to a more complete refactor and/or I'm being overzealous on the readability,
> I'd be happy to change it. :) 

No, I was just mis-reading it. I think what you've got here is a good stopping point to fix the immediate problem.

-Peff
Previous: Victoria DyeNext: Jeff King
Message 5 of 12 in “read-cache: avoid misaligned reads in index v4”
  1. read-cache: avoid misaligned reads in index v4Victoria Dye via GitGitGadget, Sep 23, 2022
  2. Jeff KingSep 23, 2022
  3. Junio C HamanoSep 23, 2022
  4. Victoria DyeSep 26, 2022
  5. Jeff KingSep 26, 2022
  6. Jeff KingSep 26, 2022
  7. Jeff KingSep 26, 2022
  8. Junio C HamanoSep 26, 2022
  9. Phillip WoodSep 25, 2022
  10. Junio C HamanoSep 26, 2022
  11. read-cache: avoid misaligned reads in index v4Victoria Dye via GitGitGadget, Sep 28, 2022
  12. Junio C HamanoSep 28, 2022

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.