Ask or search…
Comment on page

How to activate memory hotplug

Memory hotplug allows you to dynamically add or remove memory from a running virtual machine (VM) or server without requiring a system reboot. This can be a valuable feature for your VPS to efficiently manage resources. In this guide, we will show you how to activate memory hotplug using a custom udev rule in the /etc/udev/rules.d/99-hotplug-cpu-mem.rules file.


  • a VPS
  • an OnetSolutions account

Step 1: Create or Edit the udev Rule File

  1. 1.
    SSH into your VPS server using your preferred terminal emulator.
  2. 2.
    Navigate to the /etc/udev/rules.d/ directory, where udev rules are stored:
    cd /etc/udev/rules.d/
  3. 3.
    Create or edit the 99-hotplug-cpu-mem.rules file using a text editor of your choice. You can use nano, vim, or gedit:
    sudo nano 99-hotplug-cpu-mem.rules

Step 2: Add the Memory Hotplug Rule

In the 99-hotplug-cpu-mem.rules file, add the following rule to enable memory hotplug:
SUBSYSTEM=="memory", ACTION=="add", TEST=="state", ATTR{state}=="offline", ATTR{state}="online"
SUBSYSTEM=="cpu", ACTION=="add", TEST=="online", ATTR{online}=="0", ATTR{online}="1"
This rule checks for CPU online events (ACTION=="add" and TEST=="online") and sets the online attribute to 1 for CPUs where online is currently 0.

Step 3: Save and Exit

Save the changes and exit your text editor:
  • For nano, press Ctrl + O, then press Enter to save, and finally press Ctrl + X to exit.
  • For vim, type :wq and press Enter to save and exit.
  • For gedit, click the "Save" option in the GUI and close the editor.

Step 4: Reload udev Rules

To apply the new udev rule without rebooting, you need to reload the udev rules:
sudo udevadm control --reload
Please run also this script:
# Based on script by William Lam
# Bring CPUs online
for CPU_DIR in /sys/devices/system/cpu/cpu[0-9]*
echo "Found cpu: '${CPU_DIR}' ..."
if [ -f "${CPU_STATE_FILE}" ]; then
if grep -qx 1 "${CPU_STATE_FILE}"; then
echo -e "\t${CPU} already online"
echo -e "\t${CPU} is new cpu, onlining cpu ..."
echo 1 > "${CPU_STATE_FILE}"
echo -e "\t${CPU} already configured prior to hot-add"
# Bring all new Memory online
for RAM in $(grep line /sys/devices/system/memory/*/state)
echo "Found ram: ${RAM} ..."
if [[ "${RAM}" == *":offline" ]]; then
echo "Bringing online"
echo $RAM | sed "s/:offline$//"|sed "s/^/echo online > /"|source /dev/stdin
echo "Already online"

Step 5: Test Memory Hotplug

You can now test memory hotplug by adding or removing memory from your VPS.


By following these steps and creating the udev rule, you have activated memory hotplug for your VPS. This will allow you to dynamically adjust memory resources on your virtual server, providing greater flexibility and resource management capabilities.