iosinstrumentsvirtual-memory

What is the difference Between 'Dirty Memory' and 'Dirty Size' in iOS VM Tracker?


In the WWDC 2022 session(https://developer.apple.com/videos/play/wwdc2022/10106/), they explained that memory allocation can be categorized into three types: Dirty, Compressed Dirty, and Clean. And Dirty memory refers to allocations like heap allocations, which tend to have a high resident memory ratio.

And when I profile iOS app with VM tracker in Xcode instruments, I can see allocations like malloc are categorized as Dirty type.

enter image description here

Still, I'm confused due to the presence of both a 'Dirty' memory type and a 'Dirty Size' metric at the top of the view.

My guess is that the Dirty memory 'type' refers to types of allocations like malloc, which are likely to result in dirty pages.

And Dirty Size metric might represent the cumulative size of allocated memory pages that have been written to and thus have become dirty pages.

For example, malloc is "Dirty Type" but it's "Dirty Size" can be almost zero bytes. -I can do allocations with malloc for new array but not assign any value to it, so committed pages won't be actually mapped to Physical memory.

int *array = malloc(2000 * sizeof(int));

Still, I'm not sure about it. I would be grateful if anyone can clarify the exact definitions of these terms.


Solution

  • The “*Dirty*” section contains all memory regions (for example, malloc regions) that have at least one dirty page. The “Dirty Size” column indeed refers to the amount of memory contained in pages that have been written to. So, taking your code as an example:

    int *array = malloc(2000 * sizeof(int));
    

    After running this line of code, array will show up in the *All* section, not the *Dirty* section.

    array[100] = 100
    

    After running this line of code, array will show up in the *Dirty* section, with one page's worth of memory dirtied.