diff --git a/compiler/main.nim b/compiler/main.nim index e6563f281..888f89ad5 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -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"]) diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim index 3b886b2fc..780baad7a 100644 --- a/lib/system/alloc.nim +++ b/lib/system/alloc.nim @@ -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: