Difference between revisions of "Virsh setmem"

From wikieduonline
Jump to navigation Jump to search
(Created page with "<code>virsh setmem YOUR_VM_NAME size [[--config] [--live] | [--current]]</code><ref>https://linux.die.net/man/1/virsh</ref><ref>https://rentry.co/s3p8o</ref> Change the memor...")
 
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
<code>virsh setmem YOUR_VM_NAME size [[--config] [--live] | [--current]]</code><ref>https://linux.die.net/man/1/virsh</ref><ref>https://rentry.co/s3p8o</ref>
+
<code>[[virsh]] setmem YOUR_VM_NAME size [[--config] [--live] | [--current]]</code><ref>https://linux.die.net/man/1/virsh</ref><ref>https://rentry.co/s3p8o</ref>
  
 
Change the memory allocation for a guest domain/Virtual Machine. Operation is not synchronously, as with <code>[[virsh setvcpus]]</code> then the fact that the <code>virsh setmem</code> program returned, may not mean the action is complete and you must poll periodically to detect that the guest completed the operation: <code>virsh dominfo YOUR_VM_NAME  | grep memory</code>
 
Change the memory allocation for a guest domain/Virtual Machine. Operation is not synchronously, as with <code>[[virsh setvcpus]]</code> then the fact that the <code>virsh setmem</code> program returned, may not mean the action is complete and you must poll periodically to detect that the guest completed the operation: <code>virsh dominfo YOUR_VM_NAME  | grep memory</code>
Line 12: Line 12:
 
For <code>Xen</code>, you can only adjust the memory of a running domain if the domain is paravirtualized or running the PV balloon driver.
 
For <code>Xen</code>, you can only adjust the memory of a running domain if the domain is paravirtualized or running the PV balloon driver.
  
For <code>LXC</code>, the value being set is the [[cgroups]] value for limit_in_bytes or the maximum amount of user memory (including file cache). When viewing memory inside the container, this is the <code>/proc/meminfo</code> "MemTotal" value. When viewing the value from the host, use the <code>[[virsh memtune]]</code> command. In order to view the current memory in use and the maximum value allowed to set memory, use the <code>[[virsh/virsh dominfo|virsh dominfo]]</code> command.
+
For <code>LXC</code>, the value being set is the [[cgroups]] value for limit_in_bytes or the maximum amount of user memory (including file cache). When viewing memory inside the container, this is the <code>/proc/meminfo</code> "MemTotal" value. When viewing the value from the host, use the <code>[[virsh memtune]]</code> command. In order to view the current memory in use and the maximum value allowed to set memory, use the <code>[[virsh dominfo]]</code> command.
  
<code>
+
<pre>
  [[virsh/virsh dominfo|virsh dominfo]] YOUR_VM_NAME  | grep memory
+
  virsh dominfo YOUR_VM_NAME  | grep memory
 
  Max memory:    1048576 KiB
 
  Max memory:    1048576 KiB
 
  Used memory:    1048576 KiB
 
  Used memory:    1048576 KiB
</code>
+
</pre>
 +
 
 
<pre>
 
<pre>
 
# virsh setmem YOUR_VM_NAME 500M           
 
# virsh setmem YOUR_VM_NAME 500M           
 
</pre>
 
</pre>
 +
 +
<pre>
 +
# virsh setmem YOUR_VM_NAME 8G --config --live           
 +
</pre>
 +
 +
 
Example setting showing up error setting up memory higher that max memory:
 
Example setting showing up error setting up memory higher that max memory:
 
<pre>
 
<pre>
Line 27: Line 34:
 
error: invalid argument: cannot set memory higher than max memory           
 
error: invalid argument: cannot set memory higher than max memory           
 
</pre>
 
</pre>
 +
 
<pre>
 
<pre>
 
# virsh dominfo YOUR_VM_NAME  | grep memory
 
# virsh dominfo YOUR_VM_NAME  | grep memory
Line 32: Line 40:
 
Used memory:    512000 KiB
 
Used memory:    512000 KiB
 
</pre>
 
</pre>
 +
 
<pre>
 
<pre>
 
# ssh fedora-27 free -m
 
# ssh fedora-27 free -m
Line 40: Line 49:
  
  
 +
== Related commands ==
 +
* <code>[[virsh setmaxmem]]</code>
 +
* <code>[[virsh edit]]</code>
 +
* <code>[[virsh setvcpus]]</code>
  
 
== See also ==
 
== See also ==
* [[RAM]]
+
* {{virsh memory commands}}
* [[Virsh/Virsh Memory Commands|Virsh Memory Commands]]:  <code>[[Virsh/virsh dommemstat|virsh dommemstat]], [[Virsh/virsh setmem|virsh setmem]], [[Virsh/virsh setmaxmem|virsh setmaxmem]]</code>
+
* {{virsh}}
 +
* {{memory}}
 +
* {{KVM}}
  
  
 
[[Category:Linux]]
 
[[Category:Linux]]
 
[[Category:KVM]]
 
[[Category:KVM]]

Latest revision as of 06:31, 28 January 2020

virsh setmem YOUR_VM_NAME size [[--config] [--live] | [--current]][1][2]

Change the memory allocation for a guest domain/Virtual Machine. Operation is not synchronously, as with virsh setvcpus then the fact that the virsh setmem program returned, may not mean the action is complete and you must poll periodically to detect that the guest completed the operation: virsh dominfo YOUR_VM_NAME | grep memory

If --config is specified, affect the next boot of a persistent guest.
If --live is specified, perform a memory balloon of a running guest.
If --current is specified, affect the current guest state.
Both --live and --config flags may be given, but --current is exclusive. If no flag is specified, behavior is different depending on hypervisor.

size is a scaled integer; it defaults to kibibytes (blocks of 1024 bytes) unless you provide a suffix (and the older option name --kilobytes is available as a deprecated synonym) . Libvirt rounds up to the nearest kibibyte. Some hypervisors require a larger granularity than KiB, and requests that are not an even multiple will be rounded up. For example, vSphere/ESX rounds the parameter up to mebibytes (1024 kibibytes).

For Xen, you can only adjust the memory of a running domain if the domain is paravirtualized or running the PV balloon driver.

For LXC, the value being set is the cgroups value for limit_in_bytes or the maximum amount of user memory (including file cache). When viewing memory inside the container, this is the /proc/meminfo "MemTotal" value. When viewing the value from the host, use the virsh memtune command. In order to view the current memory in use and the maximum value allowed to set memory, use the virsh dominfo command.

 virsh dominfo YOUR_VM_NAME  | grep memory
 Max memory:     1048576 KiB
 Used memory:    1048576 KiB
# virsh setmem YOUR_VM_NAME 500M           
# virsh setmem YOUR_VM_NAME 8G --config --live            


Example setting showing up error setting up memory higher that max memory:

# virsh setmem YOUR_VM_NAME 8G 
error: invalid argument: cannot set memory higher than max memory          
# virsh dominfo YOUR_VM_NAME  | grep memory
Max memory:     1048576 KiB
Used memory:    512000 KiB
# ssh fedora-27 free -m
                total        used        free      shared  buff/cache   available
Mem:            467          50         327           0          88         285
Swap:          1535          51        1484


Related commands[edit]

See also[edit]

  • https://linux.die.net/man/1/virsh
  • https://rentry.co/s3p8o
  • Advertising: