Skip to main content
  1. Posts/

Linux RAM hotplug

·175 words·1 min· loading · loading ·
Sysadmin Hardware

One of the key advantages of virtualization is the ability to modify hardware parameters on the fly. While containers usually require no additional steps inside the guest system after a resource change, full virtual machines do need some internal handling once resources have been allocated on the hypervisor.

The most common case is memory. After increasing the RAM allocation on the hypervisor, you can check the memory status inside the guest system with the following command:

1root@localhost # grep line /sys/devices/system/memory/*/state
2/sys/devices/system/memory/memory0/state:online
3/sys/devices/system/memory/memory10/state:offline
4/sys/devices/system/memory/memory11/state:offline
5...

Now all that’s left is to activate the memory that is currently in the offline state. You can do this with the following command:

1echo online >/sys/devices/system/memory/memoryXX/state

where XX is the memory “module” number.

If you want to activate all the newly added memory (which is the most common scenario — it’s unclear when you’d only want to activate part of it), you can use this one-liner:

1for f in `grep -Fl offline /sys/devices/system/memory/*/state`; do echo online > $f; done;

Now you can check in top, htop or free -m.

@soar
Author
@soar
Senior SRE/DevOps engineer

Related

Bad delivery
·3 words·1 min· loading · loading
Sysadmin Hardware
Introduction into storcli
·198 words·1 min· loading · loading
Sysadmin Hardware Linux
Just a CPU and a network card
·13 words·1 min· loading · loading
Sysadmin Hardware