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  6% 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 6%]

* [SQUASH] Re: [PATCH] struct acc: use 64-bit counters
  2018-08-11  3:53  6% [PATCH] struct acc: use 64-bit counters Eric Wong
@ 2018-08-11  4:00  7% ` Eric Wong
  0 siblings, 0 replies; 3+ results
From: Eric Wong @ 2018-08-11  4:00 UTC (permalink / raw)
  To: mwrap-public

diff --git a/ext/mwrap/mwrap.c b/ext/mwrap/mwrap.c
index 5174127..cbda436 100644
--- a/ext/mwrap/mwrap.c
+++ b/ext/mwrap/mwrap.c
@@ -1356,12 +1356,12 @@ static void dump_hpb(FILE *fp, unsigned flags)
 {
 	if (flags & DUMP_HPB_STATS) {
 		fprintf(fp,
-			"lifespan_max: %zu\n"
-			"lifespan_min:%s%zu\n"
+			"lifespan_max: %"PRId64"\n"
+			"lifespan_min:%s%"PRId64"\n"
 			"lifespan_mean: %0.3f\n"
 			"lifespan_stddev: %0.3f\n"
-			"deathspan_max: %zu\n"
-			"deathspan_min:%s%zu\n"
+			"deathspan_max: %"PRId64"\n"
+			"deathspan_min:%s%"PRId64"\n"
 			"deathspan_mean: %0.3f\n"
 			"deathspan_stddev: %0.3f\n"
 			"gc_count: %zu\n",

^ permalink raw reply related	[relevance 7%]

* [PATCH] struct acc: use 64-bit counters
@ 2018-08-11  3:53  6% Eric Wong
  2018-08-11  4:00  7% ` [SQUASH] " Eric Wong
  0 siblings, 1 reply; 3+ results
From: Eric Wong @ 2018-08-11  3:53 UTC (permalink / raw)
  To: mwrap-public; +Cc: Eric Wong

Since there's no hope of atomicity here anyways, use 64-bit
counters.
---
 ext/mwrap/mwrap.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/ext/mwrap/mwrap.c b/ext/mwrap/mwrap.c
index b60c21d..5174127 100644
--- a/ext/mwrap/mwrap.c
+++ b/ext/mwrap/mwrap.c
@@ -218,14 +218,14 @@ static int has_ec_p(void)
 }
 
 struct acc {
-	size_t nr;
-	size_t min;
-	size_t max;
+	uint64_t nr;
+	int64_t min;
+	int64_t max;
 	double m2;
 	double mean;
 };
 
-#define ACC_INIT(name) { .nr=0, .min=SIZE_MAX, .max=0, .m2=0, .mean=0 }
+#define ACC_INIT(name) { .nr=0, .min=INT64_MAX, .max=-1, .m2=0, .mean=0 }
 
 /* for tracking 16K-aligned heap page bodies (protected by GVL) */
 struct {
@@ -314,29 +314,35 @@ static void
 acc_add(struct acc *acc, size_t val)
 {
 	double delta = val - acc->mean;
-	size_t nr = ++acc->nr;
+	uint64_t nr = ++acc->nr;
 
-	/* 32-bit overflow, ignore accuracy, just don't divide-by-zero */
+	/* just don't divide-by-zero if we ever hit this (unlikely :P) */
 	if (nr)
 		acc->mean += delta / nr;
 
 	acc->m2 += delta * (val - acc->mean);
-	if (val < acc->min)
-		acc->min = val;
-	if (val > acc->max)
-		acc->max = val;
+	if ((int64_t)val < acc->min)
+		acc->min = (int64_t)val;
+	if ((int64_t)val > acc->max)
+		acc->max = (int64_t)val;
 }
 
+#if SIZEOF_LONG == 8
+# define INT64toNUM(x) LONG2NUM((long)x)
+#elif defined(HAVE_LONG_LONG) && SIZEOF_LONG_LONG == 8
+# define INT64toNUM(x) LL2NUM((LONG_LONG)x)
+#endif
+
 static VALUE
 acc_max(const struct acc *acc)
 {
-	return acc->max ? SIZET2NUM(acc->max) : DBL2NUM(HUGE_VAL);
+	return INT64toNUM(acc->max);
 }
 
 static VALUE
 acc_min(const struct acc *acc)
 {
-	return acc->min == SIZE_MAX ? DBL2NUM(HUGE_VAL) : SIZET2NUM(acc->min);
+	return acc->min == INT64_MAX ? INT2FIX(-1) : INT64toNUM(acc->min);
 }
 
 static VALUE
@@ -1360,12 +1366,12 @@ static void dump_hpb(FILE *fp, unsigned flags)
 			"deathspan_stddev: %0.3f\n"
 			"gc_count: %zu\n",
 			hpb_stats.alive.max,
-			hpb_stats.alive.min == SIZE_MAX ? " -" : " ",
+			hpb_stats.alive.min == INT64_MAX ? " -" : " ",
 			hpb_stats.alive.min,
 			hpb_stats.alive.mean,
 			acc_stddev_dbl(&hpb_stats.alive),
 			hpb_stats.reborn.max,
-			hpb_stats.reborn.min == SIZE_MAX ? " -" : " ",
+			hpb_stats.reborn.min == INT64_MAX ? " -" : " ",
 			hpb_stats.reborn.min,
 			hpb_stats.reborn.mean,
 			acc_stddev_dbl(&hpb_stats.reborn),
-- 
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-11  3:53  6% [PATCH] struct acc: use 64-bit counters Eric Wong
2018-08-11  4:00  7% ` [SQUASH] " Eric Wong
2018-08-11  4:31  6% [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).