1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-08 13:36:15 +02:00

localize window memory usage accounting

This is to help threadification of delta searching.

Signed-off-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nicolas Pitre 2007-09-06 02:13:09 -04:00 committed by Junio C Hamano
parent 75d3985319
commit ef0316fcd9

View File

@ -78,7 +78,6 @@ static unsigned long delta_cache_size = 0;
static unsigned long max_delta_cache_size = 0;
static unsigned long cache_max_small_delta_size = 1000;
static unsigned long window_memory_usage = 0;
static unsigned long window_memory_limit = 0;
/*
@ -1300,7 +1299,7 @@ static int delta_cacheable(unsigned long src_size, unsigned long trg_size,
* one.
*/
static int try_delta(struct unpacked *trg, struct unpacked *src,
unsigned max_depth)
unsigned max_depth, unsigned long *mem_usage)
{
struct object_entry *trg_entry = trg->entry;
struct object_entry *src_entry = src->entry;
@ -1356,7 +1355,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
if (sz != trg_size)
die("object %s inconsistent object length (%lu vs %lu)",
sha1_to_hex(trg_entry->idx.sha1), sz, trg_size);
window_memory_usage += sz;
*mem_usage += sz;
}
if (!src->data) {
src->data = read_sha1_file(src_entry->idx.sha1, &type, &sz);
@ -1366,7 +1365,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
if (sz != src_size)
die("object %s inconsistent object length (%lu vs %lu)",
sha1_to_hex(src_entry->idx.sha1), sz, src_size);
window_memory_usage += sz;
*mem_usage += sz;
}
if (!src->index) {
src->index = create_delta_index(src->data, src_size);
@ -1376,7 +1375,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
warning("suboptimal pack - out of memory");
return 0;
}
window_memory_usage += sizeof_delta_index(src->index);
*mem_usage += sizeof_delta_index(src->index);
}
delta_buf = create_delta(src->index, trg->data, trg_size, &delta_size, max_size);
@ -1423,18 +1422,19 @@ static unsigned int check_delta_limit(struct object_entry *me, unsigned int n)
return m;
}
static void free_unpacked(struct unpacked *n)
static unsigned long free_unpacked(struct unpacked *n)
{
window_memory_usage -= sizeof_delta_index(n->index);
unsigned long freed_mem = sizeof_delta_index(n->index);
free_delta_index(n->index);
n->index = NULL;
if (n->data) {
freed_mem += n->entry->size;
free(n->data);
n->data = NULL;
window_memory_usage -= n->entry->size;
}
n->entry = NULL;
n->depth = 0;
return freed_mem;
}
static void find_deltas(struct object_entry **list, unsigned list_size,
@ -1443,7 +1443,7 @@ static void find_deltas(struct object_entry **list, unsigned list_size,
uint32_t i = list_size, idx = 0, count = 0, processed = 0;
unsigned int array_size = window * sizeof(struct unpacked);
struct unpacked *array;
int max_depth;
unsigned long mem_usage = 0;
array = xmalloc(array_size);
memset(array, 0, array_size);
@ -1453,16 +1453,16 @@ static void find_deltas(struct object_entry **list, unsigned list_size,
do {
struct object_entry *entry = list[--i];
struct unpacked *n = array + idx;
int j, best_base = -1;
int j, max_depth, best_base = -1;
free_unpacked(n);
mem_usage -= free_unpacked(n);
n->entry = entry;
while (window_memory_limit &&
window_memory_usage > window_memory_limit &&
mem_usage > window_memory_limit &&
count > 1) {
uint32_t tail = (idx + window - count) % window;
free_unpacked(array + tail);
mem_usage -= free_unpacked(array + tail);
count--;
}
@ -1497,7 +1497,7 @@ static void find_deltas(struct object_entry **list, unsigned list_size,
m = array + other_idx;
if (!m->entry)
break;
ret = try_delta(n, m, max_depth);
ret = try_delta(n, m, max_depth, &mem_usage);
if (ret < 0)
break;
else if (ret > 0)