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
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue