Skip to content

Commit e4ff865

Browse files
committed
test: differential snapshots and hugepages works
Differential snapshots work with hugetlbfs pages out of the box. This is because despite guest memory being backed by 2M pages, KVM still keeps a dirty log at 4K granularity. This means we do not need to adjust our differential snapshot logic to handle 2M chunks, as the existing logic for 4K chunks stays valid. Signed-off-by: Patrick Roy <[email protected]>
1 parent e44f6ad commit e4ff865

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

tests/integration_tests/performance/test_huge_pages.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,59 @@ def test_hugetlbfs_snapshot(
121121
check_hugetlbfs_in_use(vm.firecracker_pid, "/anon_hugepage")
122122

123123

124+
@pytest.mark.skipif(
125+
global_props.host_linux_version == "4.14",
126+
reason="MFD_HUGETLB | MFD_ALLOW_SEALING only supported on kernels >= 4.16",
127+
)
128+
def test_hugetlbfs_diff_snapshot(microvm_factory, uvm_plain, uffd_handler_paths):
129+
"""
130+
Test hugetlbfs differential snapshot support.
131+
132+
Despite guest memory being backed by huge pages, differential snapshots still work at 4K granularity.
133+
"""
134+
135+
### Create Snapshot ###
136+
uvm_plain.memory_monitor = None
137+
uvm_plain.spawn()
138+
uvm_plain.basic_config(
139+
huge_pages=HugePagesConfig.HUGETLBFS_2MB,
140+
mem_size_mib=128,
141+
track_dirty_pages=True,
142+
)
143+
uvm_plain.add_net_iface()
144+
uvm_plain.start()
145+
146+
# Wait for microvm to boot
147+
rc, _, _ = uvm_plain.ssh.run("true")
148+
assert not rc
149+
150+
base_snapshot = uvm_plain.snapshot_diff()
151+
uvm_plain.resume()
152+
153+
# Run command to dirty some pages
154+
rc, _, _ = uvm_plain.ssh.run("sync")
155+
assert not rc
156+
157+
snapshot_diff = uvm_plain.snapshot_diff()
158+
snapshot_merged = snapshot_diff.rebase_snapshot(base_snapshot)
159+
160+
uvm_plain.kill()
161+
162+
vm = microvm_factory.build()
163+
vm.spawn()
164+
165+
# Spawn page fault handler process.
166+
_pf_handler = spawn_pf_handler(
167+
vm, uffd_handler_paths["valid_2m_handler"], snapshot_merged.mem
168+
)
169+
170+
vm.restore_from_snapshot(snapshot_merged, resume=True, uffd_path=SOCKET_PATH)
171+
172+
# Verify if guest can run commands.
173+
rc, _, _ = vm.ssh.run("true")
174+
assert not rc
175+
176+
124177
@pytest.mark.skipif(
125178
global_props.host_linux_version == "4.14",
126179
reason="MFD_HUGETLB | MFD_ALLOW_SEALING only supported on kernels >= 4.16",

0 commit comments

Comments
 (0)