diff options
| author | Gustavo Kissel <kisselgustavo@gmail.com> | 2026-11-23 14:57:59 -0300 |
|---|---|---|
| committer | Gustavo Kissel <kisselgustavo@gmail.com> | 2026-11-23 14:57:59 -0300 |
| commit | b170ab90eee8c085ae3a62cee9aa70884b8b1552 (patch) | |
| tree | 82f849c60029d5f96b87848f3b61b0c4242c8925 /runtime/test/xmem_test.cpp | |
| parent | 4a7bfd5c4d86eb4cf6e63ff8fcbb508729d8a948 (diff) | |
fix(xmem): cap host views at 1024 pages so a single-page unmap stays cheap
unmap_range splits a view by unmapping it and remapping both sides; with one view per run
that cost grew with the run (review on #7584). Capping views at 64 MiB bounds it.
Diffstat (limited to 'runtime/test/xmem_test.cpp')
| -rw-r--r-- | runtime/test/xmem_test.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/runtime/test/xmem_test.cpp b/runtime/test/xmem_test.cpp index a52886c16..256718b88 100644 --- a/runtime/test/xmem_test.cpp +++ b/runtime/test/xmem_test.cpp | |||
| @@ -458,6 +458,34 @@ void test_physical_pages(const PhysicalApi& api) { | |||
| 458 | } | 458 | } |
| 459 | 459 | ||
| 460 | // The placeholder flags pass through: reserve a placeholder, carve windows and committed memory out of it. | 460 | // The placeholder flags pass through: reserve a placeholder, carve windows and committed memory out of it. |
| 461 | // A run longer than one host view is mapped as capped views, so unmapping one page inside it only remaps the rest of | ||
| 462 | // that view; every other page keeps its contents. | ||
| 463 | void test_long_run(const PhysicalApi& api) { | ||
| 464 | constexpr uint64_t kPages = 1100; // more than the 1024-page view cap | ||
| 465 | auto* const window = static_cast<uint8_t*>( | ||
| 466 | api.virtual_alloc(nullptr, kPages * kPage64k, MEM_RESERVE | kXmem64kPages, 0x23, PAGE_READWRITE)); | ||
| 467 | std::vector<uint64_t> pages(kPages); | ||
| 468 | uint64_t count = kPages; | ||
| 469 | check(window && api.allocate(0x280, &count, pages.data()) == TRUE, "a long run's window and pages are allocated"); | ||
| 470 | if (!window || count != kPages) return; | ||
| 471 | check(api.map(window, kPages, pages.data()) == window, "a run longer than the view cap maps"); | ||
| 472 | MEMORY_BASIC_INFORMATION info{}; | ||
| 473 | VirtualQuery(window, &info, sizeof(info)); | ||
| 474 | check(info.State == MEM_COMMIT && info.RegionSize == 1024 * kPage64k, "it is mapped as views of at most 1024 pages"); | ||
| 475 | for (uint64_t i = 0; i < kPages; ++i) fill_page(window + i * kPage64k, static_cast<uint32_t>(i + 1)); | ||
| 476 | void* const hole = window + 10 * kPage64k; | ||
| 477 | check(api.scatter(&hole, 1, nullptr) == TRUE && reserved_only(hole), "a page inside the first view unmaps"); | ||
| 478 | bool kept = true; | ||
| 479 | for (uint64_t i = 0; i < kPages; ++i) { | ||
| 480 | if (i != 10) kept &= page_holds(window + i * kPage64k, static_cast<uint32_t>(i + 1)); | ||
| 481 | } | ||
| 482 | check(kept, "every other page of the run keeps its contents"); | ||
| 483 | check(api.map(window, kPages, nullptr) == window && reserved_only(window) && | ||
| 484 | reserved_only(window + (kPages - 1) * kPage64k), | ||
| 485 | "the whole run unmaps"); | ||
| 486 | check(api.free_pages(kPages, pages.data()) == TRUE, "the long run's pages are freed"); | ||
| 487 | } | ||
| 488 | |||
| 461 | void test_placeholders(const PhysicalApi& api) { | 489 | void test_placeholders(const PhysicalApi& api) { |
| 462 | auto* const base = static_cast<uint8_t*>( | 490 | auto* const base = static_cast<uint8_t*>( |
| 463 | api.virtual_alloc(nullptr, 6 * kPage64k, MEM_RESERVE | MEM_RESERVE_PLACEHOLDER, 7, PAGE_NOACCESS)); | 491 | api.virtual_alloc(nullptr, 6 * kPage64k, MEM_RESERVE | MEM_RESERVE_PLACEHOLDER, 7, PAGE_NOACCESS)); |
| @@ -735,6 +763,7 @@ int main() { | |||
| 735 | if (tools_mem) check(tools_mem() == FALSE, "XMemIsToolsMemAvailable returns FALSE (no devkit tools memory)"); | 763 | if (tools_mem) check(tools_mem() == FALSE, "XMemIsToolsMemAvailable returns FALSE (no devkit tools memory)"); |
| 736 | if (virtual_alloc && physical.allocate && physical.free_pages && physical.map && physical.scatter) { | 764 | if (virtual_alloc && physical.allocate && physical.free_pages && physical.map && physical.scatter) { |
| 737 | test_physical_pages(physical); | 765 | test_physical_pages(physical); |
| 766 | test_long_run(physical); | ||
| 738 | test_placeholders(physical); | 767 | test_placeholders(physical); |
| 739 | } | 768 | } |
| 740 | 769 | ||