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

[PATCH 2/6] Support fetching the memory usage of a delta index

From
Brian Downing <bdowning@lavos.net>
Date
Jul 12, 2007, 12:55 UTC
Message-ID
<11842449522040-git-send-email-bdowning@lavos.net>
In-Reply-To
<1184244952554-git-send-email-bdowning@lavos.net>

Delta indexes, at least on 64-bit platforms, tend to be larger than the actual uncompressed data. As such, keeping track of this storage is important if you want to successfully limit the memory size of your pack window.

Squirrel away the total allocation size inside the delta_index struct, and add an accessor "sizeof_delta_index" to access it.

Signed-off-by: Brian Downing <bdowning@lavos.net>
---
 delta.h      |    7 +++++++
 diff-delta.c |   10 ++++++++++
 2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/delta.h b/delta.h
index 7b3f86d..40ccf5a 100644
--- a/delta.h
+++ b/delta.h
@@ -24,6 +24,13 @@ create_delta_index(const void *buf, unsigned long bufsize);
 extern void free_delta_index(struct delta_index *index);
 
 /*
+ * sizeof_delta_index: returns memory usage of delta index
+ *
+ * Given pointer must be what create_delta_index() returned, or NULL.
+ */
+extern unsigned long sizeof_delta_index(struct delta_index *index);
+
+/*
  * create_delta: create a delta from given index for the given buffer
  *
  * This function may be called multiple times with different buffers using
diff --git a/diff-delta.c b/diff-delta.c
index faf96e4..3af5835 100644
--- a/diff-delta.c
+++ b/diff-delta.c
@@ -119,6 +119,7 @@ struct index_entry {
 };
 
 struct delta_index {
+	unsigned long memsize;
 	const void *src_buf;
 	unsigned long src_size;
 	unsigned int hash_mask;
@@ -159,6 +160,7 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize)
 	mem = hash + hsize;
 	entry = mem;
 
+	index->memsize = memsize;
 	index->src_buf = buf;
 	index->src_size = bufsize;
 	index->hash_mask = hmask;
@@ -228,6 +230,14 @@ void free_delta_index(struct delta_index *index)
 	free(index);
 }
 
+unsigned long sizeof_delta_index(struct delta_index *index)
+{
+	if (index)
+		return index->memsize;
+	else
+		return 0;
+}
+
 /*
  * The maximum size for any opcode sequence, including the initial header
  * plus Rabin window plus biggest copy.
-- 
1.5.2.GIT
Previous: Brian DowningNext: Brian Downing
Message 3 of 13 in “Pack window memory limit, take 2”
  1. 0/6 Pack window memory limit, take 2Brian Downing, Jul 12, 2007
  2. 1/6 Don't try to delta if target is much smaller than sourceBrian Downing, Jul 12, 2007
  3. 2/6 Support fetching the memory usage of a delta indexBrian Downing, Jul 12, 2007
  4. 3/6 Add functions for parsing integers with size suffixesBrian Downing, Jul 12, 2007
  5. Johannes SchindelinJul 12, 2007
  6. Add functions for parsing integers with size suffixesBrian Downing, Jul 12, 2007
  7. 4/6 Add pack-objects window memory usage limitBrian Downing, Jul 12, 2007
  8. Brian DowningJul 12, 2007
  9. Add pack-objects window memory usage limitBrian Downing, Jul 12, 2007
  10. 5/6 Add --window-memory option to git-repackBrian Downing, Jul 12, 2007
  11. 6/6 Add documentation for --window-memory, pack.windowMemoryBrian Downing, Jul 12, 2007
  12. Nicolas PitreJul 12, 2007
  13. Junio C HamanoJul 13, 2007

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.