libdrgn: don't preallocate DWARF index memory

This doesn't make things any faster in my benchmarks, and it complicates
DWARF index initialization.
This commit is contained in:
Omar Sandoval 2019-06-07 12:06:53 -07:00
parent ec33f9bf73
commit 8a59a7e819
3 changed files with 8 additions and 32 deletions

View File

@ -230,11 +230,8 @@ static void free_shards(struct drgn_dwarf_index *dindex, size_t n)
} }
} }
struct drgn_error *drgn_dwarf_index_init(struct drgn_dwarf_index *dindex) void drgn_dwarf_index_init(struct drgn_dwarf_index *dindex)
{ {
static const size_t initial_shard_capacity =
max(1024 >> DRGN_DWARF_INDEX_SHARD_BITS, 1);
struct drgn_error *err;
size_t i; size_t i;
drgn_dwarf_index_file_table_init(&dindex->files); drgn_dwarf_index_file_table_init(&dindex->files);
@ -246,22 +243,9 @@ struct drgn_error *drgn_dwarf_index_init(struct drgn_dwarf_index *dindex)
omp_init_lock(&shard->lock); omp_init_lock(&shard->lock);
drgn_dwarf_index_die_map_init(&shard->map); drgn_dwarf_index_die_map_init(&shard->map);
shard->num_entries = 0; shard->num_entries = 0;
shard->entries_capacity = initial_shard_capacity; shard->entries_capacity = 0;
shard->dies = malloc_array(initial_shard_capacity, shard->dies = NULL;
sizeof(*shard->dies));
if (!shard->dies ||
!drgn_dwarf_index_die_map_reserve(&shard->map,
initial_shard_capacity)) {
free_shards(dindex, i + 1);
err = &drgn_enomem;
goto err;
}
} }
return NULL;
err:
drgn_dwarf_index_file_table_deinit(&dindex->files);
return err;
} }
static void free_files(struct drgn_dwarf_index *dindex, static void free_files(struct drgn_dwarf_index *dindex,
@ -1202,7 +1186,8 @@ static bool append_die_entry(struct drgn_dwarf_index_shard *shard, uint64_t tag,
if (shard->num_entries >= shard->entries_capacity) { if (shard->num_entries >= shard->entries_capacity) {
size_t new_capacity; size_t new_capacity;
new_capacity = shard->entries_capacity * 2; new_capacity = (shard->entries_capacity ?
shard->entries_capacity * 2 : 4);
if (!resize_array(&shard->dies, new_capacity)) if (!resize_array(&shard->dies, new_capacity))
return false; return false;
shard->entries_capacity = new_capacity; shard->entries_capacity = new_capacity;

View File

@ -123,12 +123,8 @@ struct drgn_dwarf_index {
struct drgn_dwarf_index_shard shards[1 << DRGN_DWARF_INDEX_SHARD_BITS]; struct drgn_dwarf_index_shard shards[1 << DRGN_DWARF_INDEX_SHARD_BITS];
}; };
/** /** Initialize a @ref drgn_dwarf_index. */
* Initialize a @ref drgn_dwarf_index. void drgn_dwarf_index_init(struct drgn_dwarf_index *dindex);
*
* @return @c NULL on success, non-@c NULL on error.
*/
struct drgn_error *drgn_dwarf_index_init(struct drgn_dwarf_index *dindex);
/** /**
* Deinitialize a @ref drgn_dwarf_index. * Deinitialize a @ref drgn_dwarf_index.

View File

@ -1546,17 +1546,12 @@ struct drgn_error *
drgn_dwarf_info_cache_create(struct drgn_type_index *tindex, drgn_dwarf_info_cache_create(struct drgn_type_index *tindex,
struct drgn_dwarf_info_cache **ret) struct drgn_dwarf_info_cache **ret)
{ {
struct drgn_error *err;
struct drgn_dwarf_info_cache *dicache; struct drgn_dwarf_info_cache *dicache;
dicache = malloc(sizeof(*dicache)); dicache = malloc(sizeof(*dicache));
if (!dicache) if (!dicache)
return &drgn_enomem; return &drgn_enomem;
err = drgn_dwarf_index_init(&dicache->dindex); drgn_dwarf_index_init(&dicache->dindex);
if (err) {
free(dicache);
return err;
}
dwarf_type_map_init(&dicache->map); dwarf_type_map_init(&dicache->map);
dwarf_type_map_init(&dicache->cant_be_incomplete_array_map); dwarf_type_map_init(&dicache->cant_be_incomplete_array_map);
dicache->depth = 0; dicache->depth = 0;