@matheusbsbs / matheus-bagliano / commits / 9c2174350c
Fork 0

pack-objects: only throw away data during memory pressure

If pack-objects hit the memory limit, it deletes objects from the delta window. This patch make it only delete the data, which is recomputed, if needed again. Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at> Acked-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin Koegler committed Feb 11, 2008 at 08:26 UTC 9c2174350cc0ae0f6bad126e15fe1f9f044117ab
1 file changed +11 -2
builtin-pack-objects.c
+11 -2
@@ -1464,7 +1464,7 @@ static unsigned int check_delta_limit(struct object_entry *me, unsigned int n)
1464 return m;
1465 }
1466
1467 -static unsigned long free_unpacked(struct unpacked *n)
1467 +static unsigned long free_unpacked_data(struct unpacked *n)
1468 {
1469 unsigned long freed_mem = sizeof_delta_index(n->index);
1470 free_delta_index(n->index);
@@ -1474,6 +1474,12 @@ static unsigned long free_unpacked(struct unpacked *n)
1474 free(n->data);
1475 n->data = NULL;
1476 }
1477 + return freed_mem;
1478 +}
1479 +
1480 +static unsigned long free_unpacked(struct unpacked *n)
1481 +{
1482 + unsigned long freed_mem = free_unpacked_data(n);
1483 n->entry = NULL;
1484 n->depth = 0;
1485 return freed_mem;
@@ -1514,7 +1520,7 @@ static void find_deltas(struct object_entry **list, unsigned *list_size,
1520 mem_usage > window_memory_limit &&
1521 count > 1) {
1522 uint32_t tail = (idx + window - count) % window;
1517 - mem_usage -= free_unpacked(array + tail);
1523 + mem_usage -= free_unpacked_data(array + tail);
1524 count--;
1525 }
1526
@@ -1547,6 +1553,9 @@ static void find_deltas(struct object_entry **list, unsigned *list_size,
1553 if (!m->entry)
1554 break;
1555 ret = try_delta(n, m, max_depth, &mem_usage);
1556 + if (window_memory_limit &&
1557 + mem_usage > window_memory_limit)
1558 + mem_usage -= free_unpacked_data(m);
1559 if (ret < 0)
1560 break;
1561 else if (ret > 0)