Page MenuHome

Cycles: Always use guarded allocator of vectors
ClosedPublic

Authored by Sergey Sharybin (sergey) on Feb 6 2016, 11:47 PM.

Details

Summary

We don't have vectors re-allocation happening multiple times from inside
a loop anymore, so we can safely switch to a memory guarded allocator for
vectors and keep track on the memory usage at various stages of rendering.

Additionally, when building from inside Blender repository, Cycles will
use Blender's guarded allocator, so actual memory usage will be displayed
in the Space Info header.

There are couple of tricky aspects of the patch:

  • TaskScheduler::exit() now explicitly frees memory used by threads. This is needed because threads is a static member which destructor isn't getting called on Blender's exit which caused memory leak print to happen.

    This shouldn't give any measurable speed issues, reallocation of that vector is only one of fewzillion other allocations happening during synchronization.
  • Use regular guarded malloc (not aligned one). No idea why it was made to be aligned in the first place. Perhaps some corner case tests or so. Vector was never expected to be aligned anyway. Let's see if we'll have actual bugs with this.

Diff Detail

Repository
rB Blender

Event Timeline

Sergey Sharybin (sergey) planned changes to this revision.Feb 7 2016, 12:01 AM

Weird, ok. It works all fine in debug mode, but in release mode crashes with memory issues even when using aligned allocator. Need to have a closer look..

Just a quick update: the issue is in order of add_subdirectory and add_definitions, basically blender/ was compiled in without guardedalloc flag.

I also changed the way how allcoator is being subclassed and made it standalone, so it does not depend on any std routines. Discovered some more memory leaks, probably from other static members somewhere. Will update the patch once those are solved.

Solve various things:

  • Make guarded allocator self-contained and not subclassed in order to avoid possible conflicts with implementation details of std::allocator.
  • Solve wrong add directory/definitions order which was causing major memory bugs.
  • Free memory of static vectors on Blender exit.

    This is needed to avoid guarded allocator confusion about unfreed datablocks. Alternatively, we can use special vector type which doesn't use guarded allocator, but not sure it's indeed more clear approach since then you'll have all the weird mix of different vector types.

Think the patch is now ready for the review.

Brecht Van Lommel (brecht) edited edge metadata.

Looks good to me.

One very minor comment is that I'd rename deinit to exit, just because that's the terminology already used in TaskScheduler and I think it sounds nicer :)

This revision is now accepted and ready to land.Feb 7 2016, 3:42 PM
This revision was automatically updated to reflect the committed changes.