winsiderss / systeminformer

A free, powerful, multi-purpose tool that helps you monitor system resources, debug software and detect malware. Brought to you by Winsider Seminars & Solutions, Inc. @ http://www.windows-internals.com
https://systeminformer.sourceforge.io
MIT License
10.81k stars 1.38k forks source link

Strange results in Memory usage measurements on OGL apps #1606

Open DiegoJArg opened 1 year ago

DiegoJArg commented 1 year ago

Hello all. I have been looking into immediate gui ui and its backends, most of which are OGL-based. While learning, I started to test several backends and check for its memory footprints w/ProcessHacker and compare them.

3D-accelerated backends are measured much higher on memory usage than normal GDI-apps. While most of the apps get compiled sizes of about 500kb its Memory usage goes above 10Mb easily. Libraries like SDL2 are about 2.5Mb and immediate mode UI's are not usually relying on Memory usage.

I got to try some simplistic examples with just triangles. See attachment WGL gets 22Mb, while GDI gets 1.5Mb. The difference on measurement is huge. I would guess that there must be dedicated memory in-use. ¿Is it being added all together? There could also be some buffers or double buffers.

It is said that GDI will go to be deprecated someday and everything will move in favour of Direct2D, on top of D3D. With the results shown here, as a data-driven decision, I would stick to GDI, but doesn't sound reasonable.

It would be interesting on the statistics tab, if it could be summarized, what type of memory is being used, what kind of usage heap/stack/file, and how much of it is shareable or not. I guess that buffers are handled by libraries by themselves, so ram usage should be assigned to the library instead of the application owns usage.

My final desired use is to easily inspect the use of shared system libraries and dedicated hardware.

I love this app !

Win32-API.zip

image

image

dmex commented 5 months ago

The difference is likely due to GDI caching bitmaps and other graphics objects in kernel mode and reusing those objects for multiple processes while WGL/OGL are not sharing bitmaps/objects across multiple processes.

https://devblogs.microsoft.com/oldnewthing/20240409-00/?p=109630

That’s because there are some objects which are considered owned by the system itself and not any specific process. Examples include objects on the clipboard, stock objects, and certain types of bitmaps.

It would be interesting on the statistics tab, if it could be summarized, what type of memory is being used, what kind of usage heap/stack/file, and how much of it is shareable or not.

It's possible but can't be automatic because these statistics require enumerating every page of the process and some processes with GB's of memory can and do take 20-30 minutes to enumerate.

DiegoJArg commented 5 months ago

Hi !! Thank you for your answer and bringing up this topic again !! I readed here and here about nvidia and cuda drivers mapping all its memory space (GPU+host memory) into a single linear large virtual address space using the kernel's virtual memory system for unified addressing.

Now, I have just an Intel HD4000 with just 32Mb of dedicated memory, which if it is truly being mapped, then applications above kernel will have wrong measurements adding up memory that is physically in the GPU.

Additionally, some drivers have suballocators that may behave differently than the windows one and reserve large space that windows tools may "think" is in active use, but probably just full of zeros.

But I don't know much about this, I would like an expert to figure out if this is what is happening, else gdi32 seem to be the lowest memory usage footprint because of erroneous readings.