On the RaspberryPI, GPU (video) and system memory are shared. When I installed and configured my Raspbian OS for the first time, I split the RAM available between GPU and CPU.
The RAM sharing means if your RPi has 512mb of RAM, some of that RAM will be reserved to use as video memory. If you don't use the GUI, you can set the GPU memory to be 16MB. If you are using a GUI, you may want to go with 64, 128, or even 256MB of GPU RAM.
What I wanted to do was to have a dynamic allocation of memory regarding the run-time load of GPU and CPU. It's much better than to manually change the memory parameters every time the type of use changes (hdmi, crt, ssh, more gui intensive use, more hdmi intensive use, etc).
In order to allow the Dynamic Memory Split I had to do a Firmware Upgrade. Be afraid, be very much afraid... lol
What I wanted to do was to make the process as error free as possible. It worked for me. Here it goes:
- Make sure that Pi Time is updated by using NTP
a. sudo apt-get install ntpdate sudo
b. ntpdate -u ntp.ubuntu.com
- Make sure the GitHub's SSL certificate is trusted. For that install the ca-certificates:
a. sudo apt-get install ca-certificates
- Install the upgrade tool
a.sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update && sudo chmod +x /usr/bin/rpi-update
- Do the Upgrade
- After the firmware has been successfully updated, you'll need to reboot to load the new firmware.
a. Sudo reboot
- At this moment I was able to add my config.txt memory parameters by editing the config.txt as sudo:
(Basically what these three lines mean is that I’ll always have a set number allocated to the processor, and it will have 96Mb of memory and the GPU will always have at least 20Mb. But, when the GPU gets low, it will request some memory from the processor, and vice versa. The cma_lwm is the “low water mark” meaning if it has less that memory available it will request it from the processor. If the GPU has more than cma_hwm (high water mark) it will release memory to the processor).
- Add the following to your cmdline.txt (do this before adding the memory config.txt parameters as sudo in the command above)
- Reboot to activate the memory parameters
- After rebooting, let's confirm the allocated memory:
As we can see, the non-allocated memory is now around 412 Mb after booting the system!!!! With this available memory I'll be able get more performance. Only around 57Mb are allocated to the gpu (I don't need more at boot-time). Don't forget that now I've got dynamic memory on the Pi, which means that if the system needs more memory for the gpu, it'll allocate it in run-time... If I’m building something from source or doing a lot of video I’ll want to squeeze every bit of performance I can out of it.
Let's do a memory test in run-time. First load the X-Windows and then try to visualize something on it. What I can see is that the memory starts to diminish:
(I executed several "cat /proc/meminfo |grep Mem" commands as I was starting to run several programs on the X-Windows).
Now, in terms of boosting the performance all I have to do is overclock it...But that's for another post :)
Happy hacking. You don’t learn to hack – you hack to learn…