Project

General

Profile

Actions

Feature #21042

open

Add and expose Thread#memory_allocations memory allocation counters

Added by stanhu (Stan Hu) about 10 hours ago.

Status:
Open
Target version:
-
[ruby-core:120710]

Description

For the last 5 years, we've been patching our Ruby interpreter with https://github.com/ruby/ruby/pull/3978 in order to track memory allocations over time. This has been running in production at GitLab for a long time.

I'd like to request approval for this patch to land upstream since we're getting tired of maintaining this patch, and this data seems like it would be generally useful. If this can be done via a C extension, let me know, and I can look at that.

Copying from that pull request:

Design

This is designed to measure a memory allocations in a multi-threaded environments (concurrent requests processing) with an accurate information about allocated memory within a given execution context.

The idea here is to provide as cheap as possible counter without an overhead of calling callbacks, and provide this information on a per-thread basis.

Implementation

This adds Thread.current.memory_allocations, which provides information about:

  • total_allocated_objects
  • total_malloc_bytes
  • total_mallocs

This is based on a expectation, that allocation for a given thread always happens
with a rb_current_thread() properly indicating a thread performing allocation.
This measures total number of allocations as counters.

Now, since the removal of objects is async and happening at random moment,
the same cannot be said for deallocations, thus only allocations are tracked.

No data to display

Actions

Also available in: Atom PDF

Like0