Total Memory on a Xen Node

I ran into an interesting issue the other day that I figured I’d make a post about in order for others. Since my company is getting more into Xen Hosting, I’ve tried to be at the forefront of the virtualization software for the company. We did run into an interesting issue though the other day when it came to determining the total amount of memory on a hardware node. Since we set up the Domain-0 to use only 512MB of memory, we were having a tough time determining how much total RAM is in the server. After googling for awhile and asking some co-workers, I discovered the following command:

xm info

This command shows quite a few interesting metrics including the total memory for the server. Using this I was able to easily discern the total amount of memory and write a quick script to compute total amount of memory:

1
2
3
4
5
6
7
8
9
10
#!/bin/bash
 
total_memory=$(xm info | grep total_memory | awk '{print $3}')
remaining=$(xm info | grep free_memory | awk '{print $3 - 512}')
used_memory=$((total_memory-remaining))
 
 
echo -e 'Total Memory:\t'$total_memory'MB ('$((total_memory/1024))'GB)'
echo -e 'Memory Used:\t'$used_memory'MB ('$((used_memory/1024))'GB)'
echo -e 'Remaining:\t'$remaining'MB ('$((remaining/1024))'GB)'

Hope this helps anyone else trying to figure out accurate Xen Memory usage

2 Replies to “Total Memory on a Xen Node”

  1. I too was caught out by the Xen hypervisor’s method of memory management. The Dom-0 machine is allocated RAM in the same way as the Dom-U’s via the hypervisor. This means that the only way you can actually get data on the total RAM for the whole physical machine is via xm info on the Dom-0. We now run your script on our servers – Thank you 🙂

  2. I’m glad to hear my script could help you! Xen’s memory management is indeed odd but, overall, I think it’s a far better hypervisor then OpenVZ.

Leave a Reply

Your email address will not be published. Required fields are marked *