Skip to content
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

passthrough: reduce the memory footprint of file handle #102

Merged
merged 2 commits into from
Jan 5, 2023

Conversation

liubogithub
Copy link
Contributor

@liubogithub liubogithub commented Dec 19, 2022

File handles used by name_to_handle_at(2) are allocated with fixed max bytes, which results in unnecessary memory pressure.

Per the manual of open_by_handle_at(2),

"The caller can discover the required size for the file_handle structure by making a call in which handle->handle_bytes is zero; in this case, the call fails with the error EOVERFLOW and handle->handle_bytes is set to indicate the required size; the caller can then use this information to allocate a structure of the correct size (see EXAMPLES below)."

This follows the description and allocates the needed bytes.

With this,
sizeof:: drops from 136 bytes to 16 bytes.
sizeof:: drops from 328 bytes to 120 bytes.

Also there is no need to make CFileHandle public.

Signed-off-by: Liu Bo [email protected]

Test has been done with passthrough::tests::test_passthroughfs_inode_file_handles (with the following changes and tempdir is on ext4 which supports file handle feature),

@@ -1330,8 +1331,8 @@ mod tests {
         let c_entry = fs.lookup(&ctx, p_inode, &child).unwrap();

         // Following test depends on host fs, it's not reliable.
-        //let data = fs.inode_map.get(c_entry.inode).unwrap();
-        //assert_eq!(matches!(data.file_or_handle, FileOrHandle::Handle(_)), true);
+        let data = fs.inode_map.get(c_entry.inode).unwrap();
+        assert_eq!(matches!(data.file_or_handle, FileOrHandle::Handle(_)), true);

         let (_, duration) = fs.getattr(&ctx, c_entry.inode, None).unwrap();
         assert_eq!(duration, fs.cfg.attr_timeout);

@liubogithub liubogithub changed the title [wip] passthrough: reduce the memory footprint of file handle passthrough: reduce the memory footprint of file handle Dec 19, 2022
@liubogithub liubogithub force-pushed the liubo/fh branch 3 times, most recently from 5930737 to 1c8f134 Compare December 21, 2022 20:35
This fixes warnings/errors in the code base according to cargo
1.66.0's clippy.

Signed-off-by: Liu Bo <[email protected]>
File handles used by name_to_handle_at(2) are allocated with fixed max
bytes, which results in unnecessary memory pressure.

Per the manual of open_by_handle_at(2),

"The caller can discover the required size for the file_handle
structure by making a call in which handle->handle_bytes is zero; in
this case, the call fails with the error EOVERFLOW and
handle->handle_bytes is set to indicate the required size; the caller
can then use this information to allocate a structure of the correct
size (see EXAMPLES below)."

This follows the description and allocates the needed bytes.
With this,
sizeof::<CFileHandle> drops from 136 bytes to 16 bytes.
sizeof::<InodeData> drops from 328 bytes to 120 bytes.


Also there is no need to make CFileHandle public.

Signed-off-by: Liu Bo <[email protected]>
@jiangliu jiangliu merged commit 0c7c137 into cloud-hypervisor:master Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants