memory allocator hotfix: do not allocate tremendous amounts of memory
This commit is contained in:
parent
e142f4c371
commit
9753782f96
2 changed files with 18 additions and 12 deletions
|
|
@ -271,9 +271,13 @@ proc mainCommand*(graph: ModuleGraph; cache: IdentCache) =
|
||||||
|
|
||||||
if msgs.gErrorCounter == 0 and
|
if msgs.gErrorCounter == 0 and
|
||||||
gCmd notin {cmdInterpret, cmdRun, cmdDump}:
|
gCmd notin {cmdInterpret, cmdRun, cmdDump}:
|
||||||
|
when declared(system.getMaxMem):
|
||||||
|
let usedMem = formatSize(getMaxMem()) & " peekmem"
|
||||||
|
else:
|
||||||
|
let usedMem = formatSize(getTotalMem())
|
||||||
rawMessage(hintSuccessX, [$gLinesCompiled,
|
rawMessage(hintSuccessX, [$gLinesCompiled,
|
||||||
formatFloat(epochTime() - gLastCmdTime, ffDecimal, 3),
|
formatFloat(epochTime() - gLastCmdTime, ffDecimal, 3),
|
||||||
formatSize(getTotalMem()),
|
usedMem,
|
||||||
if condSyms.isDefined("release"): "Release Build"
|
if condSyms.isDefined("release"): "Release Build"
|
||||||
else: "Debug Build"])
|
else: "Debug Build"])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -275,12 +275,21 @@ proc pageAddr(p: pointer): PChunk {.inline.} =
|
||||||
result = cast[PChunk](cast[ByteAddress](p) and not PageMask)
|
result = cast[PChunk](cast[ByteAddress](p) and not PageMask)
|
||||||
#sysAssert(Contains(allocator.chunkStarts, pageIndex(result)))
|
#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 =
|
proc requestOsChunks(a: var MemRegion, size: int): PBigChunk =
|
||||||
when not defined(emscripten):
|
when not defined(emscripten):
|
||||||
if not a.blockChunkSizeIncrease:
|
if not a.blockChunkSizeIncrease:
|
||||||
a.nextChunkSize =
|
if a.currMem < 64 * 1024:
|
||||||
if a.currMem < 64 * 1024: PageSize*4
|
a.nextChunkSize = PageSize*4
|
||||||
else: a.nextChunkSize*2
|
else:
|
||||||
|
a.nextChunkSize = min(roundup(a.currMem shr 2, PageSize), a.nextChunkSize * 2)
|
||||||
var size = size
|
var size = size
|
||||||
|
|
||||||
if size > a.nextChunkSize:
|
if size > a.nextChunkSize:
|
||||||
|
|
@ -344,14 +353,6 @@ proc contains[T](list, x: T): bool =
|
||||||
if it == x: return true
|
if it == x: return true
|
||||||
it = it.next
|
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.} =
|
proc listAdd[T](head: var T, c: T) {.inline.} =
|
||||||
sysAssert(c notin head, "listAdd 1")
|
sysAssert(c notin head, "listAdd 1")
|
||||||
sysAssert c.prev == nil, "listAdd 2"
|
sysAssert c.prev == nil, "listAdd 2"
|
||||||
|
|
@ -756,6 +757,7 @@ template instantiateForRegion(allocator: expr) =
|
||||||
|
|
||||||
proc getTotalMem(): int = return allocator.currMem
|
proc getTotalMem(): int = return allocator.currMem
|
||||||
proc getOccupiedMem(): int = return getTotalMem() - getFreeMem()
|
proc getOccupiedMem(): int = return getTotalMem() - getFreeMem()
|
||||||
|
proc getMaxMem*(): int = return getMaxMem(allocator)
|
||||||
|
|
||||||
# -------------------- shared heap region ----------------------------------
|
# -------------------- shared heap region ----------------------------------
|
||||||
when hasThreadSupport:
|
when hasThreadSupport:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue