Skip to content

Commit

Permalink
Disallow simultaneous usage of balloon device and huge pages
Browse files Browse the repository at this point in the history
The balloon device does not work with huge pages, so for now disallow
using them together.

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
  • Loading branch information
roypat committed Jan 18, 2024
1 parent c0287ca commit c34853c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/vmm/src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ impl VmResources {
return Err(VmConfigError::IncompatibleBalloonSize);
}

if self.balloon.get().is_some() && updated.huge_pages != HugePageConfig::None {
return Err(VmConfigError::BalloonAndHugePages);

Check warning on line 265 in src/vmm/src/resources.rs

View check run for this annotation

Codecov / codecov/patch

src/vmm/src/resources.rs#L265

Added line #L265 was not covered by tests
}

self.vm_config = updated;

Ok(())
Expand Down Expand Up @@ -325,6 +329,10 @@ impl VmResources {
return Err(BalloonConfigError::TooManyPagesRequested);
}

if self.vm_config.huge_pages != HugePageConfig::None {
return Err(BalloonConfigError::HugePages);

Check warning on line 333 in src/vmm/src/resources.rs

View check run for this annotation

Codecov / codecov/patch

src/vmm/src/resources.rs#L333

Added line #L333 was not covered by tests
}

self.balloon.set(config)
}

Expand Down Expand Up @@ -1389,6 +1397,9 @@ mod tests {

if KernelVersion::get().unwrap() >= KernelVersion::new(5, 10, 0) {
aux_vm_config.mem_size_mib = Some(2048);
// Remove the balloon device config that's added by `default_vm_resources` as it would
// trigger the "ballooning incompatible with huge pages" check.
vm_resources.balloon = BalloonBuilder::new();
vm_resources.update_vm_config(&aux_vm_config).unwrap();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/vmm/src/vmm_config/balloon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub enum BalloonConfigError {
CreateFailure(crate::devices::virtio::balloon::BalloonError),
/// Error updating the balloon device configuration: {0:?}
UpdateFailure(std::io::Error),
/// Firecracker's huge pages support is incompatible with memory ballooning.
HugePages,
}

/// This struct represents the strongly typed equivalent of the json body
Expand Down
2 changes: 2 additions & 0 deletions src/vmm/src/vmm_config/machine_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub enum VmConfigError {
KernelVersion,
/// Firecracker's hugetlbfs support requires at least host kernel 5.10.
HugetlbfsNotSupported,
/// Firecracker's huge pages support is incompatible with memory ballooning.
BalloonAndHugePages,
}

// We cannot do a `KernelVersion(kernel_version::Error)` variant because `kernel_version::Error`
Expand Down
27 changes: 27 additions & 0 deletions tests/integration_tests/performance/test_huge_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,30 @@ def test_hugetlbfs_snapshot(
assert not rc

check_hugetlbfs_in_use(vm.firecracker_pid, "/anon_hugepage")


@pytest.mark.skipif(
global_props.host_linux_version == "4.14",
reason="MFD_HUGETLB | MFD_ALLOW_SEALING only supported on kernels >= 4.16",
)
def test_negative_huge_pages_plus_balloon(uvm_plain):
"""Tests that huge pages and memory ballooning cannot be used together"""
uvm_plain.memory_monitor = None
uvm_plain.spawn()

# Ensure setting huge pages and then adding a balloon device doesn't work
uvm_plain.basic_config(huge_pages=HugePagesConfig.HUGETLBFS_2MB)
with pytest.raises(
RuntimeError,
match="Firecracker's huge pages support is incompatible with memory ballooning.",
):
uvm_plain.api.balloon.put(amount_mib=0, deflate_on_oom=False)

# Ensure adding a balloon device and then setting huge pages doesn't work
uvm_plain.basic_config(huge_pages=HugePagesConfig.NONE)
uvm_plain.api.balloon.put(amount_mib=0, deflate_on_oom=False)
with pytest.raises(
RuntimeError,
match="Machine config error: Firecracker's huge pages support is incompatible with memory ballooning.",
):
uvm_plain.basic_config(huge_pages=HugePagesConfig.HUGETLBFS_2MB)

0 comments on commit c34853c

Please sign in to comment.