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>
Nicolas Pitre committed
Sep 6, 2007 at 02:13 UTC
ef0316fcd996c1679fef37ae2a53bef403c77356
1 file changed
+14
-14
builtin-pack-objects.c
+14
-14
@@ -78,7 +78,6 @@ static unsigned long delta_cache_size = 0;
78
static unsigned long max_delta_cache_size = 0;
79
static unsigned long cache_max_small_delta_size = 1000;
80
81
-static unsigned long window_memory_usage = 0;
81
static unsigned long window_memory_limit = 0;
82
83
/*
@@ -1300,7 +1299,7 @@ static int delta_cacheable(unsigned long src_size, unsigned long trg_size,
1299
* one.
1300
*/
1301
static int try_delta(struct unpacked *trg, struct unpacked *src,
1303
- unsigned max_depth)
1302
+ unsigned max_depth, unsigned long *mem_usage)
1303
{
1304
struct object_entry *trg_entry = trg->entry;
1305
struct object_entry *src_entry = src->entry;
@@ -1356,7 +1355,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
1355
if (sz != trg_size)
1356
die("object %s inconsistent object length (%lu vs %lu)",
1357
sha1_to_hex(trg_entry->idx.sha1), sz, trg_size);
1359
- window_memory_usage += sz;
1358
+ *mem_usage += sz;
1359
}
1360
if (!src->data) {
1361
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,
1365
if (sz != src_size)
1366
die("object %s inconsistent object length (%lu vs %lu)",
1367
sha1_to_hex(src_entry->idx.sha1), sz, src_size);
1369
- window_memory_usage += sz;
1368
+ *mem_usage += sz;
1369
}
1370
if (!src->index) {
1371
src->index = create_delta_index(src->data, src_size);
@@ -1376,7 +1375,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
1375
warning("suboptimal pack - out of memory");
1376
return 0;
1377
}
1379
- window_memory_usage += sizeof_delta_index(src->index);
1378
+ *mem_usage += sizeof_delta_index(src->index);
1379
}
1380
1381
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)
1422
return m;
1423
}
1424
1426
-static void free_unpacked(struct unpacked *n)
1425
+static unsigned long free_unpacked(struct unpacked *n)
1426
{
1428
- window_memory_usage -= sizeof_delta_index(n->index);
1427
+ unsigned long freed_mem = sizeof_delta_index(n->index);
1428
free_delta_index(n->index);
1429
n->index = NULL;
1430
if (n->data) {
1431
+ freed_mem += n->entry->size;
1432
free(n->data);
1433
n->data = NULL;
1434
- window_memory_usage -= n->entry->size;
1434
}
1435
n->entry = NULL;
1436
n->depth = 0;
1437
+ return freed_mem;
1438
}
1439
1440
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,
1443
uint32_t i = list_size, idx = 0, count = 0, processed = 0;
1444
unsigned int array_size = window * sizeof(struct unpacked);
1445
struct unpacked *array;
1446
- int max_depth;
1446
+ unsigned long mem_usage = 0;
1447
1448
array = xmalloc(array_size);
1449
memset(array, 0, array_size);
@@ -1453,16 +1453,16 @@ static void find_deltas(struct object_entry **list, unsigned list_size,
1453
do {
1454
struct object_entry *entry = list[--i];
1455
struct unpacked *n = array + idx;
1456
- int j, best_base = -1;
1456
+ int j, max_depth, best_base = -1;
1457
1458
- free_unpacked(n);
1458
+ mem_usage -= free_unpacked(n);
1459
n->entry = entry;
1460
1461
while (window_memory_limit &&
1462
- window_memory_usage > window_memory_limit &&
1462
+ mem_usage > window_memory_limit &&
1463
count > 1) {
1464
uint32_t tail = (idx + window - count) % window;
1465
- free_unpacked(array + tail);
1465
+ mem_usage -= free_unpacked(array + tail);
1466
count--;
1467
}
1468
@@ -1497,7 +1497,7 @@ static void find_deltas(struct object_entry **list, unsigned list_size,
1497
m = array + other_idx;
1498
if (!m->entry)
1499
break;
1500
- ret = try_delta(n, m, max_depth);
1500
+ ret = try_delta(n, m, max_depth, &mem_usage);
1501
if (ret < 0)
1502
break;
1503
else if (ret > 0)