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

Re: [PATCH] avoid unncessary malloc of whole file size

From
Jeff King <peff@peff.net>
Date
Jan 24, 2019, 21:18 UTC
Message-ID
<20190124211844.GC16114@sigill.intra.peff.net>
In-Reply-To
<xmqqlg39hia8.fsf@gitster-ct.c.googlers.com>
On Thu, Jan 24, 2019 at 01:12:15PM -0800, Junio C Hamano wrote:
Show 32 quoted lines
> Joey Hess <id@joeyh.name> writes:
> 
> > When a worktree file is larger than the available memory, and a clean
> > filter is in use, this avoids mallocing a buffer the whole size of the
> > file when reading from the clean filter, which caused commands like git
> > status and git commit to OOM.
> >
> > Often in this situation the clean filter will produce a short identifier
> > for the file, so such a large buffer is not needed.
> >
> > When the clean filter does output something around the same size as the
> > worktree file, the buffer will need to be reallocated until it fits,
> > starting at 8192 and doubling in size. Benchmarking indicates that
> > reallocation is not a significant overhead for outputs up to a
> > few MB in size.
> 
> Problem description first, then solultion.  "... this avoids ..." is
> already talking about solution while forcing the readers to know
> what the problem is.
> 
>     When a worktree file is ... filter is in use, we allocate a
>     buffer for the whole size of the file when reading from the
>     clean filter.  This can force us to overallocate if the clean
>     filter is used to radically shrink a huge file and replace it
>     with a small token (e.g. git-annex or git-lfs) and lead to OOM
>     at the worst case.  Reading from the filter and growing the
>     buffer as we go would avoid such an unnecessary OOM.
> 
>     When the clean filter does output ...
>     ... few MB in size.
> 
> perhaps.

Yeah, I agree that organization is nicer. Other than that, the patch looks good to me.

-Peff
Previous: Junio C Hamano
Message 12 of 12 in “git status OOM on mmap of large file”
  1. Joey HessJan 22, 2019
  2. brian m. carlsonJan 24, 2019
  3. Jeff KingJan 24, 2019
  4. Joey HessJan 24, 2019
  5. Jeff KingJan 24, 2019
  6. Duy NguyenJan 24, 2019
  7. Joey HessJan 24, 2019
  8. Jeff KingJan 24, 2019
  9. Jeff KingJan 24, 2019
  10. avoid unncessary malloc of whole file sizeJoey Hess, Jan 24, 2019
  11. Junio C HamanoJan 24, 2019
  12. Jeff KingJan 24, 2019

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.