Bug 101467 - swr driver leaks memory (texture management)
Summary: swr driver leaks memory (texture management)
Status: RESOLVED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: Drivers/Gallium/swr (show other bugs)
Version: 17.1
Hardware: Other All
: medium normal
Assignee: mesa-dev
QA Contact: mesa-dev
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-06-16 14:34 UTC by Andrés Gómez García
Modified: 2017-07-20 14:08 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Andrés Gómez García 2017-06-16 14:34:01 UTC
This is, basically, the same report than bug 23530.

If you run the piglit test to check above's bug with the swr driver, oom-killer kicks in:
https://cgit.freedesktop.org/piglit/tree/tests/texturing/streaming-texture-leak.c

My command line is something like:
$ LIBGL_ALWAYS_SOFTWARE=1 GALLIUM_DRIVER=swr /home/local/piglit/bin/streaming-texture-leak -auto
Comment 1 Bruce Cherniak 2017-06-28 21:10:59 UTC
Well, technically the swr driver isn't "leaking" memory, it's just deferring deletion of the underlying storage until a sync point.

Because the loop is simply:
   for (bigly_number_of_textures) {
      allocate_texture()
      draw_something()
      delete_texture()
   }
   read_pixels()

There is nothing forcing synchronization until the read_pixels.  So, at the end of the loop, there are 5000 free() queued up, that all get flushed on the read_pixels.  This accounts for ~20GB of allocated system memory.
Comment 2 Bruce Cherniak 2017-06-28 22:11:52 UTC
For the curious, this is the same result as allowing llvmpipe to build larger scenes by setting the defines LP_SCENE_MAX_SIZE and LP_SCENE_MAX_RESOURCE_SIZE to *large* values.

This suggests that when/if the oom-killer kicks in is more dependent on the amount of system memory than indicative of a memory leak.
Comment 3 Bruce Cherniak 2017-06-29 15:44:25 UTC
I'm going to close this as "not a bug", since we're technically not leaking memory.
Comment 4 Eero Tamminen 2017-06-30 07:54:36 UTC
If application is freeing the resources, but driver memory usage still grows unbounded due to deferred deletion, I'm not sure what else it could be described than leak...
Comment 5 Bruce Cherniak 2017-06-30 20:15:06 UTC
OK.  I have a small patch that lowers the overall memory usage for streaming-texture-leak without affecting our targeted applications.

For those running on smaller memory (16GB?) systems, this will prevent oom-killer.

Thus far, we have not seen any real world applications that exhibit behavior similar to the streaming-texture-leak test; as any form of pipeline flush will trigger the defer queue and properly free any retained allocations.  But, this addresses those as well.  

I'll submit the patch for review shortly.
Comment 6 Bruce Cherniak 2017-07-03 20:39:06 UTC
Fixed in master by commit 32c1a54b.  cc'd for inclusion in 17.1 stable.

This patch limits the number of items on the fence work queue (the
deferred deletion list) by submitting a sync fence when the queue size
exceeds a threshold.  This initiates deferred deletion of all resources
on the list and decreases the total amount of memory held waiting for
"deferred deletion".
Comment 7 Bruce Cherniak 2017-07-20 13:13:13 UTC
Available in 17.1.5 with commit 5c91fcfa.
Comment 8 Andrés Gómez García 2017-07-20 14:08:29 UTC
(In reply to Bruce Cherniak from comment #7)
> Available in 17.1.5 with commit 5c91fcfa.

Thanks Bruce, I should actually have noted that myself.

I suppose we can close, then ...


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.