summaryrefslogtreecommitdiff
path: root/rts/sm
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2013-02-14 10:06:44 +0000
committerSimon Marlow <marlowsd@gmail.com>2013-02-14 10:06:53 +0000
commit65a0e1eb88fb48d085f8da498a7acc2fd345c2a8 (patch)
tree3d5c6489c1b51d085a9f8b313aae5daa3330bcf2 /rts/sm
parente5085db5d16f904f9307445fbafc206283f630c7 (diff)
downloadhaskell-65a0e1eb88fb48d085f8da498a7acc2fd345c2a8.tar.gz
Simplify the allocation stats accounting
We were doing it in two different ways and asserting that the results were the same. In most cases they were, but I found one case where they weren't: the GC itself allocates some memory for running finalizers, and this memory was accounted for one way but not the other. It was simpler to remove the old way of counting allocation that to try to fix it up, so I did that.
Diffstat (limited to 'rts/sm')
-rw-r--r--rts/sm/GC.c33
-rw-r--r--rts/sm/GCThread.h1
-rw-r--r--rts/sm/Storage.c32
-rw-r--r--rts/sm/Storage.h4
4 files changed, 20 insertions, 50 deletions
diff --git a/rts/sm/GC.c b/rts/sm/GC.c
index f4a479ec63..ea0e4030bd 100644
--- a/rts/sm/GC.c
+++ b/rts/sm/GC.c
@@ -156,7 +156,7 @@ static StgWord dec_running (void);
static void wakeup_gc_threads (nat me);
static void shutdown_gc_threads (nat me);
static void collect_gct_blocks (void);
-static StgWord collect_pinned_object_blocks (void);
+static void collect_pinned_object_blocks (void);
#if 0 && defined(DEBUG)
static void gcCAFs (void);
@@ -186,7 +186,7 @@ GarbageCollect (nat collect_gen,
{
bdescr *bd;
generation *gen;
- StgWord live_blocks, live_words, allocated, par_max_copied, par_tot_copied;
+ StgWord live_blocks, live_words, par_max_copied, par_tot_copied;
#if defined(THREADED_RTS)
gc_thread *saved_gct;
#endif
@@ -243,11 +243,6 @@ GarbageCollect (nat collect_gen,
}
#endif
- /* Approximate how much we allocated.
- * Todo: only when generating stats?
- */
- allocated = countLargeAllocated(); /* don't count the nursery yet */
-
/* Figure out which generation to collect
*/
N = collect_gen;
@@ -304,7 +299,7 @@ GarbageCollect (nat collect_gen,
// gather blocks allocated using allocatePinned() from each capability
// and put them on the g0->large_object list.
- allocated += collect_pinned_object_blocks();
+ collect_pinned_object_blocks();
// Initialise all the generations/steps that we're collecting.
for (g = 0; g <= N; g++) {
@@ -419,7 +414,7 @@ GarbageCollect (nat collect_gen,
}
if (!DEBUG_IS_ON && n_gc_threads != 1) {
- gct->allocated = clearNursery(cap);
+ clearNursery(cap);
}
shutdown_gc_threads(gct->thread_index);
@@ -659,17 +654,14 @@ GarbageCollect (nat collect_gen,
// Reset the nursery: make the blocks empty
if (DEBUG_IS_ON || n_gc_threads == 1) {
for (n = 0; n < n_capabilities; n++) {
- allocated += clearNursery(&capabilities[n]);
+ clearNursery(&capabilities[n]);
}
} else {
// When doing parallel GC, clearNursery() is called by the
- // worker threads, and the value returned is stored in
- // gct->allocated.
+ // worker threads
for (n = 0; n < n_capabilities; n++) {
if (gc_threads[n]->idle) {
- allocated += clearNursery(&capabilities[n]);
- } else {
- allocated += gc_threads[n]->allocated;
+ clearNursery(&capabilities[n]);
}
}
}
@@ -781,7 +773,7 @@ GarbageCollect (nat collect_gen,
#endif
// ok, GC over: tell the stats department what happened.
- stat_endGC(cap, gct, allocated, live_words, copied,
+ stat_endGC(cap, gct, live_words, copied,
live_blocks * BLOCK_SIZE_W - live_words /* slop */,
N, n_gc_threads, par_max_copied, par_tot_copied);
@@ -1094,7 +1086,7 @@ gcWorkerThread (Capability *cap)
scavenge_until_all_done();
if (!DEBUG_IS_ON) {
- gct->allocated = clearNursery(cap);
+ clearNursery(cap);
}
#ifdef THREADED_RTS
@@ -1439,17 +1431,15 @@ collect_gct_blocks (void)
purposes.
-------------------------------------------------------------------------- */
-static StgWord
+static void
collect_pinned_object_blocks (void)
{
nat n;
bdescr *bd, *prev;
- StgWord allocated = 0;
for (n = 0; n < n_capabilities; n++) {
prev = NULL;
for (bd = capabilities[n].pinned_object_blocks; bd != NULL; bd = bd->link) {
- allocated += bd->free - bd->start;
prev = bd;
}
if (prev != NULL) {
@@ -1461,8 +1451,6 @@ collect_pinned_object_blocks (void)
capabilities[n].pinned_object_blocks = 0;
}
}
-
- return allocated;
}
/* -----------------------------------------------------------------------------
@@ -1480,7 +1468,6 @@ init_gc_thread (gc_thread *t)
t->failed_to_evac = rtsFalse;
t->eager_promotion = rtsTrue;
t->thunk_selector_depth = 0;
- t->allocated = 0;
t->copied = 0;
t->scanned = 0;
t->any_work = 0;
diff --git a/rts/sm/GCThread.h b/rts/sm/GCThread.h
index 59327bc20b..7aacb4eb51 100644
--- a/rts/sm/GCThread.h
+++ b/rts/sm/GCThread.h
@@ -176,7 +176,6 @@ typedef struct gc_thread_ {
// -------------------
// stats
- W_ allocated; // result of clearNursery()
W_ copied;
W_ scanned;
W_ any_work;
diff --git a/rts/sm/Storage.c b/rts/sm/Storage.c
index 518ae0d0c8..f14b3b0c9d 100644
--- a/rts/sm/Storage.c
+++ b/rts/sm/Storage.c
@@ -240,8 +240,8 @@ void storageAddCapabilities (nat from, nat to)
void
exitStorage (void)
{
- W_ allocated = updateNurseriesStats();
- stat_exit(allocated);
+ updateNurseriesStats();
+ stat_exit();
}
void
@@ -508,22 +508,18 @@ allocNurseries (nat from, nat to)
assignNurseriesToCapabilities(from, to);
}
-W_
+void
clearNursery (Capability *cap)
{
bdescr *bd;
- W_ allocated = 0;
for (bd = nurseries[cap->no].blocks; bd; bd = bd->link) {
- allocated += (W_)(bd->free - bd->start);
cap->total_allocated += (W_)(bd->free - bd->start);
bd->free = bd->start;
ASSERT(bd->gen_no == 0);
ASSERT(bd->gen == g0);
IF_DEBUG(sanity,memset(bd->start, 0xaa, BLOCK_SIZE));
}
-
- return allocated;
}
void
@@ -771,6 +767,7 @@ allocatePinned (Capability *cap, W_ n)
// g0->large_objects.
if (bd != NULL) {
dbl_link_onto(bd, &cap->pinned_object_blocks);
+ // add it to the allocation stats when the block is full
cap->total_allocated += bd->free - bd->start;
}
@@ -927,32 +924,19 @@ dirty_MVAR(StgRegTable *reg, StgClosure *p)
* updateNurseriesStats()
*
* Update the per-cap total_allocated numbers with an approximation of
- * the amount of memory used in each cap's nursery. Also return the
- * total across all caps.
- *
+ * the amount of memory used in each cap's nursery.
+ *
* Since this update is also performed by clearNurseries() then we only
* need this function for the final stats when the RTS is shutting down.
* -------------------------------------------------------------------------- */
-W_
-updateNurseriesStats (void)
+void updateNurseriesStats (void)
{
- W_ allocated = 0;
nat i;
for (i = 0; i < n_capabilities; i++) {
- int cap_allocated = countOccupied(nurseries[i].blocks);
- capabilities[i].total_allocated += cap_allocated;
- allocated += cap_allocated;
+ capabilities[i].total_allocated += countOccupied(nurseries[i].blocks);
}
-
- return allocated;
-}
-
-W_
-countLargeAllocated (void)
-{
- return g0->n_new_large_words;
}
W_ countOccupied (bdescr *bd)
diff --git a/rts/sm/Storage.h b/rts/sm/Storage.h
index 65f5242c31..c4f8709847 100644
--- a/rts/sm/Storage.h
+++ b/rts/sm/Storage.h
@@ -82,7 +82,7 @@ void dirty_TVAR(Capability *cap, StgTVar *p);
extern nursery *nurseries;
void resetNurseries ( void );
-W_ clearNursery ( Capability *cap );
+void clearNursery ( Capability *cap );
void resizeNurseries ( W_ blocks );
void resizeNurseriesFixed ( W_ blocks );
W_ countNurseryBlocks ( void );
@@ -91,7 +91,7 @@ W_ countNurseryBlocks ( void );
Stats 'n' DEBUG stuff
-------------------------------------------------------------------------- */
-W_ updateNurseriesStats (void);
+void updateNurseriesStats (void);
W_ countLargeAllocated (void);
W_ countOccupied (bdescr *bd);
W_ calcNeeded (rtsBool force_major, W_ *blocks_needed);