|
1 | 1 | # Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
2 | 2 | # SPDX-License-Identifier: Apache-2.0 |
3 | 3 | """Performance benchmark for snapshot restore.""" |
| 4 | +import re |
4 | 5 | import signal |
5 | 6 | import tempfile |
6 | 7 | import time |
@@ -172,3 +173,40 @@ def test_post_restore_latency( |
172 | 173 | ) |
173 | 174 |
|
174 | 175 | metrics.put_metric("fault_latency", int(duration) / NS_IN_MSEC, "Milliseconds") |
| 176 | + |
| 177 | + |
| 178 | +@pytest.mark.nonci |
| 179 | +@pytest.mark.parametrize("huge_pages", HugePagesConfig) |
| 180 | +def test_population_latency( |
| 181 | + microvm_factory, rootfs, guest_kernel_linux_5_10, metrics, huge_pages |
| 182 | +): |
| 183 | + """Collects population latency metrics (e.g. how long it takes UFFD handler to fault in all memory)""" |
| 184 | + test_setup = SnapshotRestoreTest(mem=128, vcpus=1, huge_pages=huge_pages) |
| 185 | + vm = test_setup.configure_vm( |
| 186 | + microvm_factory, guest_kernel_linux_5_10, rootfs, metrics |
| 187 | + ) |
| 188 | + snapshot = vm.snapshot_full() |
| 189 | + vm.kill() |
| 190 | + |
| 191 | + for microvm in microvm_factory.build_n_from_snapshot( |
| 192 | + snapshot, ITERATIONS, uffd_handler_name="fault_all" |
| 193 | + ): |
| 194 | + # do _something_ to trigger a pagefault, which will then cause the UFFD handler to fault in _everything_ |
| 195 | + microvm.ssh.check_output("true") |
| 196 | + |
| 197 | + for _ in range(5): |
| 198 | + time.sleep(1) |
| 199 | + |
| 200 | + match = re.match( |
| 201 | + r"Finished Faulting All: (\d+)us", microvm.uffd_handler.log_data |
| 202 | + ) |
| 203 | + |
| 204 | + if match: |
| 205 | + latency_us = int(match.group(1)) |
| 206 | + |
| 207 | + metrics.put_metric( |
| 208 | + "populate_latency", latency_us / 1000, "Milliseconds" |
| 209 | + ) |
| 210 | + break |
| 211 | + else: |
| 212 | + raise RuntimeError("UFFD handler did not print population latency after 5s") |
0 commit comments