diff --git a/ghc/rts/BlockAlloc.h b/ghc/rts/BlockAlloc.h
index 1ef18d4dc34aa7ad9ece96926c3eac9431886a1f..a121917c212ae48937a9a5257bad4d4733784cef 100644
--- a/ghc/rts/BlockAlloc.h
+++ b/ghc/rts/BlockAlloc.h
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: BlockAlloc.h,v 1.3 1999/01/13 17:25:38 simonm Exp $
+ * $Id: BlockAlloc.h,v 1.4 1999/02/03 16:32:47 simonm Exp $
  *
  * Block Allocator Interface
  *
@@ -32,6 +32,23 @@ static inline bdescr *Bdescr(StgPtr p)
      );
 }
 
+/* Round a value to megablocks --------------------------------------------- */
+
+#define WORDS_PER_MBLOCK  (BLOCKS_PER_MBLOCK * BLOCK_SIZE_W)
+
+static inline nat
+round_to_mblocks(nat words)
+{
+  if (words > WORDS_PER_MBLOCK) {
+    if ((words % WORDS_PER_MBLOCK) < (WORDS_PER_MBLOCK / 2)) {
+      words = (words / WORDS_PER_MBLOCK) * WORDS_PER_MBLOCK;
+    } else {
+      words = ((words / WORDS_PER_MBLOCK) + 1) * WORDS_PER_MBLOCK;
+    }
+  }
+  return words;
+}
+
 /* Debugging  -------------------------------------------------------------- */
 
 #ifdef DEBUG
diff --git a/ghc/rts/Schedule.c b/ghc/rts/Schedule.c
index f7de47a2d7d3c43c8850f1a274831b85958571c2..48f9e39a863a179a057db006a8ac5ee053f3b2ad 100644
--- a/ghc/rts/Schedule.c
+++ b/ghc/rts/Schedule.c
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: Schedule.c,v 1.7 1999/02/02 14:21:31 simonm Exp $
+ * $Id: Schedule.c,v 1.8 1999/02/03 16:32:47 simonm Exp $
  *
  * Scheduler
  *
@@ -107,7 +107,8 @@ initThread(StgTSO *tso, nat stack_size)
 
   tso->splim        = (P_)&(tso->stack) + RESERVED_STACK_WORDS;
   tso->stack_size   = stack_size;
-  tso->max_stack_size = RtsFlags.GcFlags.maxStkSize - TSO_STRUCT_SIZEW;
+  tso->max_stack_size = round_to_mblocks(RtsFlags.GcFlags.maxStkSize) 
+                              - TSO_STRUCT_SIZEW;
   tso->sp           = (P_)&(tso->stack) + stack_size;
 
 #ifdef PROFILING
@@ -676,6 +677,7 @@ threadStackOverflow(StgTSO *tso)
   new_stack_size = stg_min(tso->stack_size * 2, tso->max_stack_size);
   new_tso_size   = (nat)BLOCK_ROUND_UP(new_stack_size * sizeof(W_) + 
 				       TSO_STRUCT_SIZE)/sizeof(W_);
+  new_tso_size = round_to_mblocks(new_tso_size);  /* Be MBLOCK-friendly */
   new_stack_size = new_tso_size - TSO_STRUCT_SIZEW;
 
   IF_DEBUG(scheduler, fprintf(stderr,"increasing stack size from %d words to %d.\n", tso->stack_size, new_stack_size));