5

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?

4

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:

coherent_pool=6M
smsc95xx.turbo_mode=N
gpu_mem=128
cma_lwm=16
cma_hwm=32

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.

However...

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:

gpu_mem=8

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.

2

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
  reboot
}
else if ( !hdmiconnected AND md5(/boot/config.txt)!=md5(/boot/config-nohdmi.txt) )
{
  copy /boot/config-nohdmi.txt /boot/config.txt
  reboot
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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