Skip to content

Commit da8f248

Browse files
committed
Hibernation: Add check for disk space requirement
1. Hibernation requires free disk space proportional to RAM of the machine. LISA currently does not support os disk size as a requirement. 2. Azure does not support Hibernation for VM with memory larger than 256 GB
1 parent c3396f7 commit da8f248

File tree

3 files changed

+75
-3
lines changed

3 files changed

+75
-3
lines changed

lisa/microsoft/testsuites/power/common.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
Df,
1616
Dmesg,
1717
Fio,
18+
Free,
1819
HibernationSetup,
1920
Hwclock,
2021
Iperf3,
@@ -49,6 +50,60 @@ def is_distro_supported(node: Node) -> None:
4950
)
5051

5152

53+
def check_hibernation_disk_requirements(node: Node) -> None:
54+
"""
55+
Check if the VM has sufficient disk space for hibernation.
56+
Hibernation requires disk space based on RAM size using the formula:
57+
- 2 × RAM if RAM ≤ 8 GB
58+
- 1.5 × RAM if 8 < RAM ≤ 64 GB
59+
- RAM if 64 < RAM ≤ 256 GB
60+
- Not supported if RAM > 256 GB
61+
"""
62+
free_tool = node.tools[Free]
63+
df_tool = node.tools[Df]
64+
65+
# Get total memory in KB
66+
total_memory_kb = free_tool._get_field_bytes_kib("Mem", "total")
67+
total_memory_gb = total_memory_kb / (1024 * 1024) # Convert KB to GB
68+
69+
# Skip hibernation check for VMs with > 256 GB RAM
70+
if total_memory_gb > 256:
71+
raise SkippedException(
72+
f"Hibernation is not supported for VMs with RAM > 256 GB. "
73+
f"Current RAM: {total_memory_gb:.2f} GB"
74+
)
75+
76+
# Calculate required swap space based on RAM size
77+
if total_memory_gb <= 8:
78+
required_space_gb = 2 * total_memory_gb
79+
formula = "2*RAM"
80+
elif total_memory_gb <= 64:
81+
required_space_gb = 1.5 * total_memory_gb
82+
formula = "1.5*RAM"
83+
else:
84+
required_space_gb = total_memory_gb
85+
formula = "RAM"
86+
87+
# Add 20% buffer for filesystem overhead, defragmentation, and safety margin
88+
required_space_with_buffer = required_space_gb * 1.2
89+
90+
root_partition = df_tool.get_partition_by_mountpoint("/", force_run=True)
91+
assert root_partition is not None, "Unable to determine root partition disk space"
92+
93+
# available_blocks is in 1K blocks, convert to GB
94+
available_space_gb = root_partition.available_blocks / 1024 / 1024
95+
96+
if available_space_gb < required_space_with_buffer:
97+
raise LisaException(
98+
f"Insufficient disk space for hibernation. "
99+
f"Memory size: {total_memory_gb:.2f} GB, "
100+
f"Available space: {available_space_gb:.2f} GB, "
101+
f"Required space: {required_space_gb:.2f} GB ({formula}), "
102+
f"Recommended (20% buffer): {required_space_with_buffer:.2f} GB. "
103+
f"Please increase 'osdisk_size_in_gb'."
104+
)
105+
106+
52107
def _prepare_hibernation_environment(node: Node) -> None:
53108
"""
54109
Prepare the hibernation environment by handling OS-specific requirements.

lisa/microsoft/testsuites/power/power.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from assertpy import assert_that
88
from func_timeout import func_timeout
99
from microsoft.testsuites.power.common import (
10+
check_hibernation_disk_requirements,
1011
cleanup_env,
1112
is_distro_supported,
1213
run_network_workload,
@@ -46,6 +47,8 @@ def before_case(self, log: Logger, **kwargs: Any) -> None:
4647
if isinstance(node.os, BSD) or isinstance(node.os, Windows):
4748
raise SkippedException(f"{node.os} is not supported.")
4849

50+
check_hibernation_disk_requirements(node)
51+
4952
@TestCaseMetadata(
5053
description="""
5154
This case is to verify vm hibernation with synthetic network.

lisa/tools/hibernation_setup.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ class HibernationSetup(Tool):
3636
re.MULTILINE,
3737
)
3838

39+
# Defrag size is larger than filesystem's free space
40+
_defrag_space_error_pattern = re.compile(
41+
r"Defrag size is larger than filesystem's free space",
42+
re.MULTILINE,
43+
)
44+
3945
"""
4046
The below shows an example output of `filefrag -v /hibfile.sys`
4147
We are interested in the physical offset of the hibfile.
@@ -90,9 +96,17 @@ def check_uevent(self) -> int:
9096

9197
def _analyze_stdout_for_errors(self, stdout: str) -> None:
9298
# Check for insufficient swap space error
93-
error_message = get_matched_str(stdout, self._insufficient_swap_space_pattern)
94-
if error_message:
95-
raise LisaException(f"Hibernation setup failed: {error_message}")
99+
swap_error = get_matched_str(stdout, self._insufficient_swap_space_pattern)
100+
if swap_error:
101+
raise LisaException(f"Hibernation setup failed: {swap_error}")
102+
103+
# Check for defrag space error
104+
defrag_error = get_matched_str(stdout, self._defrag_space_error_pattern)
105+
if defrag_error:
106+
raise LisaException(
107+
f"Hibernation setup failed: {defrag_error}. "
108+
"Please increase osdisk_size_in_gb."
109+
)
96110

97111
def hibernate(self) -> None:
98112
self.node.tools[Systemctl].hibernate()

0 commit comments

Comments
 (0)