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

Re: leaky cherry-pick

From
Jeff King <peff@peff.net>
Date
Jan 10, 2012, 19:50 UTC
Message-ID
<20120110195017.GA19961@sigill.intra.peff.net>
In-Reply-To
<CALkWK0nwE0c6qVvbauPrjmb3NX4NDeGSrvrC2ry2bjMeM4Hr0A@mail.gmail.com>
On Tue, Jan 10, 2012 at 10:58:45AM +0530, Ramkumar Ramachandra wrote:
Show 24 quoted lines
> Interesting- I wonder where .gitattributes parsing code fits into all
> this.  The purpose of bootstrap _attr_stack() is to populate
> attr_stack for its callers.  Lots of memory allocation happening in
> handle_attr_line() -- that information is returned to
> bootstrap_attr_stack().  We have to keep backtracking until that
> information is provably useless and free it.  Hm, convert_attrs() (in
> convert.c) is a common caller in both cases, but the populated
> attr_stack is local to attr.c; I wonder if this is the problem.  If my
> hunch is right, it should be a trivial fix (caution: untested):
> 
> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
> 
> diff --git a/attr.c b/attr.c
> index 76b079f..12e3824 100644
> --- a/attr.c
> +++ b/attr.c
> @@ -745,6 +745,7 @@ int git_check_attr(const char *path, int num,
> struct git_attr_check *check)
>  		check[i].value = value;
>  	}
> 
> +	drop_attr_stack();
>  	return 0;
>  }

I don't think this is right. The attr_stack is intentionally kept in place after a lookup as a cache, because callers are very likely to lookup nearby filenames. The first thing we do is pop unrelated parts of the stack, keep the early bits, and then push any new needed directories.

So if you do a lookup for "foo/bar/baz/file1", the stack afterwards would be:

  $GIT_DIR/info/attributes
  foo/bar/baz/.gitattributes
  foo/bar/.gitattributes
  foo/.gitattributes
  .gitattributes
  [builtins]

If you then do a lookup for "foo/bar/baz/file2", it can use the exact same stack without looking for or reparsing the attribute files. If you then do a lookup for "foo/bar/bleep/file", it pops only the entry for "foo/bar/baz/.gitattributes", and pushes only the entry for "foo/bar/bleep/.gitattributes".

The calling code _could_ say "btw, I am done with attributes now, so free the memory". But we don't bother, since it's a small amount of memory, and other parts of the code may want it later.

-Peff
Previous: Ramkumar RamachandraNext: Ramkumar Ramachandra
Message 5 of 11 in “leaky cherry-pick”
  1. Pete WyckoffJan 9, 2012
  2. Junio C HamanoJan 9, 2012
  3. Nguyen Thai Ngoc DuyJan 10, 2012
  4. Ramkumar RamachandraJan 10, 2012
  5. Jeff KingJan 10, 2012
  6. Ramkumar RamachandraJan 11, 2012
  7. Junio C HamanoJan 11, 2012
  8. Ramkumar RamachandraJan 11, 2012
  9. Jeff KingJan 11, 2012
  10. Junio C HamanoJan 12, 2012
  11. Jeff KingJan 12, 2012

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.