delta-islands: free island_marks and bitmaps
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 <e@80x24.org> Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Helped-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Wong committed
Feb 3, 2023 at 23:44 UTC
647982bb7171b2409f2a90da245b8a31913f930f
3 files changed
+18
-1
builtin/pack-objects.c
+3
-1
@@ -929,8 +929,10 @@ static struct object_entry **compute_write_order(void)
929
*/
930
for_each_tag_ref(mark_tagged, NULL);
931
932
- if (use_delta_islands)
932
+ if (use_delta_islands) {
933
max_layers = compute_pack_layers(&to_pack);
934
+ free_island_marks();
935
+ }
936
937
ALLOC_ARRAY(wo, to_pack.nr_objects);
938
wo_end = 0;
delta-islands.c
+14
@@ -513,6 +513,20 @@ void propagate_island_marks(struct commit *commit)
513
}
514
}
515
516
+void free_island_marks(void)
517
+{
518
+ struct island_bitmap *bitmap;
519
+
520
+ kh_foreach_value(island_marks, bitmap, {
521
+ if (!--bitmap->refcount)
522
+ free(bitmap);
523
+ });
524
+ kh_destroy_oid_map(island_marks);
525
+
526
+ /* detect use-after-free with a an address which is never valid: */
527
+ island_marks = (void *)-1;
528
+}
529
+
530
int compute_pack_layers(struct packing_data *to_pack)
531
{
532
uint32_t i;
delta-islands.h
+1
@@ -14,5 +14,6 @@ void resolve_tree_islands(struct repository *r,
14
void load_delta_islands(struct repository *r, int progress);
15
void propagate_island_marks(struct commit *commit);
16
int compute_pack_layers(struct packing_data *to_pack);
17
+void free_island_marks(void);
18
19
#endif /* DELTA_ISLANDS_H */