user2492286
user2492286

Reputation: 99

Ruby process memory structure

I'm trying to figure out an issue with memory usage in a ruby process. I tried to take a heap dump of the ruby process using the ObjectSpace module to understand what's happening. What's puzzling is that, the "top" command in linux reports that the process uses 17.8 GB of virtual memory and 15GB of resident memory. But, the size of the heap dumps are only around 2.7-2.9 GB.

Based on the Ruby documentation, Objectspace.dump_all method dumps the contents of the ruby heap as JSON.

I'm not able to understand what is hogging the rest of the memory. It would be helpful, if someone could help me to understand what's happening.

Thank you.

Upvotes: 1

Views: 1095

Answers (1)

anothermh
anothermh

Reputation: 10564

It is likely that your application is allocating objects that are then groomed by the Garbage Collector. You can check this with a call to GC.stat

Ruby does not release memory back to the operating system in any meaningful way. (if you're running MRI) Consequently, if you allocate 18GB of memory and 15GB gets garbage collected, you'll end up with your ~3GB of heap data.

The Ruby MRI GC is not a compacting garbage collector, so as long as there is any data in the heap the heap will not be released. This leads to memory fragmentation and the values that you see in your app.

Upvotes: 1

Related Questions