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

qemu backend tries to allocate millions of megabytes of memory #677

Closed
Saviq opened this issue Mar 12, 2019 · 2 comments
Closed

qemu backend tries to allocate millions of megabytes of memory #677

Saviq opened this issue Mar 12, 2019 · 2 comments
Assignees
Labels

Comments

@Saviq
Copy link
Collaborator

Saviq commented Mar 12, 2019

Between #654 and #650 the qemu backend started allocating petabytes of memory... Failing, obviously.

@Saviq Saviq added the bug label Mar 12, 2019
@ricab
Copy link
Collaborator

ricab commented Mar 13, 2019

From man qemu-system-x86_64

   -m [size=]megs[,slots=n,maxmem=size]
       Sets guest startup RAM size to megs megabytes. Default is 128 MiB.  Optionally, a
       suffix of "M" or "G" can be used to signify a value in megabytes or gigabytes
       respectively.

So qemu's memory resolution is megabytes. We will floor when an exact match is not possible.

@ricab
Copy link
Collaborator

ricab commented Mar 13, 2019

Also interesting: https://libvirt.org/formatdomain.html#elementsMemoryAllocation

In particular

[...] the value will be rounded up to the nearest kibibyte by libvirt, and may be further rounded to the granularity supported by the hypervisor. Some hypervisors also enforce a minimum, such as 4000KiB. [...]"

ricab added a commit that referenced this issue Mar 14, 2019
This completes the switch to MemorySize (compiling and passing tests). Fixes #677.
bors bot added a commit that referenced this issue Mar 18, 2019
681: Cleanse backend memory args r=Saviq a=ricab

Fixes #677

On investigation, back-end tools use slightly different formats to represent digital info sizes (bytes). So, our previous assumption that a *bytes string* would be correctly interpreted everywhere is not actually true. IOW, neither plain strings nor plain numbers are adequate to convey memory sizes uniformly, so the earlier *shortcut implementation* falls short. 

This PR encapsulates memory sizes in a dedicated type: `MemorySize`. This type does the necessary arithmetic, but it is the responsibility of each (internal) back-end implementation to derive the string representation they need (unit and unit representation).

Co-authored-by: Ricardo Abreu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants