From 984745b074c186f6058730087a4fc8156240ec76 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Wed, 31 Jul 2019 22:29:13 -0400 Subject: nonmoving: Upper-bound time we hold SM_MUTEX for during sweep --- rts/sm/NonMovingSweep.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'rts/sm') diff --git a/rts/sm/NonMovingSweep.c b/rts/sm/NonMovingSweep.c index 31a9041880..cf5fcd70d7 100644 --- a/rts/sm/NonMovingSweep.c +++ b/rts/sm/NonMovingSweep.c @@ -293,9 +293,33 @@ void nonmovingSweepMutLists() } } +/* A variant of freeChain_lock that will only hold the lock for at most max_dur + * freed blocks to ensure that we don't starve other lock users (e.g. the + * mutator). + */ +static void freeChain_lock_max(bdescr *bd, int max_dur) +{ + ACQUIRE_SM_LOCK; + bdescr *next_bd; + int i = 0; + while (bd != NULL) { + next_bd = bd->link; + freeGroup(bd); + bd = next_bd; + if (i == max_dur) { + RELEASE_SM_LOCK; + yieldThread(); + ACQUIRE_SM_LOCK; + i = 0; + } + i++; + } + RELEASE_SM_LOCK; +} + void nonmovingSweepLargeObjects() { - freeChain_lock(nonmoving_large_objects); + freeChain_lock_max(nonmoving_large_objects, 10000); nonmoving_large_objects = nonmoving_marked_large_objects; n_nonmoving_large_blocks = n_nonmoving_marked_large_blocks; nonmoving_marked_large_objects = NULL; -- cgit v1.2.1