For the most part, I run my Raspberry Pi headless (which requires very little VRAM). However, I occasionally plug in a monitor (usually after I mess up my SSH configuration).

Is there a way to have the Raspberry Pi allocate less VRAM if HDMI isn't present on boot, and more VRAM when HDMI is connected on boot?

  • What OS are you using?
    – syb0rg
    Jan 12, 2014 at 2:08
  • Raspbian and occasionally Arch and Raspbmc
    – Alexander
    Jan 12, 2014 at 2:47

2 Answers 2


According to this:

The firmware and kernel as of 19. November 2012 supports CMA, which means the memory split between ARM and GPU is managed dynamically at runtime.

If you enable that, you should not have to do anything -- when you start X, if the GPU needs memory, it can request some from the CPU. The configuration goes in /boot/config.txt and is explained in that elinux link. I've tried:


This works with the latest stock raspbian kernel (3.10.25), but beware if you have a custom kernel you will need to enable CMA or this will give you grief. I don't think the first two directives are strictly necessary, YMMV.

Afterward, you should be able to run vcgencmd commands and see a list including cma_config and get_mem (the last one requires a parameter, either arm or gpu). If you run free, you should have a base mem of ~475 MB, more than the ~448 MB without CMA using the default 64 MB of video mem, even though gpu_mem=128.


If all you need the monitor for is special occasions ("usually after I mess up my SSH configuration"), you don't need this, and you don't two configurations either, because you'll get the most RAM (~497 MB) this way:


No CMA configuration, etc. This is my preference, and I can plug in an HDMI monitor and start X. Most of the memory needed to run a GUI desktop is actually CPU memory.

In short, you don't need much gpu mem at all1 -- certainly the display will work with much less than the default 64 MB -- and you don't need two configurations.

1. Without having looked into it, I would guess most of time you could never use more than X resolution x Y resolution x 4 (32-bits/pixel) x 2 (double buffer?) bytes; e.g. for HD 1920 x 1080 x 4 x 2 = 16 MB -- and the use of a double buffer there is a big assumption, so likely only half that. Much larger amounts of GPU memory probably only come into play when openGL-ES, or some other special feature (GPU accelerated video playback) is in use.


Not directly I think, but you could just run a script on bootup that checks the values in /boot/config.txt. If they don't match the values needed for the current state of the hdmi, changes the values in config.txt and then performs a reboot.

Easiest way to implement this is to just have two config.txt files. Something like config-hdmi.txt and config-nohdmi.txt.

Then in pseudo code

if( hdmiconnected AND md5(/boot/config.txt)!=md5(/boot/config-hdmi.txt) )
  copy /boot/config-hdmi.txt /boot/config.txt
else if ( !hdmiconnected AND md5(/boot/config.txt)!=md5(/boot/config-nohdmi.txt) )
  copy /boot/config-nohdmi.txt /boot/config.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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