From ef17ba047bcfe96f49967f05d3af0f78bca454a3 Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Fri, 26 Feb 2016 18:58:34 +0000 Subject: [PATCH] Purge spare committed memory when growing the arena fails due to the commit limit. Copied from Perforce Change: 189362 ServerID: perforce.ravenbrook.com --- mps/code/policy.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mps/code/policy.c b/mps/code/policy.c index dbcb33e278f..f90c4c485f5 100644 --- a/mps/code/policy.c +++ b/mps/code/policy.c @@ -77,6 +77,14 @@ Res PolicyAlloc(Tract *tractReturn, Arena arena, LocusPref pref, /* Plan C: Extend the arena, then try A and B again. */ if (moreZones != ZoneSetEMPTY) { res = arena->class->grow(arena, pref, size); + /* If we can't extent because we hit the commit limit, try purging + some spare committed memory and try again.*/ + /* TODO: This would be a good time to *remap* VM instead of + returning it to the OS. */ + if (res == ResCOMMIT_LIMIT) { + if (arena->class->purgeSpare(arena, size) >= size) + res = arena->class->grow(arena, pref, size); + } if (res != ResOK) return res; if (zones != ZoneSetEMPTY) {