Thanks to visit codestin.com
Credit goes to github.com

Skip to content

vmm: Set reserve=on by default when hugepages=on - #8770

Merged
rbradford merged 2 commits into
cloud-hypervisor:mainfrom
poliglots:main
Aug 26, 2026
Merged

vmm: Set reserve=on by default when hugepages=on#8770
rbradford merged 2 commits into
cloud-hypervisor:mainfrom
poliglots:main

Conversation

@poliglots

Copy link
Copy Markdown
Contributor

When hugepages=on but reserve isn't explicitly set, default reserve to on. This ensures the kernel reserves physical RAM for huge pages at boot time, exposing memory shortages early as a configuration error rather than later via a random SIGBUS mid-flight.

prefault=on takes precedence and is not affected, since prefaulting already implies reservation. Users can still explicitly set reserve=off.

Fixes #8742

@poliglots
poliglots requested a review from a team as a code owner August 22, 2026 09:01

@rbradford rbradford left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks but this is wrong. We talk about the CLI as a shorthand but we also need to cover the API boot. Also we need to be clever and use Option type for compatibility.

@poliglots

Copy link
Copy Markdown
Contributor Author

Thanks @rbradford for the feedback, let me try to cover them. will update you.

@poliglots

Copy link
Copy Markdown
Contributor Author

Hi @rbradford ,
I have tried to cover the API part. Please check if I am in right direction.
Thanks.

@poliglots
poliglots requested a review from rbradford August 24, 2026 06:08

@rbradford rbradford left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for taking my feedback onboard.

