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

Re: What's cooking in git.git (Sep 2016, #03; Fri, 9)

From
Jeff King <peff@peff.net>
Date
Sep 12, 2016, 16:46 UTC
Message-ID
<20160912164616.vg33kldazuthff3d@sigill.intra.peff.net>
In-Reply-To
<xmqqoa3w8zco.fsf@gitster.mtv.corp.google.com>
On Fri, Sep 09, 2016 at 03:47:35PM -0700, Junio C Hamano wrote:
Show 13 quoted lines
> * jk/delta-base-cache (2016-08-23) 7 commits
>   (merged to 'next' on 2016-08-25 at f1c141a)
>  + t/perf: add basic perf tests for delta base cache
>  + delta_base_cache: use hashmap.h
>  + delta_base_cache: drop special treatment of blobs
>  + delta_base_cache: use list.h for LRU
>  + release_delta_base_cache: reuse existing detach function
>  + clear_delta_base_cache_entry: use a more descriptive name
>  + cache_or_unpack_entry: drop keep_cache parameter
> 
>  The delta-base-cache mechanism has been a key to the performance in
>  a repository with a tightly packed packfile, but it did not scale
>  well even with a larger value of core.deltaBaseCacheLimit.
I happened to notice today that this topic needs a minor tweak:
-- >8 --
Subject: [PATCH] add_delta_base_cache: use list_for_each_safe

We may remove elements from the list while we are iterating, which requires using a second temporary pointer. Otherwise stepping to the next element of the list might involve looking at freed memory (which generally works in practice, as we _just_ freed it, but of course is wrong to rely on; valgrind notices it).

Signed-off-by: Jeff King <peff@peff.net>
---
 sha1_file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index a57b71d..132c861 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2187,11 +2187,11 @@ static void add_delta_base_cache(struct packed_git *p, off_t base_offset,
 	void *base, unsigned long base_size, enum object_type type)
 {
 	struct delta_base_cache_entry *ent = xmalloc(sizeof(*ent));
-	struct list_head *lru;
+	struct list_head *lru, *tmp;
 
 	delta_base_cached += base_size;
 
-	list_for_each(lru, &delta_base_cache_lru) {
+	list_for_each_safe(lru, tmp, &delta_base_cache_lru) {
 		struct delta_base_cache_entry *f =
 			list_entry(lru, struct delta_base_cache_entry, lru);
 		if (delta_base_cached <= delta_base_cache_limit)
-- 
2.10.0.230.g6f8d04b
Previous: Junio C HamanoNext: Junio C Hamano
Message 2 of 4 in “What's cooking in git.git (Sep 2016, #03; Fri, 9)”
  1. Junio C HamanoSep 9, 2016
  2. Jeff KingSep 12, 2016
  3. Junio C HamanoSep 12, 2016
  4. Jeff KingSep 12, 2016

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.