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

Re: [PATCH v2 2/2] Prevent git from rehashing 4GiB files

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 12, 2023, 17:58 UTC
Message-ID
<xmqqpm1jn2nh.fsf@gitster.g>
In-Reply-To
<20231012160930.330618-3-sandals@crustytoothpaste.net>
"brian m. carlson" <sandals@crustytoothpaste.net> writes:
> An example would be to have a 2^32 sized file in the index of
> patched git. Patched git would save the file as 2^31 in the cache.
> An unpatched git would very much see the file has changed in size
> and force it to rehash the file, which is safe.

The reason why this is "safe" is because an older Git will would keep rehashing whether 2^31 or 0 is stored as its sd_size, so the change is not making things worse? With older git, "git diff-files" will report that such a file is not up to date, and then the user will refresh the index, which will store 0 as its sd_file, so tentatively "git status" may give a wrong information, but we probalby do not care? Is that how the reasoning goes?

Show 15 quoted lines
> +/*
> + * Munge st_size into an unsigned int.
> + */
> +static unsigned int munge_st_size(off_t st_size) {
> +	unsigned int sd_size = st_size;
> +
> +	/*
> +	 * If the file is an exact multiple of 4 GiB, modify the value so it
> +	 * doesn't get marked as racily clean (zero).
> +	 */
> +	if (!sd_size && st_size)
> +		return 0x80000000;
> +	else
> +		return sd_size;
> +}

This assumes typeof(sd_size) aka "unsigned int" is always 32-bit, which does not sound reasonable. Reference to 4GiB, 2^32 and 2^31 in the code and the proposed commit log message need to be qualified with "on a platform whose uint is 32-bit" or something, or better yet, phrased in a way that is agnostic to the integer size. At the very least, the hardcoded 0x80000000 needs to be rethought, I am afraid.

Other than that, the workaround for the racy-git avoidance code does sound good. I actually wonder if we should always use 1 regardless of integer size.

Previous: brian m. carlsonNext: brian m. carlson
Message 10 of 16 in “Prevent re-reading 4 GiB files on every status”
  1. 0/2 Prevent re-reading 4 GiB files on every statusbrian m. carlson, Oct 12, 2023
  2. 1/2 t: add a test helper to truncate filesbrian m. carlson, Oct 12, 2023
  3. Eric SunshineOct 12, 2023
  4. brian m. carlsonOct 13, 2023
  5. Junio C HamanoOct 12, 2023
  6. brian m. carlsonOct 13, 2023
  7. Junio C HamanoOct 13, 2023
  8. Jeff KingOct 16, 2023
  9. 2/2 Prevent git from rehashing 4GiB filesbrian m. carlson, Oct 12, 2023
  10. Junio C HamanoOct 12, 2023
  11. brian m. carlsonOct 12, 2023
  12. Junio C HamanoOct 12, 2023
  13. Jeff KingOct 17, 2023
  14. Jason HattonOct 17, 2023
  15. Junio C HamanoOct 17, 2023
  16. brian m. carlsonOct 18, 2023

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.