Comment thread vmm/src/vm_config.rs Outdated
Comment on lines +273 to +278
impl MemoryZoneConfig {
pub fn reserve(&self) -> bool {
self.reserve.unwrap_or(self.hugepages && !self.prefault)
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not quite right. Apply the policy only in MemoryManager

Comment thread vmm/src/vm_config.rs Outdated
Comment on lines +352 to +357
impl MemoryConfig {
pub fn reserve(&self) -> bool {
self.reserve.unwrap_or(self.hugepages && !self.prefault)
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto.

hugepage_size: None,
prefault: false,
reserve: false,
reserve: None,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should be rolled into the commit that broke the build. Every commit needs to be buildable.

@poliglots

Copy link
Copy Markdown
Contributor Author

Thanks. Will work on it and update you.

@poliglots

Copy link
Copy Markdown
Contributor Author

Hi, I have made the changes as suggested by you. Please take a look. Thanks.

@poliglots
poliglots requested a review from rbradford August 24, 2026 13:22

@rbradford rbradford left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please audit your commits. You shouldn't add and then remove.

@poliglots

Copy link
Copy Markdown
Contributor Author

Sorry for the mess. Will correct and update by tomorrow. Thanks for feedback.

@poliglots

Copy link
Copy Markdown
Contributor Author

Hi Rob,

Thanks for all the feedback. I've squashed all 4 commits into one and moved the reserve default policy so it's applied only in MemoryManager, with the config structs keeping Option for API compatibility.

Apologies for the messy history — appreciate your patience.

Could you please take another look?

@poliglots
poliglots requested a review from rbradford August 25, 2026 08:40

@rbradford rbradford left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You should still keep the separate commit for making reserve an Option<bool>

Comment thread vmm/src/config.rs Outdated
hugepage_size: Some(2 << 20),
size: 1 << 30,
hugepages: true,
// reserve is None; the effective default is computed in MemoryManager

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can drop this comment

Comment thread vmm/src/memory_manager.rs Outdated
region_size as usize,
prefault.unwrap_or(zone.prefault),
zone.reserve,
zone.reserve.unwrap_or(zone.hugepages && !zone.prefault),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you actually need the !zone.prefault ? How does this affect the flags in create_ram_region_raw() does it even matter?

@rbradford

Copy link
Copy Markdown
Member

I would look into git rebase -i if you don't know it. It will help you create an appropriately structured set of commits,

@poliglots

Copy link
Copy Markdown
Contributor Author

Thanks, will update by tomorrow.

@poliglots

Copy link
Copy Markdown
Contributor Author

You should still keep the separate commit for making reserve an Option<bool>

Hi @rbradford ,

Need your little guidance here. I am planning to have two commits

  1. First commit will the copy of "8c8fdc0"
  2. Second commit will the diff of current commit "7328cc6" and "8c8fdc0".

I have Question:

  1. If I make separate commit 8c8fdc0 i.e. Use Option for reserve and add .reserve() method , then the "impl MemoryConfig" which I defined in config.rs will be get removed in 2nd commit. Then will it look like I removed again after adding. or its ok since we do it because of review comments.
  2. In the Second commit , I will incorporate the latest feedback i.e. removal of !zone.prefault from "memory_manager.rs" and removal of comment from "config.rs" along with policy application in memory manager.

Do you think this would be correct approach.

Thanks.

@rbradford

Copy link
Copy Markdown
Member

I

You should still keep the separate commit for making reserve an Option<bool>

Hi @rbradford ,

Need your little guidance here. I am planning to have two commits

  1. First commit will the copy of "8c8fdc0"
  2. Second commit will the diff of current commit "7328cc6" and "8c8fdc0".

I have Question:

  1. If I make separate commit 8c8fdc0 i.e. Use Option for reserve and add .reserve() method , then the "impl MemoryConfig" which I defined in config.rs will be get removed in 2nd commit. Then will it look like I removed again after adding. or its ok since we do it because of review comments.
  2. In the Second commit , I will incorporate the latest feedback i.e. removal of !zone.prefault from "memory_manager.rs" and removal of comment from "config.rs" along with policy application in memory manager.

I don't know why you think you need to reference these old commits. Instead just split the commit you already had? Why would feel you need to add the helper when you can just to .unwrap_or(false).

I took 5 minutes and updated the PR with the appropriate structure. Hope you don't mind. I think were were going around in circles over something which should be very simple.

Make specifying this optional rather than a default of false so as to
allow differentiating from intentionally included and false vs
ambivalent. This prepares for enabling reserve when hugepages is enabled
when the user does not intentionally disable reserve.

See: cloud-hypervisor#8742

Signed-off-by: Shatrughan Rai <[email protected]>
Signed-off-by: Rob Bradford <[email protected]>
@rbradford

Copy link
Copy Markdown
Member

I had to rebase and address some issues due to #8581 landing.

Don't map with MADV_NORESERVE when hugepages are enabled unless the user
has explicitly disabled reserving.

Fixes: cloud-hypervisor#8742

Signed-off-by: Shatrughan Rai <[email protected]>
Signed-off-by: Rob Bradford <[email protected]>
@poliglots

Copy link
Copy Markdown
Contributor Author

Hi Rob,

I completely agree that we were going in circles. Thanks for putting the commit "a35e6ba" and "39683f1"

Your feedback will help me to improve for future PRs.

Thanks.

@rbradford

Copy link
Copy Markdown
Member

Hi Rob,

I completely agree that we were going in circles. Thanks for putting the commit "a35e6ba" and "39683f1"

Your feedback will help me to improve for future PRs.

Thanks.

Good to hear. Hope you can understand why this split makes sense. In this case: 1. prep (and yes that meant adding .unwrap_of(false) that would be immediately replaced) 2. apply policy standalone so it's easy to understand

@rbradford
rbradford enabled auto-merge August 25, 2026 13:46
@poliglots

Copy link
Copy Markdown
Contributor Author

Good to hear. Hope you can understand why this split makes sense. In this case: 1. prep (and yes that meant adding .unwrap_of(false) that would be immediately replaced) 2. apply policy standalone so it's easy to understand

Thanks for the explanation, The two-step split makes complete sense. Thanks.

@rbradford
rbradford added this pull request to the merge queue Aug 26, 2026
Merged via the queue into cloud-hypervisor:main with commit 1a576b4 Aug 26, 2026
42 checks passed
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.

vmm: Turn reserve=on if hugepages=on

2 participants