From: Duncan Coutts Date: Fri, 3 Feb 2012 12:57:19 +0000 (+0000) Subject: Calculate the total memory allocated on a per-capability basis X-Git-Tag: ghc-7.6.1-release~294^2^2~12 X-Git-Url: http://git.haskell.org/ghc.git/commitdiff_plain/8536f09c2f310a95297b339de6084f77cc4044c1 Calculate the total memory allocated on a per-capability basis In addition to the existing global method. For now we just do it both ways and assert they give the same grand total. At some stage we can simplify the global method to just take the sum of the per-cap counters. --- diff --git a/rts/Capability.c b/rts/Capability.c index d1184db..564953b 100644 --- a/rts/Capability.c +++ b/rts/Capability.c @@ -250,6 +250,7 @@ initCapability( Capability *cap, nat i ) cap->spark_stats.gcd = 0; cap->spark_stats.fizzled = 0; #endif + cap->total_allocated = 0; cap->f.stgEagerBlackholeInfo = (W_)&__stg_EAGER_BLACKHOLE_info; cap->f.stgGCEnter1 = (StgFunPtr)__stg_gc_enter_1; diff --git a/rts/Capability.h b/rts/Capability.h index 64273c7..1a2e7fd 100644 --- a/rts/Capability.h +++ b/rts/Capability.h @@ -122,6 +122,8 @@ struct Capability_ { // Stats on spark creation/conversion SparkCounters spark_stats; #endif + // Total words allocated by this cap since rts start + lnat total_allocated; // Per-capability STM-related data StgTVarWatchQueue *free_tvar_watch_queues; diff --git a/rts/Stats.c b/rts/Stats.c index 2c7c35d..76444b3 100644 --- a/rts/Stats.c +++ b/rts/Stats.c @@ -375,6 +375,22 @@ stat_endGC (gc_thread *gct, GC_par_max_copied += (StgWord64) max_copied; GC_par_avg_copied += (StgWord64) avg_copied; GC_tot_cpu += gc_cpu; + + /* For the moment we calculate both per-HEC and total allocation. + * There is thus redundancy here, but for the moment we will calculate + * it both the old and new way and assert they're the same. + * When we're sure it's working OK then we can simplify things. + * TODO: simplify calcAllocated and clearNurseries so they don't have + * to calculate the total + */ + { + lnat tot_alloc = 0; + lnat n; + for (n = 0; n < n_capabilities; n++) { + tot_alloc += capabilities[n].total_allocated; + } + ASSERT(GC_tot_alloc == tot_alloc); + } if (gen == RtsFlags.GcFlags.generations-1) { /* major GC? */ if (live > max_residency) { diff --git a/rts/sm/Storage.c b/rts/sm/Storage.c index 0f5587a..59ad231 100644 --- a/rts/sm/Storage.c +++ b/rts/sm/Storage.c @@ -497,7 +497,8 @@ clearNurseries (void) for (i = 0; i < n_capabilities; i++) { for (bd = nurseries[i].blocks; bd; bd = bd->link) { - allocated += (lnat)(bd->free - bd->start); + allocated += (lnat)(bd->free - bd->start); + capabilities[i].total_allocated += (lnat)(bd->free - bd->start); bd->free = bd->start; ASSERT(bd->gen_no == 0); ASSERT(bd->gen == g0); @@ -656,6 +657,7 @@ allocate (Capability *cap, lnat n) initBdescr(bd, g0, g0); bd->flags = BF_LARGE; bd->free = bd->start + n; + cap->total_allocated += n; return bd->start; }