Skip to content

Commit 0ef95f7

Browse files
Nicolas Pitregitster
authored andcommitted
pack-objects: free preferred base memory after usage
When adding objects for preferred delta base, the content from tree objects leading to given paths is kept in a cache. This has the potential to grow significantly, especially with large directories as the whole tree object content is loaded in memory, even if in practice the number of those objects is limited to the 256 cache entries plus the $window root tree objects. Still, that can't hurt freeing that up after object enumeration is done, and before more memory is needed for delta search. Signed-off-by: Nicolas Pitre <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6523078 commit 0ef95f7

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

builtin-pack-objects.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,33 @@ static void add_preferred_base(unsigned char *sha1)
10121012
it->pcache.tree_size = size;
10131013
}
10141014

1015+
static void cleanup_preferred_base(void)
1016+
{
1017+
struct pbase_tree *it;
1018+
unsigned i;
1019+
1020+
it = pbase_tree;
1021+
pbase_tree = NULL;
1022+
while (it) {
1023+
struct pbase_tree *this = it;
1024+
it = this->next;
1025+
free(this->pcache.tree_data);
1026+
free(this);
1027+
}
1028+
1029+
for (i = 0; i < ARRAY_SIZE(pbase_tree_cache); i++) {
1030+
if (!pbase_tree_cache[i])
1031+
continue;
1032+
free(pbase_tree_cache[i]->tree_data);
1033+
free(pbase_tree_cache[i]);
1034+
pbase_tree_cache[i] = NULL;
1035+
}
1036+
1037+
free(done_pbase_paths);
1038+
done_pbase_paths = NULL;
1039+
done_pbase_paths_num = done_pbase_paths_alloc = 0;
1040+
}
1041+
10151042
static void check_object(struct object_entry *entry)
10161043
{
10171044
if (entry->in_pack) {
@@ -2308,6 +2335,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
23082335
rp_av[rp_ac] = NULL;
23092336
get_object_list(rp_ac, rp_av);
23102337
}
2338+
cleanup_preferred_base();
23112339
if (include_tag && nr_result)
23122340
for_each_ref(add_ref_tag, NULL);
23132341
stop_progress(&progress_state);

0 commit comments

Comments
 (0)