-
Notifications
You must be signed in to change notification settings - Fork 113
Add is_hugetlbfs() to GuestMemoryRegion #120
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -289,6 +289,26 @@ pub trait GuestMemoryRegion: Bytes<MemoryRegionAddress, E = Error> { | |
| fn as_volatile_slice(&self) -> Result<volatile_memory::VolatileSlice> { | ||
| self.get_slice(MemoryRegionAddress(0), self.len() as usize) | ||
| } | ||
|
|
||
| /// Show if the region is based on the `HugeTLBFS`. | ||
| /// Returns Some(true) if the region is backed by hugetlbfs. | ||
| /// None represents that no information is available. | ||
| /// | ||
| /// # Examples (uses the `backend-mmap` feature) | ||
| /// | ||
| /// ``` | ||
| /// # #[cfg(feature = "backend-mmap")] | ||
| /// # { | ||
| /// # use vm_memory::{GuestAddress, GuestMemory, GuestMemoryMmap, GuestRegionMmap}; | ||
| /// let addr = GuestAddress(0x1000); | ||
| /// let mem = GuestMemoryMmap::from_ranges(&[(addr, 0x1000)]).unwrap(); | ||
| /// let r = mem.find_region(addr).unwrap(); | ||
| /// assert_eq!(r.is_hugetlbfs(), None); | ||
| /// # } | ||
| /// ``` | ||
| fn is_hugetlbfs(&self) -> Option<bool> { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the late comment, but can we actually just use conditional compilation here and make it available only on Linux, instead of having a blank implementation for Windows? |
||
| None | ||
| } | ||
| } | ||
|
|
||
| /// `GuestAddressSpace` provides a way to retrieve a `GuestMemory` object. | ||
|
|
@@ -1199,4 +1219,13 @@ mod tests { | |
|
|
||
| crate::bytes::tests::check_atomic_accesses(mem, addr, bad_addr); | ||
| } | ||
|
|
||
| #[cfg(feature = "backend-mmap")] | ||
| #[test] | ||
| fn test_guest_memory_mmap_is_hugetlbfs() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicates the test in comment. (as pointed out before) |
||
| let addr = GuestAddress(0x1000); | ||
| let mem = GuestMemoryMmap::from_ranges(&[(addr, 0x1000)]).unwrap(); | ||
| let r = mem.find_region(addr).unwrap(); | ||
| assert_eq!(r.is_hugetlbfs(), None); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We just merged a PR that updated all the code examples that needed features. Can you please update this example to follow that template?
Changes that would be needed:
vm-memory/src/guest_memory.rs
Line 266 in 576a406
[cfg(feature = "backend-mmap")]only one at the begginging of the example, and get rid of thetest_guest_memory_mmap_is_hugetlbfsfunction. The code can sit directly in the example.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
test_guest_memory_mmap_is_hugetlbsfunction is still there. To get rid of it, and also declare the#[cfg(feature = "backend-mmap")], we would need to start a code block (and have it all conditionally compiled only for that feature).With this approach, you no longer need the function
test_guest_memory_mmap_is_hugetlbfs, and all the cfg macros.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cargo fmtfails because of alignment. The code needs to be aligned as in my previous comment. We can fix it in a subsequent PR.