mwrap user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH] mwrap 2.0.0 mwrap - LD_PRELOAD malloc wrapper for Ruby
@ 2018-07-20  9:25  4% Eric Wong
  0 siblings, 0 replies; 4+ results
From: Eric Wong @ 2018-07-20  9:25 UTC (permalink / raw)
  To: ruby-talk, mwrap-public

mwrap is designed to answer the question:

   Which lines of Ruby are hitting malloc the most?

mwrap wraps all malloc-family calls to trace the Ruby source
location of such calls and bytes allocated at each callsite.
As of mwrap 2.0.0, it can also function as a leak detector
and show live allocations at every call site.  Depending on
your application and workload, the overhead is roughly a 50%
increase memory and runtime.

It works best for allocations under GVL, but tries to track
numeric caller addresses for allocations made without GVL so you
can get an idea of how much memory usage certain extensions and
native libraries use.

It requires the concurrent lock-free hash table from the
Userspace RCU project: https://liburcu.org/

It does not require recompiling or rebuilding Ruby, but only
supports Ruby trunk (2.6.0dev+) on a few platforms:

* GNU/Linux
* FreeBSD (tested 11.1)

It may work on NetBSD, OpenBSD and DragonFly BSD.


Changes in 2.0.0:

This release includes significant changes to track live
allocations and frees.  It can find memory leaks from malloc
with less overhead than valgrind's leakchecker and there is a
new Rack endpoint (MwrapRack) which can display live allocation
stats.

API additions:

* Mwrap#[] - https://80x24.org/mwrap/Mwrap.html#method-c-5B-5D
* Mwrap::SourceLocation - https://80x24.org/mwrap/Mwrap/SourceLocation.html
* MwrapRack - https://80x24.org/mwrap/MwrapRack.html

Incompatible changes:

* Mwrap.clear now an alias to Mwrap.reset; as it's unsafe
  to implement the new Mwrap#[] API otherwise:
  https://80x24.org/mwrap-public/20180716211933.5835-12-e@80x24.org/

26 changes since v1.0.0:

      README: improve usage example
      MANIFEST: add .document
      add benchmark
      use __attribute__((weak)) instead of dlsym
      Mwrap.dump: do not segfault on invalid IO arg
      bin/mwrap: support LISTEN_FDS env from systemd
      support per-allocation headers for per-alloc tracking
      mwrap: use malloc to do our own memalign
      hold RCU read lock to insert each allocation
      realloc: do not copy if allocation failed
      internal_memalign: do not assume real_malloc succeeds
      ensure ENOMEM is preserved in errno when appropriate
      memalign: check alignment on all public functions
      reduce stack usage from file names
      resolve real_malloc earlier for C++ programs
      allow analyzing live allocations via Mwrap[location]
      alias Mwrap.clear to Mwrap.reset
      implement accessors for SourceLocation
      mwrap_aref: quiet -Wshorten-64-to-32 warning
      fixes for FreeBSD 11.1...
      use memrchr to extract address under glibc
      do not track allocations for constructor and Init_
      disable memalign tracking by default
      support Mwrap.quiet to temporarily disable allocation tracking
      mwrap_rack: Rack app to track live allocations
      documentation updates for 2.0.0 release

^ permalink raw reply	[relevance 4%]

