Skip to content

nvme_driver: allocate different DMA memory sizes if not bounce buffering #1306

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 3 commits into from
May 15, 2025

Conversation

chris-oo
Copy link
Member

@chris-oo chris-oo commented May 6, 2025

A previous change increased the DMA memory allocated per queue to 128 pages, to handle the need for additional pages to bounce buffer on CVMs. Make this configurable, so that the pages allocated go back to the previous of 64, when not isolated.

@chris-oo chris-oo requested review from a team as code owners May 6, 2025 20:53
@chris-oo chris-oo changed the title nvme_driver: Allocate different DMA memory sizes if not bounce buffering nvme_driver: allocate different DMA memory sizes if not bounce buffering May 6, 2025
);
let alloc: PageAllocator =
PageAllocator::new(mem.subblock(data_offset, QueuePair::PER_QUEUE_PAGES * PAGE_SIZE));
let alloc = if bounce_buffer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like this expression can be shortened? E.g. use one PageAllocator::new after checking all asserts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assert is probably not needed at all?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm the assert is checking the minimum size is large enough for the given commands right? I don't know enough to say if the assert should be removed or not, but it still seems useful?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, what I meant is - we are asserting if one constant is greater than another constant. Can be done statically outside of this function, I think. But okay, leave it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a static assert, since it's a const evaluation at compile time. A bit confusing, but it doesn't require taking a dependency on static_assert which i think does the same thing under the hood.

@@ -266,7 +266,7 @@ async fn test_nvme_save_restore_inner(driver: DefaultDriver) {
.unwrap();

let device = NvmeTestEmulatedDevice::new(nvme_ctrl, msi_x, dma_client.clone());
let mut nvme_driver = NvmeDriver::new(&driver_source, CPU_COUNT, device)
let mut nvme_driver = NvmeDriver::new(&driver_source, CPU_COUNT, device, false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: add a test case with true

yupavlen-ms
yupavlen-ms previously approved these changes May 6, 2025
benhillis
benhillis previously approved these changes May 15, 2025
// buffering / double buffering is needed.
let alloc_len = if bounce_buffer {
const SIZE: usize = QueuePair::PER_QUEUE_PAGES_BOUNCE_BUFFER * PAGE_SIZE;
const _: () = assert!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we package this up as a local const fn? E.g.,

const fn pages_to_size(pages: usize) -> usize {
    let size = pages * PAGE_SIZE;
    assert!(size >= ...);
    size
}
// Note: using const {} to ensure the internal assertion checks are at compile time
let alloc_len = if bounce_buffer {
    const { pages_to_size(QueuePair::PER_QUEUE_PAGES_BOUNCE_BUFFER) }
} else {
    const { pages_to_size(QueuePair::PER_QUEUE_PAGES_NO_BOUNCE_BUFFER) }
};

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat, can do

@chris-oo chris-oo enabled auto-merge (squash) May 15, 2025 18:58
@chris-oo chris-oo merged commit ba5966a into microsoft:main May 15, 2025
28 checks passed
@chris-oo chris-oo deleted the nvme-queue-conf branch May 15, 2025 19:22
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.

4 participants