Skip to content

Commit c4955d3

Browse files
authored
fix segfault in defragmentation (#1404)
1 parent 95eb44c commit c4955d3

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

runtime-common/core/memory-resource/details/memory_ordered_chunk_list.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ void memory_ordered_chunk_list::save_next(list_node* node, const list_node* next
3131
}
3232

3333
void memory_ordered_chunk_list::add_from_array(list_node** first, list_node** last) noexcept {
34-
if (first == last) {
35-
return;
36-
}
37-
34+
// There may be memory blocks in the range [first, last) that do not belong to
35+
// this memory resource's main arena, such as those from extra allocations.
36+
// For now, simply skip these blocks.
3837
last = std::partition(first, last, [this](const auto* mem) {
3938
return reinterpret_cast<uintptr_t>(mem) >= reinterpret_cast<uintptr_t>(this->memory_resource_begin_) &&
4039
reinterpret_cast<uintptr_t>(mem) < reinterpret_cast<uintptr_t>(this->memory_resource_end_);
4140
});
41+
42+
if (first == last) {
43+
return;
44+
}
45+
4246
std::sort(first, last, std::greater<>{});
4347

4448
if (!head_) {

runtime-light/state/component-state.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ struct ComponentState final : private vk::not_copyable {
3838
private:
3939
static constexpr std::string_view INI_ARG_PREFIX = "ini ";
4040
static constexpr std::string_view RUNTIME_CONFIG_ARG = "runtime-config";
41-
// FIXME: Temporary workaround (increased INIT_COMPONENT_ALLOCATOR_SIZE) to prevent segmentation fault during defragmentation
42-
static constexpr auto INIT_COMPONENT_ALLOCATOR_SIZE = static_cast<size_t>(128U * 1024U * 1024U); // 128MB
41+
static constexpr auto INIT_COMPONENT_ALLOCATOR_SIZE = static_cast<size_t>(1024U * 1024U); // 1MB
4342

4443
void parse_env() noexcept;
4544

runtime-light/state/image-state.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ struct ImageState final : private vk::not_copyable {
8787
}
8888

8989
private:
90-
static constexpr auto INIT_IMAGE_ALLOCATOR_SIZE = static_cast<size_t>(16U * 1024U * 1024U); // 16 MB
90+
static constexpr auto INIT_IMAGE_ALLOCATOR_SIZE = static_cast<size_t>(1024U * 1024U); // 1MB
9191
};

0 commit comments

Comments
 (0)