Files
Felipe de Azevedo Piovezan 091b20e78c [lldb] Use std::map in MemoryRegionInfoCache (#206986)
The RangeVector abstraction is slow w.r.t. amount of sorting it
requires, and it is particularly bad when sorting a MemoryRegionInfo, as
this object is expensive to move. All of this is aggravated in sanitizer
bots, where a handful of tests started timing out as a result of the
MemoryRegionInfoCache.

This commit fixes the situation by simplifying the code: just use a
std::map. Based on current usage, behaviour should be identical to
before. In particular, neither case addresses cases like this:

1. Insert range [100, 200]
2. Insert range [150, 160]
3. Query address 170.

In both cases we fail to find a cached range and proceed to query the
inferior again. Which is not incorrect, jut doesn't maximize the cache
usage.

A proper fix is to use an interval tree, with the assumption that if
overlapping ranges are inserted, they have the same memory region info
contents and we can just join the intervals.
2026-07-02 07:59:53 +01:00

42 lines
1.3 KiB
C++

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "lldb/Target/MemoryRegionInfoCache.h"
#include "lldb/Target/MemoryRegionInfo.h"
using namespace lldb;
using namespace lldb_private;
void MemoryRegionInfoCache::Clear() {
std::lock_guard<std::mutex> guard(m_mutex);
m_region_infos.clear();
}
size_t MemoryRegionInfoCache::GetSize() {
std::lock_guard<std::mutex> guard(m_mutex);
return m_region_infos.size();
}
std::optional<MemoryRegionInfo>
MemoryRegionInfoCache::GetMemoryRegion(addr_t load_addr) {
std::lock_guard<std::mutex> guard(m_mutex);
auto it = m_region_infos.upper_bound(load_addr);
if (it == m_region_infos.begin())
return std::nullopt;
--it;
if (load_addr < it->second.GetRange().GetRangeEnd())
return it->second;
return std::nullopt;
}
void MemoryRegionInfoCache::AddRegion(const MemoryRegionInfo &ri) {
std::lock_guard<std::mutex> guard(m_mutex);
m_region_infos.insert_or_assign(ri.GetRange().GetRangeBase(), ri);
}