Noesis memory fragmentation crashes - how to avoid?
Posted: 12 Feb 2018, 17:29
Context:
Our app is an image editor and is very UI-heavy. We noticed that it crashes during stress testing doing the following repeatedly:
1. Open an image
2. Going through few XAML screens (just to select effect below)
3. Run simple "convert to grayscale" effect on GPU
4. go to 1
After a week of investigation about the source of the crash and more than 50 runs with a variety of code changes and debug logging, we figured out it's GPU memory fragmentation.
[Very] Long story short - after many other changes, in the end, we turned off Noesis completely and saw this:
With Noesis: app crashes after 54 open-effect-close iterations
Without Noesis: app keeps running after 330 open-effect-close iterations
We think something like this is happening in the GPU memory, where "A" means "app allocated memory" and "N" means "Noesis allocated memory"
GPU (and maybe CPU) memory "creeps up" on every iteration, thus causing an early crash. This is on Android phone.
Question
How can we better manage Noesis memory to ensure no fragmentation and crash happens? e.g. maybe a trick to specify to Noesis "allocate this much and use this space as your own?"
I remember before there used to be pre-determined off-screen surface size. I think that was helpful in managing fragmentation. Having something like "minimum pre-determined off-screen surface size" would be great to avoid the crash. We could set during app start to what we think is the most Noesis would use and thus prevent crashes due to GPU memory fragmentation.
Our app is an image editor and is very UI-heavy. We noticed that it crashes during stress testing doing the following repeatedly:
1. Open an image
2. Going through few XAML screens (just to select effect below)
3. Run simple "convert to grayscale" effect on GPU
4. go to 1
After a week of investigation about the source of the crash and more than 50 runs with a variety of code changes and debug logging, we figured out it's GPU memory fragmentation.
[Very] Long story short - after many other changes, in the end, we turned off Noesis completely and saw this:
With Noesis: app crashes after 54 open-effect-close iterations
Without Noesis: app keeps running after 330 open-effect-close iterations
We think something like this is happening in the GPU memory, where "A" means "app allocated memory" and "N" means "Noesis allocated memory"
Code: Select all
iteration 1:
open image: [NNAAAAAAAAAAAA....................] <-- initial GPU memory with noesis and image loaded
switch XAML: [NNAAAAAAAAAAAANN..................] <-- Noesis adds some memory
effect, then close image: [NNNN..........NN..................] <-- notice image is released, Noesis maybe allocated some more memory? (not sure, could be due to trasparencies)
iteration 2:
open image: [NNNN..........NNAAAAAAAAAAAA......] <-- since memory is fragmented, new image cannot allocate the smaller "gap" thus using different memory region
...
Question
How can we better manage Noesis memory to ensure no fragmentation and crash happens? e.g. maybe a trick to specify to Noesis "allocate this much and use this space as your own?"
I remember before there used to be pre-determined off-screen surface size. I think that was helpful in managing fragmentation. Having something like "minimum pre-determined off-screen surface size" would be great to avoid the crash. We could set during app start to what we think is the most Noesis would use and thus prevent crashes due to GPU memory fragmentation.