ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:120710] [Ruby master Feature#21042] Add and expose Thread#memory_allocations memory allocation counters
@ 2025-01-15 22:52 stanhu (Stan Hu) via ruby-core
  0 siblings, 0 replies; only message in thread
From: stanhu (Stan Hu) via ruby-core @ 2025-01-15 22:52 UTC (permalink / raw)
  To: ruby-core; +Cc: stanhu (Stan Hu)

Issue #21042 has been reported by stanhu (Stan Hu).

----------------------------------------
Feature #21042: Add and expose Thread#memory_allocations memory allocation counters
https://bugs.ruby-lang.org/issues/21042

* Author: stanhu (Stan Hu)
* Status: Open
* Assignee: ioquatix (Samuel Williams)
----------------------------------------
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.




-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-01-15 22:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-15 22:52 [ruby-core:120710] [Ruby master Feature#21042] Add and expose Thread#memory_allocations memory allocation counters stanhu (Stan Hu) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).