AlexJ
Posts: 6
Joined: Tue Feb 24, 2015 1:52 pm

Getting GPU memory usage

Thu Aug 25, 2016 10:33 am

Is there a better way of obtaining GPU memory usage than using `vcdbg reloc`? Since that requires that you flush the cache first, it's not reliable.
The vcgencmd mem_reloc_stats and mem_oom commands are useful, but it would be nice to get the usage before we run out. I notice there is a mem_test command which seems to perform some kind of test allocation. So I can't figure out how much is left by trial and error. But is it atomic? IE, will other processes fail to allocate during the test?

Or, is there some other way of getting the memory usage that I have missed? (Fine if it's an API call).

Thanks!

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: Getting GPU memory usage

Fri Aug 26, 2016 5:44 pm

In order to get the GPU mem usage the easiest way is to use the MailBox Property Tag 0x00010006 Get VC memory.

I am not yet familiar with any other method of doing this.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

AlexJ
Posts: 6
Joined: Tue Feb 24, 2015 1:52 pm

Re: Getting GPU memory usage

Fri Aug 26, 2016 7:06 pm

Thanks. This seems to be returning the total GPU memory size:
$ /opt/vc/bin/vcmailbox 0x00010006 0x10 0 0 0 0 0 0
0x0000002c 0x80000000 0x00010006 0x00000010 0x80000008 0x37000000 0x08000000 0x00000000 0x00000000 0x00000000 0x00000000
(128Mb in my case). What I would like is the amount of free memory. Have I made a mistake in how to call it?

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5378
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Getting GPU memory usage

Fri Aug 26, 2016 7:34 pm

Code: Select all

vcgencmd get_mem <type>
Where type is:
arm: total memory assigned to arm
gpu: total memory assigned to gpu
malloc_total: total memory assigned to gpu malloc heap
malloc: free gpu memory in malloc heap
reloc_total: total memory assigned to gpu relocatable heap
reloc: free gpu memory in relocatable heap

AlexJ
Posts: 6
Joined: Tue Feb 24, 2015 1:52 pm

Re: Getting GPU memory usage

Tue Aug 30, 2016 8:59 am

Thanks! That's exactly what I was looking for.

Return to “C/C++”