diff options
| author | Mark Rowe <mrowe@bdash.net.nz> | 2024-11-22 18:08:19 -0800 |
|---|---|---|
| committer | kat <kat@vector35.com> | 2024-12-10 10:39:14 -0500 |
| commit | c70afdbe472b80151cbe65395b95283848ade62e (patch) | |
| tree | 20639ff02e4bf5f1637be51e40e40d0259894738 /view/sharedcache/core/VM.h | |
| parent | a2e5d06195c6ec725fa311220ea7037abbb9ce69 (diff) | |
[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.
Diffstat (limited to 'view/sharedcache/core/VM.h')
| -rw-r--r-- | view/sharedcache/core/VM.h | 27 |
1 files changed, 24 insertions, 3 deletions
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<SelfAllocatingWeakPtr<MMappedFileAccessor>> fileAccessor; size_t fileOffset; PageMapping(std::string filePath, std::shared_ptr<SelfAllocatingWeakPtr<MMappedFileAccessor>> 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<size_t, PageMapping> 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<AddressRange, PageMapping, std::less<>> m_map; size_t m_pageSize; - size_t m_pageSizeBits; bool m_safe; friend VMReader; |
