Adaptive Thinking

Techniques and technical niches

vSphere ESX4: Hot Add Memory for Linux Guests

Posted by JohnMurrayUK on 27th July, 2009


I was asked recently if I could hot-add some RAM to a client’s virtual machine over at virtualDCS. Most of the information I’d found online related to Windows Server versions, but I needed to hot add resources to a Linux VM. VMware.com was lacking in detail about the hot-add compatibility with client operating systems, so I realised I’d better lab it up and see how it works for myself.

The first problem I had, was that the virtual machine I’d cloned from my clients live VM, was originally built using ESX3.5. Hence, it was VM version 4, and hot add hardware is not supported unless the VM hardware is upgraded to version 7. In order to enable hot-add features, I had to first upgrade VMware Tools, and then shut down the VM again to upgrade the virtual hardware to version 7.

Once this had been done, I made sure the VM General Options (VM > Edit Settings > Options > General Options) was set to the correct OS type. This important, as the interface will only display the Memory/CPU Hotplug options for supported OSes. In my case I was running CentOS 5.3 x86_64, so selected Other Linux 2.6.

General Options

Next I enabled the Hot Add CPU and Memory as below, but was unable to check the radio button for Hot Remove CPU, which is interesting in relation to what I found when playing with Hot Add CPUs (discussed in an upcoming post).

HotAdd-Remove

I found that the CentOS build I was using (2.6.18-128.el5) recognises hot added memory automatically. A colleague (thanks Stu) recommended I read the Linux Hotplug Memory docs which made the rest fairly obvious.

My VM was running with 512MB RAM, so I added some more via the vCenter console, so my VM now had 1GB RAM allocated to it. (BTW: even though vCenter appears to let you do this for the 32bit guest version, it doesn’t actually work. The task is reported as successful, but when you check the VM properties again, you’ll see the RAM was not added.)

When memory is hotplugged, the kernel recognizes new memory, makes new memory management tables, and makes sysfs files for new memory’s operation.
If firmware supports notification of connection of new memory to OS, this phase is triggered automatically. ACPI can notify this event. If not, “probe” operation by system administration is used instead.

Now comes the interesting part. Within

/sys/devices/system/memory

there are a number of folders all named ‘memoryX’ where X represents a unique ‘section’ of memory. How big each section is, and hence how many folders you have is dependent on your environment, but you can check the file

/sys/devices/system/memory/block_size_bytes

to view the size of sections in bytes. Basically, the whole memory has been divided up into equal sized chunks as per the SPARSEMEM memory model.

In each section’s folder there is a file called ‘state’, and in each file is one of two words; online or offline.
Locate the memoryX folder(s) which account for the hot added memory by working out the section sizes above, or (like me), just check the contents of the state files:

#cat /sys/devices/system/memory/memoryX/state

Once you locate the offline sections, you can bring them online as follows:

#echo online > /sys/devices/system/memory/memoryX/state

Validate the memory change is seen, using:

#free

That’s it! Quite simple really.

UPDATE: I noticed that William Lam (lamw on the VMware communities) created a nice script to automate the discovery and online process.  It’s very neat and can be downloaded here:

#!/bin/bash
# William Lam
# http://engineering.ucsb.edu/~duonglt/vmware/
# hot-add memory to LINUX system using vSphere ESX(i) 4.0
# 08/09/2009

if [ "$UID" -ne "0" ]
 then
 echo -e "You must be root to run this script.\nYou can 'sudo' to get root access"
 exit 1
fi

for MEMORY in $(ls /sys/devices/system/memory/ | grep memory)
do
 SPARSEMEM_DIR="/sys/devices/system/memory/${MEMORY}"
 echo "Found sparsemem: \"${SPARSEMEM_DIR}\" ..."
 SPARSEMEM_STATE_FILE="${SPARSEMEM_DIR}/state"
 STATE=$(cat "${SPARSEMEM_STATE_FILE}" | grep -i online)
 if [ "${STATE}" == "online" ]; then
 echo -e "\t${MEMORY} already online"
 else
 echo -e "\t${MEMORY} is new memory, onlining memory ..."
 echo online > "${SPARSEMEM_STATE_FILE}"
 fi
done

Add to FacebookAdd to NewsvineAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to Ma.gnoliaAdd to TechnoratiAdd to Furl

About these ads

15 Responses to “vSphere ESX4: Hot Add Memory for Linux Guests”

  1. [...] ESX4: Hot Add CPUs for Linux Guests Sometime ago within my post entitled vSphere ESX4: Hot Add Memory for Linux Guests, I promised to blog about hot add CPU support to the same VM.  As you may have guessed, I [...]

  2. [...] stated here, it is fairly easy to add memory online since esx4 if you have enable the option once offline [...]

  3. [Anonymous] Not said

    https://bugzilla.redhat.com/show_bug.cgi?id=669642

  4. fix 0x0000007b…

    [...]vSphere ESX4: Hot Add Memory for Linux Guests « Adaptive Thinking[...]…

  5. Felgi Aluminiowe…

    [...]vSphere ESX4: Hot Add Memory for Linux Guests « Adaptive Thinking[...]…

  6. [...] to at least scale-up CPU and memory resources online for newer versions of Windows and Linux. See here for a good description how to do that with Linux VMs. I would definitely consider it an enhancement [...]

  7. Ubuntu said

    Ubuntu…

    [...]vSphere ESX4: Hot Add Memory for Linux Guests « Adaptive Thinking[...]…

  8. Domain said

    Domain…

    [...]vSphere ESX4: Hot Add Memory for Linux Guests « Adaptive Thinking[...]…

  9. An absorbing communication is worth note. I imagine that you should compose author on this message, it power not be a inhibition bailiwick but generally group are not sufficiency to mouth on much topics. To the next. Cheers like your vSphere ESX4: Hot Add Memory for Linux Guests Adaptive Thinking.

  10. Supplementary Year’s Day is observed on January 1, the pre-eminent day of the year on the with it Gregorian calendar as well as the Julian chronicle used in primordial Rome. With most countries using the Gregorian chronicle as their main chronicle, Unusual Year’s Time is the closest thing to being the mankind’s only truly far-reaching public holiday, often noted with fireworks at the gesture of midnight as the advanced year starts. January 1 on the Julian slate currently corresponds to January 14 on the Gregorian diary, and it is on that engagement that followers of some of the Eastern Received churches celebrate the New Year.

    Sim so dep gia re Sfone | Gia Re

  11. [...] kernel discovers the new memory that you have added to the server. In addition, you might have to manually enable it in /sysThis post has no tagLeave a Reply Cancel replyYour email address will not be [...]

  12. alu-felgi said

    naturally like your web-site but you need to test the spelling on quite a few of your posts. Many of them are rife with spelling problems and I find it very bothersome to tell the truth nevertheless I will definitely come again again.

  13. yeu sinh ly…

    [...]vSphere ESX4: Hot Add Memory for Linux Guests « Adaptive Thinking[...]…

  14. games said

    travel Instruments and sung without the help of 21 separate producers !!!!!. Remember: a guidebook on a specific time in 2010. How about forced education, just like A Clockwork Orange?

  15. [...] should help http://adaptivethinking.wordpress.co…-linux-guests/ [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: