diff options
author | Taylor Blau <me@ttaylorr.com> | 2024-06-25 19:40:15 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-06-25 22:52:06 +0200 |
commit | 9c8a9ec787149dc4f4b278d9bd8ad94c96691a5f (patch) | |
tree | aa85a3b02f7778ae2db9d9c8af222d9fcf241680 /bloom.h | |
parent | commit-graph: reuse existing Bloom filters where possible (diff) | |
download | git-9c8a9ec787149dc4f4b278d9bd8ad94c96691a5f.tar.xz git-9c8a9ec787149dc4f4b278d9bd8ad94c96691a5f.zip |
bloom: introduce `deinit_bloom_filters()`
After we are done using Bloom filters, we do not currently clean up any
memory allocated by the commit slab used to store those filters in the
first place.
Besides the bloom_filter structures themselves, there is mostly nothing
to free() in the first place, since in the read-only path all Bloom
filter's `data` members point to a memory mapped region in the
commit-graph file itself.
But when generating Bloom filters from scratch (or initializing
truncated filters) we allocate additional memory to store the filter's
data.
Keep track of when we need to free() this additional chunk of memory by
using an extra pointer `to_free`. Most of the time this will be NULL
(indicating that we are representing an existing Bloom filter stored in
a memory mapped region). When it is non-NULL, free it before discarding
the Bloom filters slab.
Suggested-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'bloom.h')
-rw-r--r-- | bloom.h | 3 |
1 files changed, 3 insertions, 0 deletions
@@ -56,6 +56,8 @@ struct bloom_filter { unsigned char *data; size_t len; int version; + + void *to_free; }; /* @@ -96,6 +98,7 @@ void add_key_to_filter(const struct bloom_key *key, const struct bloom_filter_settings *settings); void init_bloom_filters(void); +void deinit_bloom_filters(void); enum bloom_filter_computed { BLOOM_NOT_COMPUTED = (1 << 0), |