Skip to content

fix: rename page_size_kib to page_size #4948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ and this project adheres to

### Deprecated

- [#4948](https://github.com/firecracker-microvm/firecracker/pull/4948):
Deprecated the `page_size_kib` field in the
[UFFD handshake](docs/snapshotting/handling-page-faults-on-snapshot-resume.md#registering-memory-to-be-handled-via-userfault-file-descriptors),
and replaced it with a `page_size` field. The `page_size_kib` field is
misnamed, as the value Firecracker sets it to is actually the page size in
_bytes_, not KiB. It will be removed in Firecracker 2.0.

### Removed

### Fixed
Expand Down
13 changes: 5 additions & 8 deletions src/firecracker/examples/uffd/uffd_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct GuestRegionUffdMapping {
/// Offset in the backend file/buffer where the region contents are.
pub offset: u64,
/// The configured page size for this memory region.
pub page_size_kib: usize,
pub page_size: usize,
}

impl GuestRegionUffdMapping {
Expand Down Expand Up @@ -79,7 +79,7 @@ impl UffdHandler {
mappings.len()
)
});
let page_size = first_mapping.page_size_kib;
let page_size = first_mapping.page_size;

// Make sure memory size matches backing data size.
assert_eq!(memsize, size);
Expand Down Expand Up @@ -152,10 +152,7 @@ impl UffdHandler {
return false;
}
Err(Error::CopyFailed(errno))
if std::io::Error::from(errno).raw_os_error().unwrap() == libc::EEXIST =>
{
()
}
if std::io::Error::from(errno).raw_os_error().unwrap() == libc::EEXIST => {}
Err(e) => {
panic!("Uffd copy failed: {e:?}");
}
Expand Down Expand Up @@ -364,7 +361,7 @@ mod tests {
base_host_virt_addr: 0,
size: 0x1000,
offset: 0,
page_size_kib: 4096,
page_size: 4096,
}];
let dummy_memory_region_json = serde_json::to_string(&dummy_memory_region).unwrap();

Expand Down Expand Up @@ -397,7 +394,7 @@ mod tests {
base_host_virt_addr: 0,
size: 0,
offset: 0,
page_size_kib: 4096,
page_size: 4096,
}];
let error_memory_region_json = serde_json::to_string(&error_memory_region).unwrap();
stream
Expand Down
21 changes: 14 additions & 7 deletions src/vmm/src/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ pub struct GuestRegionUffdMapping {
/// Offset in the backend file/buffer where the region contents are.
pub offset: u64,
/// The configured page size for this memory region.
pub page_size: usize,
/// The configured page size **in bytes** for this memory region. The name is
/// wrong but cannot be changed due to being API, so this field is deprecated,
/// to be removed in 2.0.
#[deprecated]
pub page_size_kib: usize,
}

Expand Down Expand Up @@ -593,11 +598,13 @@ fn create_guest_memory(
let mut backend_mappings = Vec::with_capacity(guest_memory.num_regions());
let mut offset = 0;
for mem_region in guest_memory.iter() {
#[allow(deprecated)]
backend_mappings.push(GuestRegionUffdMapping {
base_host_virt_addr: mem_region.as_ptr() as u64,
size: mem_region.size(),
offset,
page_size_kib: huge_pages.page_size_kib(),
page_size: huge_pages.page_size(),
page_size_kib: huge_pages.page_size(),
});
offset += mem_region.size() as u64;
}
Expand Down Expand Up @@ -788,26 +795,26 @@ mod tests {
assert_eq!(uffd_regions.len(), 1);
assert_eq!(uffd_regions[0].size, 0x20000);
assert_eq!(uffd_regions[0].offset, 0);
assert_eq!(
uffd_regions[0].page_size_kib,
HugePageConfig::None.page_size_kib()
);
assert_eq!(uffd_regions[0].page_size, HugePageConfig::None.page_size());
}

#[test]
fn test_send_uffd_handshake() {
#[allow(deprecated)]
let uffd_regions = vec![
GuestRegionUffdMapping {
base_host_virt_addr: 0,
size: 0x100000,
offset: 0,
page_size_kib: HugePageConfig::None.page_size_kib(),
page_size: HugePageConfig::None.page_size(),
page_size_kib: HugePageConfig::None.page_size(),
},
GuestRegionUffdMapping {
base_host_virt_addr: 0x100000,
size: 0x200000,
offset: 0,
page_size_kib: HugePageConfig::Hugetlbfs2M.page_size_kib(),
page_size: HugePageConfig::Hugetlbfs2M.page_size(),
page_size_kib: HugePageConfig::Hugetlbfs2M.page_size(),
},
];

Expand Down
4 changes: 2 additions & 2 deletions src/vmm/src/vmm_config/machine_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ impl HugePageConfig {
matches!(self, HugePageConfig::Hugetlbfs2M)
}

/// Gets the page size in KiB of this [`HugePageConfig`].
pub fn page_size_kib(&self) -> usize {
/// Gets the page size in bytes of this [`HugePageConfig`].
pub fn page_size(&self) -> usize {
match self {
HugePageConfig::None => 4096,
HugePageConfig::Hugetlbfs2M => 2 * 1024 * 1024,
Expand Down