OnetSolutions
  • Home
  • ๐ŸŒWeb Hosting
    • cPanel
    • Subdomains
    • Backup
    • Webmail
      • Roundcube
    • Additional domain
    • HTTPS redirection
    • PHP email
    • PHP version
    • Softaculous
  • ๐Ÿ–ฅ๏ธVPS
    • Getting started with your VPS
    • Snapshot
    • Backup
    • Restart
    • KVM Console
    • Redirect my Domain
    • Operating System
    • Offers
    • Network
      • No Port Blocking Policy
    • Agent
    • Firewall
  • ๐Ÿ’กTutorials
    • ๐Ÿ–ฅ๏ธHow to install K3S
    • ๐ŸคHow to install Yunohost
    • ๐ŸณHow to install Docker
    • โšชHow to install Gitlab
    • ๐Ÿ“ฆHow to update the kernel
    • ๐Ÿ”‘How to change the password
    • ๐ŸงชHow to do a Speedtest
    • ๐Ÿ“…How to change the date and time
    • ๐Ÿ”—How to connect to Linux server
    • ๐Ÿ’พHow to extend a partition
    • ๐Ÿ“How to activate memory hotplug
    • โฌ†๏ธHow to upgrade Debian 11 to Debian 12
    • โฌ†๏ธHow to upgrade Ubuntu to latest version
  • ๐ŸŒDomain
    • Register
    • Incoming transfer
  • ๐Ÿ“‚Subscription
    • ๐Ÿ’ฐBilling
      • ๐Ÿ•œHow to renew?
    • ๐Ÿ•Commitment
Powered by GitBook
On this page
  • Requirements
  • Step 1: Create or Edit the udev Rule File
  • Step 2: Add the Memory Hotplug Rule
  • Step 3: Save and Exit
  • Step 4: Reload udev Rules
  • Step 5: Test Memory Hotplug
  • Conclusion

Was this helpful?

  1. Tutorials

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.

Requirements

  • a VPS

  • an OnetSolutions account

Step 1: Create or Edit the udev Rule File

  1. SSH into your VPS server using your preferred terminal emulator.

  2. Navigate to the /etc/udev/rules.d/ directory, where udev rules are stored:

    cd /etc/udev/rules.d/
  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:

#!/bin/bash
# Based on script by William Lam

# Bring CPUs online
for CPU_DIR in /sys/devices/system/cpu/cpu[0-9]*
do
    CPU=${CPU_DIR##*/}
    echo "Found cpu: '${CPU_DIR}' ..."
    CPU_STATE_FILE="${CPU_DIR}/online"
    if [ -f "${CPU_STATE_FILE}" ]; then
        if grep -qx 1 "${CPU_STATE_FILE}"; then
            echo -e "\t${CPU} already online"
        else
            echo -e "\t${CPU} is new cpu, onlining cpu ..."
            echo 1 > "${CPU_STATE_FILE}"
        fi
    else
        echo -e "\t${CPU} already configured prior to hot-add"
    fi
done

# Bring all new Memory online
for RAM in $(grep line /sys/devices/system/memory/*/state)
do
    echo "Found ram: ${RAM} ..."
    if [[ "${RAM}" == *":offline" ]]; then
        echo "Bringing online"
        echo $RAM | sed "s/:offline$//"|sed "s/^/echo online > /"|source /dev/stdin
    else
        echo "Already online"
    fi
done

Step 5: Test Memory Hotplug

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

Conclusion

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.

PreviousHow to extend a partitionNextHow to upgrade Debian 11 to Debian 12

Last updated 1 year ago

Was this helpful?

๐Ÿ’ก
๐Ÿ“