Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-08-2004, 04:59 AM   #1
Registered: Dec 2003
Location: the Netherlands
Distribution: SuSE 9.0
Posts: 54

Rep: Reputation: 15
Memory usage of openGL program

I have a question about memory usage in openGL:

I am the developer of Ultimate Stunts ( ), and I have an ATI radeon 9200 card with 128MB video RAM, and using the closed-source drivers from ATI. I discovered with top that Ultimate Stunts needed up to 197 MB virtual memory, and I would like to know where that comes from.

First of all, that 197 MB is a stable number, so it's not a memory leak (at least not in the game loop). So I tried to turn everything off (texturing, z-buffering, detailed geometry, ...), and I managed to get the memory usage down to 155 MB.

Then I tried running glxgears, which needed 150 MB. So it seems that nothing's wrong with Ultimate Stunts. The extra 5MB can come from a bigger executable, and sound samples.

The next thing I tried was to turn every feature on step by step. The results showed that most features didn't increase the memory usage, but that fully enabling the textures needed an extra 39 MB.

I calculated the size of the bitmaps, and even with 32 bits per pixel it only was 28 MB.

The questions are:
1: why is that 150 MB for openGL so big?
2: Does that 150 MB include my 128 MB video memory?
3: I expect the textures to be loaded into video memory. If the video memory is already assigned to the process, then why does loading textures increase the memory usage? Is this a normal RAM cache of the openGL driver?
4: Why is the extra required memory for the textures not equal to the calculated size?
Old 09-08-2004, 05:52 AM   #2
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,991

Rep: Reputation: 76
1) Linux reports the video memory used by a program in addition to system RAM.
2&3) Video memory is dynamically allocated, just like system RAM, and the amount used grows as you put stuff into it. Otherwise, virtual desktops and virtual terminals (and even multiple apps on the same desktop) wouldn't work if you just allocated the whole lot to one process, because no other process would have any space to load its own bitmaps into.

To answer question 4, it depends on your hardware acceleration. But textures tend to be aligned on 32-bit boundaries even for 24-bit textures because this tends to make them faster to move around the graphics card. So you'll get 8 out of every 32 bits not being used.
Old 09-09-2004, 01:02 AM   #3
Senior Member
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 52
i'm as far from an expert in this as one can get !!!!!
but i like thinking about it so here i go...
first -- all memory in linux is a virtual abstraction layer
a top level page table array points to second level pages
the card driver is using memory mapping to map a range of regular user space virtual memory pages to the pages mapped to the device memory by the driver ...
it may even be possible that for speed the driver is writing dummy data to the allocated pages ???
possibly bypassing malloc and instead allocating page-aligned memory which might show up bigger due to page size alignment or if using malloc allocating a larger size and mapping an alligned page size region within it -- since the driver is a kernel module it is even possible these pages are locked !
and will show up everywhere as a fixed size.
OK all of this stuff is used by x and not by your program i think
if you look at
/proc/X_pid/map i think the /dev/mem entries are the maps to the card space
so the video card memory can potentially show all used up all the time ???
this is such an abstraction i might have the /dev/names backwards ?
when x writes your program data to /dev/ati (or whatever the user space side of the shared mapping is)
i'm not even sure it has to even shows up as your programm using memory (it's just piping through to memory allocated to x) ?? or it may be showing up as your program using all video mem ?
it looks like the latter for you .

anybody else with a different understanding of that please speakup

so what you are seeing in top for your app is non video card user space virtual memory
that must have a page or pages allocated to 100% of the video mem...
you should be able to look at /proc/pid and see exactly what it all is........

one interesting point is that i just ran glxgears here on my nVidia system and i get
18.8 Mb Total
6.2 Mb RSS
15.0 Mb Shared

so mine is just showing what is being used on the user side.
but it's all just too close to the total i think to be a coincidence for yours......
my x server says 154Mb which is almost exactly what you are saying.....
it's really all in how the driver is written i think.
Old 09-09-2004, 06:28 AM   #4
Registered: Dec 2003
Location: the Netherlands
Distribution: SuSE 9.0
Posts: 54

Original Poster
Rep: Reputation: 15
So as far as I understand it is possible that the 150 MB consists (partially) of memory mapped to the video memory, or shared memory with the X server & which is most probably driver specific. So I don't have to worry about that. I understand that memory alignment of the textures can take up some extra memory, which can make the difference between 28MB and 39MB.

Then one question remains: why does my memory usage increase when I load textures? I load them, give a pointer to openGL, openGL copies it to its own memory, and then I free it in my own memory. I expect the openGL driver to load it into video RAM. If this was not already present in that 150MB, then I'd like to know what IS in the 150MB. Maybe it's the X server's memory, maybe I'll have a look at that /proc/[id]/map.

One other interesting thing: I tried to run glxgears TWO times simultaneously, and they did not rotate simultaneously. Instead, first nr 1 rotated for maybe a second, then the other, then the first again etc. Is this a slow kind of multitasking to the video card resources?


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
memory usage issh1 Linux - Software 2 06-30-2005 02:36 AM
getting realtime info on memory usage-cpu and harddrive usage steering Linux - Newbie 5 03-03-2005 08:43 PM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM
Controlling CPU usage & memory usage Saravana babu Linux - Software 0 02-18-2004 05:55 AM
Memory Leak when using memory debugging C program on SuSE SLES8 babalina Linux - Distributions 0 10-06-2003 09:39 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:50 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration