Skip to content

Commit c34853c

Browse files
committed
Disallow simultaneous usage of balloon device and huge pages
The balloon device does not work with huge pages, so for now disallow using them together. Signed-off-by: Patrick Roy <[email protected]>
1 parent c0287ca commit c34853c

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

src/vmm/src/resources.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ impl VmResources {
261261
return Err(VmConfigError::IncompatibleBalloonSize);
262262
}
263263

264+
if self.balloon.get().is_some() && updated.huge_pages != HugePageConfig::None {
265+
return Err(VmConfigError::BalloonAndHugePages);
266+
}
267+
264268
self.vm_config = updated;
265269

266270
Ok(())
@@ -325,6 +329,10 @@ impl VmResources {
325329
return Err(BalloonConfigError::TooManyPagesRequested);
326330
}
327331

332+
if self.vm_config.huge_pages != HugePageConfig::None {
333+
return Err(BalloonConfigError::HugePages);
334+
}
335+
328336
self.balloon.set(config)
329337
}
330338

@@ -1389,6 +1397,9 @@ mod tests {
13891397

13901398
if KernelVersion::get().unwrap() >= KernelVersion::new(5, 10, 0) {
13911399
aux_vm_config.mem_size_mib = Some(2048);
1400+
// Remove the balloon device config that's added by `default_vm_resources` as it would
1401+
// trigger the "ballooning incompatible with huge pages" check.
1402+
vm_resources.balloon = BalloonBuilder::new();
13921403
vm_resources.update_vm_config(&aux_vm_config).unwrap();
13931404
}
13941405
}

src/vmm/src/vmm_config/balloon.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pub enum BalloonConfigError {
2828
CreateFailure(crate::devices::virtio::balloon::BalloonError),
2929
/// Error updating the balloon device configuration: {0:?}
3030
UpdateFailure(std::io::Error),
31+
/// Firecracker's huge pages support is incompatible with memory ballooning.
32+
HugePages,
3133
}
3234

3335
/// This struct represents the strongly typed equivalent of the json body

src/vmm/src/vmm_config/machine_config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pub enum VmConfigError {
3333
KernelVersion,
3434
/// Firecracker's hugetlbfs support requires at least host kernel 5.10.
3535
HugetlbfsNotSupported,
36+
/// Firecracker's huge pages support is incompatible with memory ballooning.
37+
BalloonAndHugePages,
3638
}
3739

3840
// We cannot do a `KernelVersion(kernel_version::Error)` variant because `kernel_version::Error`

tests/integration_tests/performance/test_huge_pages.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,30 @@ def test_hugetlbfs_snapshot(
112112
assert not rc
113113

114114
check_hugetlbfs_in_use(vm.firecracker_pid, "/anon_hugepage")
115+
116+
117+
@pytest.mark.skipif(
118+
global_props.host_linux_version == "4.14",
119+
reason="MFD_HUGETLB | MFD_ALLOW_SEALING only supported on kernels >= 4.16",
120+
)
121+
def test_negative_huge_pages_plus_balloon(uvm_plain):
122+
"""Tests that huge pages and memory ballooning cannot be used together"""
123+
uvm_plain.memory_monitor = None
124+
uvm_plain.spawn()
125+
126+
# Ensure setting huge pages and then adding a balloon device doesn't work
127+
uvm_plain.basic_config(huge_pages=HugePagesConfig.HUGETLBFS_2MB)
128+
with pytest.raises(
129+
RuntimeError,
130+
match="Firecracker's huge pages support is incompatible with memory ballooning.",
131+
):
132+
uvm_plain.api.balloon.put(amount_mib=0, deflate_on_oom=False)
133+
134+
# Ensure adding a balloon device and then setting huge pages doesn't work
135+
uvm_plain.basic_config(huge_pages=HugePagesConfig.NONE)
136+
uvm_plain.api.balloon.put(amount_mib=0, deflate_on_oom=False)
137+
with pytest.raises(
138+
RuntimeError,
139+
match="Machine config error: Firecracker's huge pages support is incompatible with memory ballooning.",
140+
):
141+
uvm_plain.basic_config(huge_pages=HugePagesConfig.HUGETLBFS_2MB)

0 commit comments

Comments
 (0)