14

When setting up virtual machines on the various host systems I've used, be they Hyper-V, VMware or KVM, I have always allocated RAM in amounts that match physical memory configurations - e.g. to add 1GB of RAM I would add 1024MB, for 6GB of RAM I would add 6 x 1024 = 6144MB.

I realised that I've never thought about why I do this, it was just The Way Things Were Done at a previous workplace that I never questioned.

So, my question is, aside from the fact that it means virtualised operating systems can neatly round the allocated RAM to the nearest GB, are there any disadvantages to allocating RAM in quantities that are not powers of two, or multiples thereof? e.g. would there be any downside to adding 500MB of RAM, 750MB of RAM, or 1001MB of RAM?

Alternately, are there any advantages that would make this the recommended way of doing things?

I've left the question open-ended as far as host OS as I'd be interested to see if there are different considerations for the different hosts.

0
11

There's no downside. You can add what you need in terms of RAM. Same for CPUs. If you need 3 vCPU or 4 or 5, you can assign as required.

Some admins like to see multiples of 512 and 1024, but it really doesn't matter.

4
  • 1
    When you've been around so long you start answering the same thing :P (Yes technically the question is slightly different, but your answer is valid here as well)
    – Reaces
    Apr 21 '16 at 12:24
  • 2
    To add a little to this, the reason I prefer "round" numbers for my VM's is because I can easily tell how much RAM is available in the system. If you're using VM's in the cloud, it doesn't matter as much. But when I have a physical VM server with 32GB RAM, I know that that means I can have 32x1GB VM's, 16x2GB VM's, etc. How many VM's with a weird number, like 322MB RAM can I have? I'd have to do some math. So ewwhite is right, it doesn't matter for the VM itself, but it matters for the admin.
    – Jake
    Apr 21 '16 at 13:21
  • 1
    @Jake With ballooning and memory sharing the way it is, I'm not sure it's that simple anymore ;)
    – Reaces
    Apr 22 '16 at 5:44
  • @Reaces very true - and as I mentioned, the cloud - I deal much more with VM's in AWS than on my physical server, and as far as I'm concerned, Amazon has infinite memory. And if they ever ran out, they could just order more...from Amazon. 1022.5MB it is! But it does yield a little bit of information about why things were done in that way for quite a while.
    – Jake
    Apr 22 '16 at 12:38
3

No, there are no advantages / disadvantage. Sysadmins tends to prefer the round size, I do.

I can build a very small linux system and give it 403 MB of ram, the system will allocate what it is needed for it to work. But, you will not find modules of ram of 403 MB, because everything works with the powers of 2. So simply round to what best fit your build.

I used to virtualize Windows and Linux OS's in my single esxi and gave Ubuntu 768MB and Windows 3328MB and it was good for both, 4GB in total. If I'd have it with less ram, I simply would lose it.

0

are there any disadvantages to allocating RAM in quantities that are not powers of two, or multiples thereof?

First of all. Remember that every integer is a multiple of a power of two. So the real question to be asking is if you should restrict yourself to certain multipliers or certain powers of two.

Physical machines usually come with memory which is a small multiplier (1, 3, or 5) of a power of two. But the reasons for this do not apply to virtual machines.

However page sizes is a concern which applies to virtual machines. There are architectures which operate with exactly two possible page sizes. Common 32 bit architectures support pages of exactly 4KB and 4MB. Common 64 bit architectures support pages of exactly 4KB and 2MB.

If you keep the memory allocated to a VM always a multiple of 4MB, it will be more practical for the underlying code to use large pages for optimizing performance. For those reasons I recommend aiming for multiples of 4MB.

I do expect properly designed software to round sizes to a multiple of 4MB for you, if that is more beneficial. But if you choose a multiple of 4MB to begin with, you will be less reliant on the software getting those corner cases right.

Other than that, I say allocate the RAM to the VMs in quantities which are as accurate as you can predict their requirements. If you predict a VM needs between 500MB and 750MB for optimal performance, then allocate 752MB. I see no reason to round that up to 768MB or 1024MB.

The buddy memory allocation method used by some systems is designed to work with powers of two. However the method can with a small effort be adopted to work with sizes which are not a power of two. Even on physical machines with memory the size of a multiple of two, it is still likely that part of the physical memory isn't available to the buddy allocator. Thus every OS using this method can be expected to ensure other memory sizes will work.

Not the answer you're looking for? Browse other questions tagged or ask your own question.