'Total Used Memory' is greater than 'System Used Memory' on Quest 2

Hi,

I'm currently making a in game memory profiler module with a breakdown similar to the breakdown in the built-in memory module. I'm using the profile counters detailed in the documentation (https://docs.unity3d.com/Manual/ProfilerMemory.html). Everything works great and correctly when running in editor, but when I deploy on the target platform (Quest 2) I see that 'Total Used Memory' is greater than 'System Used Memory', which I assume is incorrect. You can also see this in the memory module in the builtin profiler: 8357433--1100079--Screenshot 2022-08-12 140331.png

Is this a known issue?
Which of the counters is correct, 'System Used Memory' or 'Tracked Memory used'?
Also, is there a reason Untracked Memory is unknown?

Appreciate any answers :)

Hi. Which Unity version is that?

Generally speaking, it's because there is no fast way of getting "System Used Memory" on Linux-based platforms, and the closest approximation might return an incorrect number. If you need a more precise value you need to take a snapshot in Memory Profiler.

This was in Unity 2022.1.7f1.

I see, is this also why “untracked” memory is unknown in the profiler?

It’s a bit more complicated.

  1. Why “System Used Memory” sometime less ‘Tracked Memory used’

Linux traditionally has a hacky way of reporting total (committed) memory used by a process (VSS), which worked fine for older 32bit systems but returns complete gibberish for more modern 64bit systems. There is a way to get a more reasonable value, but sampling it takes ~200ms so it can’t be done per frame & in real-time.

As a result, in real-time profiler and counters on Linux instead of reporting total committed value, we report resident memory value (RSS). It’s smaller and might be smaller than “Total Tracked” but have much more sense than the alternative.

On the other hand than it comes to memory profiler, 200ms is nothing and we use more precise methods to get memory information.

  1. Why there is “Untracked”
    Unity has memory manager which tracks all allocations made in our code. Unfortunately, then it comes to native plugins and some OS subsystems, they might allocate process memory but their allocations won’t be done through our memory manager and so aren’t tracked. The simplest example on Android - Android VM (Dalvik) does allocation but they’re invisible to our memory manager and so will be adding to “Untracked” value.

We’re improving Memory Profiler to visualize such allocations but getting that information is a slow process and can’t be done in real-time.

I see, thanks for the answer. I don’t need our real-time memory tracker to be totally correct. It’s more to get an estimate and have some indication of when you need to reach for a more specific tool (such as the memory profiler) and do more precise profiling. Given the unreliability of the “System Used Memory” would you think that “Tracked Memory Used” would be a better candidate for such a system?

Also, the ‘System Used Memory’ is as far as I’ve seen always less than ‘Tracked Memory Used’ on the Quest 2, and it looks like ‘System Used Memory’ is in the ballpark of ‘Tracked Memory Used - (GFX Memory Used / 2)’. The Quest 2 has combined GPU and CPU memory, could that be a possible explanation as to why I’m seeing this, or would you think that this is just a coincidence?

Right, the question was more about why the ‘Untracked’ category has an ‘unknown’ value (as can be seen in the screenshot in the post). Because in the editor there’s always a value there, never ‘unknown’ :slight_smile:

The Unknown value is just a result of the UI realizing that it tracked more than the System claimed was used, so the untracked amount can’t be positive, (would be negative but that makes no sense) and is therefore unknowable for the tool.