memory allocator hotfix: do not allocate tremendous amounts of memory

This commit is contained in:
Andreas Rumpf
2017-01-13 12:07:19 +01:00
parent e142f4c371
commit 9753782f96
2 changed files with 18 additions and 12 deletions

View File

@@ -271,9 +271,13 @@ proc mainCommand*(graph: ModuleGraph; cache: IdentCache) =
if msgs.gErrorCounter == 0 and
gCmd notin {cmdInterpret, cmdRun, cmdDump}:
when declared(system.getMaxMem):
let usedMem = formatSize(getMaxMem()) & " peekmem"
else:
let usedMem = formatSize(getTotalMem())
rawMessage(hintSuccessX, [$gLinesCompiled,
formatFloat(epochTime() - gLastCmdTime, ffDecimal, 3),
formatSize(getTotalMem()),
usedMem,
if condSyms.isDefined("release"): "Release Build"
else: "Debug Build"])

View File

@@ -275,12 +275,21 @@ proc pageAddr(p: pointer): PChunk {.inline.} =
result = cast[PChunk](cast[ByteAddress](p) and not PageMask)
#sysAssert(Contains(allocator.chunkStarts, pageIndex(result)))
proc writeFreeList(a: MemRegion) =
var it = a.freeChunksList
c_fprintf(stdout, "freeChunksList: %p\n", it)
while it != nil:
c_fprintf(stdout, "it: %p, next: %p, prev: %p, size: %ld\n",
it, it.next, it.prev, it.size)
it = it.next
proc requestOsChunks(a: var MemRegion, size: int): PBigChunk =
when not defined(emscripten):
if not a.blockChunkSizeIncrease:
a.nextChunkSize =
if a.currMem < 64 * 1024: PageSize*4
else: a.nextChunkSize*2
if a.currMem < 64 * 1024:
a.nextChunkSize = PageSize*4
else:
a.nextChunkSize = min(roundup(a.currMem shr 2, PageSize), a.nextChunkSize * 2)
var size = size
if size > a.nextChunkSize:
@@ -344,14 +353,6 @@ proc contains[T](list, x: T): bool =
if it == x: return true
it = it.next
proc writeFreeList(a: MemRegion) =
var it = a.freeChunksList
c_fprintf(stdout, "freeChunksList: %p\n", it)
while it != nil:
c_fprintf(stdout, "it: %p, next: %p, prev: %p\n",
it, it.next, it.prev)
it = it.next
proc listAdd[T](head: var T, c: T) {.inline.} =
sysAssert(c notin head, "listAdd 1")
sysAssert c.prev == nil, "listAdd 2"
@@ -756,6 +757,7 @@ template instantiateForRegion(allocator: expr) =
proc getTotalMem(): int = return allocator.currMem
proc getOccupiedMem(): int = return getTotalMem() - getFreeMem()
proc getMaxMem*(): int = return getMaxMem(allocator)
# -------------------- shared heap region ----------------------------------
when hasThreadSupport: