From 647982bb7171b2409f2a90da245b8a31913f930f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 3 Feb 2023 23:44:30 +0000 Subject: [PATCH] delta-islands: free island_marks and bitmaps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On my mirror of linux.git forkgroup with 780 islands, this saves nearly 4G of heap memory in pack-objects. This savings only benefits delta island users of pack bitmaps, as the process would otherwise be exiting anyways. However, there's probably not many delta island users, but the majority of delta island users would also be pack bitmaps users. Signed-off-by: Eric Wong Helped-by: Ævar Arnfjörð Bjarmason Helped-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/pack-objects.c | 4 +++- delta-islands.c | 14 ++++++++++++++ delta-islands.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 573d0b20b76..f305dd31876 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -929,8 +929,10 @@ static struct object_entry **compute_write_order(void) */ for_each_tag_ref(mark_tagged, NULL); - if (use_delta_islands) + if (use_delta_islands) { max_layers = compute_pack_layers(&to_pack); + free_island_marks(); + } ALLOC_ARRAY(wo, to_pack.nr_objects); wo_end = 0; diff --git a/delta-islands.c b/delta-islands.c index 90c0d6958f4..8b234cb85b0 100644 --- a/delta-islands.c +++ b/delta-islands.c @@ -513,6 +513,20 @@ void propagate_island_marks(struct commit *commit) } } +void free_island_marks(void) +{ + struct island_bitmap *bitmap; + + kh_foreach_value(island_marks, bitmap, { + if (!--bitmap->refcount) + free(bitmap); + }); + kh_destroy_oid_map(island_marks); + + /* detect use-after-free with a an address which is never valid: */ + island_marks = (void *)-1; +} + int compute_pack_layers(struct packing_data *to_pack) { uint32_t i; diff --git a/delta-islands.h b/delta-islands.h index eb0f952629f..8d1591ae28b 100644 --- a/delta-islands.h +++ b/delta-islands.h @@ -14,5 +14,6 @@ void resolve_tree_islands(struct repository *r, void load_delta_islands(struct repository *r, int progress); void propagate_island_marks(struct commit *commit); int compute_pack_layers(struct packing_data *to_pack); +void free_island_marks(void); #endif /* DELTA_ISLANDS_H */