From c70afdbe472b80151cbe65395b95283848ade62e Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Fri, 22 Nov 2024 18:08:19 -0800 Subject: [SharedCache] Have VM track ranges rather than pages There are typically only a few dozen mappings, while there can be millions of pages. This reduces the amount of time spent populating the mapping from region to file accessor along with the memory usage of the same. --- view/sharedcache/core/VM.h | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'view/sharedcache/core/VM.h') diff --git a/view/sharedcache/core/VM.h b/view/sharedcache/core/VM.h index b8e5c59b..e47cf15e 100644 --- a/view/sharedcache/core/VM.h +++ b/view/sharedcache/core/VM.h @@ -183,7 +183,7 @@ struct PageMapping { std::shared_ptr> fileAccessor; size_t fileOffset; PageMapping(std::string filePath, std::shared_ptr> fileAccessor, size_t fileOffset) - : filePath(filePath), fileAccessor(fileAccessor), fileOffset(fileOffset) {} + : filePath(std::move(filePath)), fileAccessor(std::move(fileAccessor)), fileOffset(fileOffset) {} }; @@ -215,9 +215,30 @@ class VMReader; class VM { - std::map m_map; + + // Represents a range of addresses [start, end). + // Note that `end` is not included within the range. + struct AddressRange { + size_t start; + size_t end; + + bool operator<(const AddressRange& b) const { + return start < b.start || (start == b.start && end < b.end); + } + + friend bool operator<(const AddressRange& range, size_t address) { + return range.end <= address; + } + + friend bool operator<(size_t address, const AddressRange& range) { + return address < range.start; + } + }; + + // A map keyed by address ranges that can be looked up via any + // address within a range thanks to C++14's transparent comparators. + std::map> m_map; size_t m_pageSize; - size_t m_pageSizeBits; bool m_safe; friend VMReader; -- cgit v1.3.1