* Re: [ANN] mwrap - LD_PRELOAD malloc wrapper + line stats for Ruby
  @ 2018-07-16 21:48  4%     ` Eric Wong
  0 siblings, 0 replies; 4+ results
From: Eric Wong @ 2018-07-16 21:48 UTC (permalink / raw)
  To: Sam Saffron; +Cc: ruby-talk, mwrap-public

Eric Wong <e@80x24.org> wrote:
> Sam Saffron <sam.saffron@gmail.com> wrote:
> > Is there any chance we can have a mode with "free" tracking as well?
> > That way we can enable this on a long running process to detect leaks?
> 
> Maybe, but it might get a lot more expensive to be useful...
> Merely counting frees and associating them with source lines
> like mwrap currently does with *allocs would not be useful,
> since GC can call free from just about anywhere.

Definitely more expensive, but it's still usable:

   https://80x24.org/mwrap-public/20180716211933.5835-1-e@80x24.org/

TL;DR: live demo of the new features running inside a Rack app:

  https://80x24.org/MWRAP/each/2000

The following changes since commit 834de3bc0da4af53535d5c9d4975e546df9fb186:

  bin/mwrap: support LISTEN_FDS env from systemd (2018-07-16 19:33:12 +0000)

are available in the Git repository at:

  https://80x24.org/mwrap.git heavy

for you to fetch changes up to c432e3ad30aa247dbac8575af87b0c594365d3fd:

Cloning from that git URL runs it through the same process which
is running /MWRAP/.  (I will eventually replace cgit on
80x24.org with repobrowse <https://80x24.org/repobrowse/README>)

> So we'd have to try per-allocation accounting to know for sure
> and it could get time consuming.

So depending on the application, it's up to 50% more memory
intensive and 50% slower.  Though likely cheaper than most leak
checkers (definitely cheaper than valgrind's leakchecker).

memalign functions (used by CoW-friendly Ruby GC) ends up
causing massive fragmentation as a result, because we can't reuse
the the overallocated part like a full malloc implementation
can.  And I even disabled tracking allocations made by them by
default, since it can be noisy and misleading when hit in cold
paths.

> Yes, if we add per-allocation tracking, storing the
> rb_gc_count() result for each malloc count could be useful to
> track the relative age of each malloc-ed region.

Yes, that's done, and the /at/$LOCATION endpoint lets us see
the size and rb_gc_count value at the time of allocation
for each live allocation:

https://80x24.org/MWRAP/at//home/rb/lib/ruby/gems/2.6.0/gems/rack-2.0.5/lib/rack/deflater.rb:77

(note the double slash :<)

^ permalink raw reply	[relevance 4%]

* [PATCH 0/19] the heavy version of mwrap
@ 2018-07-16 21:19  5% Eric Wong
  0 siblings, 0 replies; 4+ results
From: Eric Wong @ 2018-07-16 21:19 UTC (permalink / raw)
  To: mwrap-public

TL;DR: live demo of the new features running inside a Rack app:

  https://80x24.org/MWRAP/each/2000

The following changes since commit 834de3bc0da4af53535d5c9d4975e546df9fb186:

  bin/mwrap: support LISTEN_FDS env from systemd (2018-07-16 19:33:12 +0000)

are available in the Git repository at:

  https://80x24.org/mwrap.git heavy

for you to fetch changes up to c432e3ad30aa247dbac8575af87b0c594365d3fd:

  mwrap_rack: Rack app to track live allocations (2018-07-16 21:14:13 +0000)

----------------------------------------------------------------
Eric Wong (19):
      support per-allocation headers for per-alloc tracking
      mwrap: use malloc to do our own memalign
      hold RCU read lock to insert each allocation
      realloc: do not copy if allocation failed
      internal_memalign: do not assume real_malloc succeeds
      ensure ENOMEM is preserved in errno when appropriate
      memalign: check alignment on all public functions
      reduce stack usage from file names
      resolve real_malloc earlier for C++ programs
      allow analyzing live allocations via Mwrap[location]
      alias Mwrap.clear to Mwrap.reset
      implement accessors for SourceLocation
      mwrap_aref: quiet -Wshorten-64-to-32 warning
      fixes for FreeBSD 11.1...
      use memrchr to extract address under glibc
      do not track allocations for constructor and Init_
      disable memalign tracking by default
      support Mwrap.quiet to temporarily disable allocation tracking
      mwrap_rack: Rack app to track live allocations

 ext/mwrap/extconf.rb |  15 +
 ext/mwrap/mwrap.c    | 792 +++++++++++++++++++++++++++++++++++++++++++--------
 lib/mwrap_rack.rb    | 105 +++++++
 test/test_mwrap.rb   | 113 ++++++++
 4 files changed, 901 insertions(+), 124 deletions(-)
 create mode 100644 lib/mwrap_rack.rb



^ permalink raw reply	[relevance 5%]

* [PATCH] bin/mwrap: support LISTEN_FDS env from systemd
@ 2018-07-16  9:30  7% Eric Wong
  0 siblings, 0 replies; 4+ results
From: Eric Wong @ 2018-07-16  9:30 UTC (permalink / raw)
  To: mwrap-public

OK, Ruby blindly closing file descriptors it doesn't know about
is really getting on my nerves, now.
---
 bin/mwrap | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/bin/mwrap b/bin/mwrap
index 964fdf8..9f67dab 100755
--- a/bin/mwrap
+++ b/bin/mwrap
@@ -26,4 +26,11 @@ if ENV['MWRAP'] =~ /dump_fd:(\d+)/
     opts[dump_fd] = dump_io
   end
 end
+
+# allow inheriting FDs from systemd
+n = ENV['LISTEN_FDS']
+if n && ENV['LISTEN_PID'].to_i == $$
+  n = 3 + n.to_i
+  (3...n).each { |fd| opts[fd] = IO.new(fd) }
+end
 exec *ARGV, opts
-- 
EW


^ permalink raw reply related	[relevance 7%]

Results 1-4 of 4 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2018-07-02 12:00     [ANN] mwrap - LD_PRELOAD malloc wrapper + line stats for Ruby Eric Wong
2018-07-03  0:11     ` Sam Saffron
2018-07-03  7:48       ` Eric Wong
2018-07-16 21:48  4%     ` Eric Wong
2018-07-16  9:30  7% [PATCH] bin/mwrap: support LISTEN_FDS env from systemd Eric Wong
2018-07-16 21:19  5% [PATCH 0/19] the heavy version of mwrap Eric Wong
2018-07-20  9:25  4% [PATCH] mwrap 2.0.0 mwrap - LD_PRELOAD malloc wrapper for Ruby Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mwrap.git/

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 read-only IMAP folder(s) and NNTP newsgroup(s).