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: |
* [ANN] mwrap 2.1.0 mwrap - LD_PRELOAD malloc wrapper for Ruby
@ 2018-08-11  4:31  7% Eric Wong
  0 siblings, 0 replies; 3+ results
From: Eric Wong @ 2018-08-11  4:31 UTC (permalink / raw)
  To: ruby-talk, mwrap-public

Changes:

    mwrap 2.1.0 - heap_page_body struct tracking

    This release enables tracking of memalign allocations for
    "struct heap_page_body" in the Ruby GC.  This can be useful
    for tracking deathspans (time between free and re-allocation)
    of heap page bodies which can cause fragmentation in some
    malloc implementations, including glibc.

    The documentation for it is available at:

      https://80x24.org/mwrap/Mwrap/HeapPageBody.html

    And a live demo runs at:

      https://80x24.org/MWRAP/heap_pages

    This release also includes global counters for
     Mwrap.total_bytes_allocated and Mwrap.total_bytes_freed

    10 changes since v2.0.0 (2018-07-20):

          add olddoc.yml to generate links in page footers
          add .olddoc.yml to MANIFEST
          gemspec: use "git describe" output for prereleases
          add global counters for total bytes allocated/freed
          keep stats for memalign-ed heap_page_body in Ruby
          remove "memalign:" MWRAP option
          allow dump_heap: mask via MWRAP env
          tweak hpb stats destructor output
          struct acc: use 64-bit counters
          doc: 2.1 pre-release updates

About:

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.

Mailing list and archives:

	https://80x24.org/mwrap-public/
	nntp://80x24.org/inbox.comp.lang.ruby.mwrap
	mailto:mwrap-public@80x24.org (no HTML mail, please)

Note: I might not be able answer questions about this for a few days.

git clone https://80x24.org/mwrap.git
homepage + rdoc: https://80x24.org/mwrap/

^ permalink raw reply	[relevance 7%]

* [PATCH v2] remove "memalign:" MWRAP option
  2018-08-10  7:08  6% [PATCH] remove "memalign:" MWRAP option Eric Wong
@ 2018-08-10  7:10  6% ` Eric Wong
  0 siblings, 0 replies; 3+ results
From: Eric Wong @ 2018-08-10  7:10 UTC (permalink / raw)
  To: mwrap-public

Since we learned to treat heap_page_body allocations specially,
we can also keep track of rare memalign allocations done outside
of the Ruby GC this way.
---
 Cleaned up compiler warnings.  Note to self: read compiler warnings
 before spewing

 ext/mwrap/mwrap.c | 18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)

diff --git a/ext/mwrap/mwrap.c b/ext/mwrap/mwrap.c
index 29cfc11..986ca70 100644
--- a/ext/mwrap/mwrap.c
+++ b/ext/mwrap/mwrap.c
@@ -23,7 +23,6 @@
 #include "jhash.h"
 
 static ID id_uminus;
-static unsigned int track_memalign;
 const char *rb_source_location_cstr(int *line); /* requires 2.6.0dev */
 extern int __attribute__((weak)) ruby_thread_has_gvl_p(void);
 extern void * __attribute__((weak)) ruby_current_execution_context_ptr;
@@ -107,7 +106,6 @@ lfht_new(void)
 __attribute__((constructor)) static void resolve_malloc(void)
 {
 	int err;
-	const char *opt;
 	++locating;
 
 #ifdef __FreeBSD__
@@ -151,11 +149,6 @@ __attribute__((constructor)) static void resolve_malloc(void)
 	if (err)
 		fprintf(stderr, "pthread_atfork failed: %s\n", strerror(err));
 	page_size = sysconf(_SC_PAGESIZE);
-	opt = getenv("MWRAP");
-	if (opt && (opt = strstr(opt, "memalign:"))) {
-		if (!sscanf(opt, "memalign:%u", &track_memalign))
-			fprintf(stderr, "not an unsigned int: %s\n", opt);
-	}
 	--locating;
 }
 
@@ -575,10 +568,8 @@ internal_memalign(void **pp, size_t alignment, size_t size, uintptr_t caller)
 	if (alignment == HEAP_PAGE_ALIGN && size == HEAP_PAGE_SIZE) {
 		if (has_ec_p()) generation = rb_gc_count();
 		l = IS_HEAP_PAGE_BODY;
-	} else if (track_memalign) {
-		l = update_stats_rcu_lock(size, caller);
 	} else {
-		l = 0;
+		l = update_stats_rcu_lock(size, caller);
 	}
 
 	if (l == IS_HEAP_PAGE_BODY) {
@@ -1285,16 +1276,9 @@ static VALUE hpb_stat(int argc, VALUE *argv, VALUE hpb)
  * * dump_fd: a writable FD to dump to
  * * dump_path: a path to dump to, the file is opened in O_APPEND mode
  * * dump_min: the minimum allocation size (total) to dump
- * * memalign: use `1' to enable tracking the memalign family
  *
  * If both `dump_fd' and `dump_path' are specified, dump_path takes
  * precedence.
- *
- * Tracking the memalign family of functions is misleading for Ruby
- * applications, as heap page allocations can happen anywhere a
- * Ruby object is allocated, even in the coldest code paths.
- * Furthermore, it is rarely-used outside of the Ruby object allocator.
- * Thus tracking memalign functions is disabled by default.
  */
 void Init_mwrap(void)
 {
-- 
EW


^ permalink raw reply related	[relevance 6%]

* [PATCH] remove "memalign:" MWRAP option
@ 2018-08-10  7:08  6% Eric Wong
  2018-08-10  7:10  6% ` [PATCH v2] " Eric Wong
  0 siblings, 1 reply; 3+ results
From: Eric Wong @ 2018-08-10  7:08 UTC (permalink / raw)
  To: mwrap-public

Since we learned to treat heap_page_body allocations specially,
we can also keep track of rare memalign allocations done outside
of the Ruby GC this way.
---
 ext/mwrap/mwrap.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/ext/mwrap/mwrap.c b/ext/mwrap/mwrap.c
index 29cfc11..c44ea89 100644
--- a/ext/mwrap/mwrap.c
+++ b/ext/mwrap/mwrap.c
@@ -23,7 +23,6 @@
 #include "jhash.h"
 
 static ID id_uminus;
-static unsigned int track_memalign;
 const char *rb_source_location_cstr(int *line); /* requires 2.6.0dev */
 extern int __attribute__((weak)) ruby_thread_has_gvl_p(void);
 extern void * __attribute__((weak)) ruby_current_execution_context_ptr;
@@ -152,10 +151,6 @@ __attribute__((constructor)) static void resolve_malloc(void)
 		fprintf(stderr, "pthread_atfork failed: %s\n", strerror(err));
 	page_size = sysconf(_SC_PAGESIZE);
 	opt = getenv("MWRAP");
-	if (opt && (opt = strstr(opt, "memalign:"))) {
-		if (!sscanf(opt, "memalign:%u", &track_memalign))
-			fprintf(stderr, "not an unsigned int: %s\n", opt);
-	}
 	--locating;
 }
 
@@ -575,10 +570,8 @@ internal_memalign(void **pp, size_t alignment, size_t size, uintptr_t caller)
 	if (alignment == HEAP_PAGE_ALIGN && size == HEAP_PAGE_SIZE) {
 		if (has_ec_p()) generation = rb_gc_count();
 		l = IS_HEAP_PAGE_BODY;
-	} else if (track_memalign) {
-		l = update_stats_rcu_lock(size, caller);
 	} else {
-		l = 0;
+		l = update_stats_rcu_lock(size, caller);
 	}
 
 	if (l == IS_HEAP_PAGE_BODY) {
@@ -1285,16 +1278,9 @@ static VALUE hpb_stat(int argc, VALUE *argv, VALUE hpb)
  * * dump_fd: a writable FD to dump to
  * * dump_path: a path to dump to, the file is opened in O_APPEND mode
  * * dump_min: the minimum allocation size (total) to dump
- * * memalign: use `1' to enable tracking the memalign family
  *
  * If both `dump_fd' and `dump_path' are specified, dump_path takes
  * precedence.
- *
- * Tracking the memalign family of functions is misleading for Ruby
- * applications, as heap page allocations can happen anywhere a
- * Ruby object is allocated, even in the coldest code paths.
- * Furthermore, it is rarely-used outside of the Ruby object allocator.
- * Thus tracking memalign functions is disabled by default.
  */
 void Init_mwrap(void)
 {
-- 
EW


^ permalink raw reply related	[relevance 6%]

Results 1-3 of 3 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2018-08-10  7:08  6% [PATCH] remove "memalign:" MWRAP option Eric Wong
2018-08-10  7:10  6% ` [PATCH v2] " Eric Wong
2018-08-11  4:31  7% [ANN] mwrap 2.1.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).