allocator: disable unnecessary stuff for ORC [backport] (#20489)
This commit is contained in:
parent
0f5ad49971
commit
7aaeb75ebd
1 changed files with 42 additions and 93 deletions
|
|
@ -108,7 +108,8 @@ type
|
||||||
next: ptr HeapLinks
|
next: ptr HeapLinks
|
||||||
|
|
||||||
MemRegion = object
|
MemRegion = object
|
||||||
minLargeObj, maxLargeObj: int
|
when not defined(gcDestructors):
|
||||||
|
minLargeObj, maxLargeObj: int
|
||||||
freeSmallChunks: array[0..SmallChunkSize div MemAlign-1, PSmallChunk]
|
freeSmallChunks: array[0..SmallChunkSize div MemAlign-1, PSmallChunk]
|
||||||
flBitmap: uint32
|
flBitmap: uint32
|
||||||
slBitmap: array[RealFli, uint32]
|
slBitmap: array[RealFli, uint32]
|
||||||
|
|
@ -117,10 +118,12 @@ type
|
||||||
currMem, maxMem, freeMem, occ: int # memory sizes (allocated from OS)
|
currMem, maxMem, freeMem, occ: int # memory sizes (allocated from OS)
|
||||||
lastSize: int # needed for the case that OS gives us pages linearly
|
lastSize: int # needed for the case that OS gives us pages linearly
|
||||||
chunkStarts: IntSet
|
chunkStarts: IntSet
|
||||||
root, deleted, last, freeAvlNodes: PAvlNode
|
when not defined(gcDestructors):
|
||||||
|
root, deleted, last, freeAvlNodes: PAvlNode
|
||||||
locked, blockChunkSizeIncrease: bool # if locked, we cannot free pages.
|
locked, blockChunkSizeIncrease: bool # if locked, we cannot free pages.
|
||||||
nextChunkSize: int
|
nextChunkSize: int
|
||||||
bottomData: AvlNode
|
when not defined(gcDestructors):
|
||||||
|
bottomData: AvlNode
|
||||||
heapLinks: HeapLinks
|
heapLinks: HeapLinks
|
||||||
when defined(nimTypeNames):
|
when defined(nimTypeNames):
|
||||||
allocCounter, deallocCounter: int
|
allocCounter, deallocCounter: int
|
||||||
|
|
@ -264,35 +267,36 @@ proc llAlloc(a: var MemRegion, size: int): pointer =
|
||||||
inc(a.llmem.acc, size)
|
inc(a.llmem.acc, size)
|
||||||
zeroMem(result, size)
|
zeroMem(result, size)
|
||||||
|
|
||||||
proc getBottom(a: var MemRegion): PAvlNode =
|
when not defined(gcDestructors):
|
||||||
result = addr(a.bottomData)
|
proc getBottom(a: var MemRegion): PAvlNode =
|
||||||
if result.link[0] == nil:
|
result = addr(a.bottomData)
|
||||||
result.link[0] = result
|
if result.link[0] == nil:
|
||||||
result.link[1] = result
|
result.link[0] = result
|
||||||
|
result.link[1] = result
|
||||||
|
|
||||||
proc allocAvlNode(a: var MemRegion, key, upperBound: int): PAvlNode =
|
proc allocAvlNode(a: var MemRegion, key, upperBound: int): PAvlNode =
|
||||||
if a.freeAvlNodes != nil:
|
if a.freeAvlNodes != nil:
|
||||||
result = a.freeAvlNodes
|
result = a.freeAvlNodes
|
||||||
a.freeAvlNodes = a.freeAvlNodes.link[0]
|
a.freeAvlNodes = a.freeAvlNodes.link[0]
|
||||||
else:
|
else:
|
||||||
result = cast[PAvlNode](llAlloc(a, sizeof(AvlNode)))
|
result = cast[PAvlNode](llAlloc(a, sizeof(AvlNode)))
|
||||||
when defined(nimAvlcorruption):
|
when defined(nimAvlcorruption):
|
||||||
cprintf("tracking location: %p\n", result)
|
cprintf("tracking location: %p\n", result)
|
||||||
result.key = key
|
result.key = key
|
||||||
result.upperBound = upperBound
|
result.upperBound = upperBound
|
||||||
let bottom = getBottom(a)
|
let bottom = getBottom(a)
|
||||||
result.link[0] = bottom
|
result.link[0] = bottom
|
||||||
result.link[1] = bottom
|
result.link[1] = bottom
|
||||||
result.level = 1
|
result.level = 1
|
||||||
#when defined(nimAvlcorruption):
|
#when defined(nimAvlcorruption):
|
||||||
# track("allocAvlNode", result, sizeof(AvlNode))
|
# track("allocAvlNode", result, sizeof(AvlNode))
|
||||||
sysAssert(bottom == addr(a.bottomData), "bottom data")
|
sysAssert(bottom == addr(a.bottomData), "bottom data")
|
||||||
sysAssert(bottom.link[0] == bottom, "bottom link[0]")
|
sysAssert(bottom.link[0] == bottom, "bottom link[0]")
|
||||||
sysAssert(bottom.link[1] == bottom, "bottom link[1]")
|
sysAssert(bottom.link[1] == bottom, "bottom link[1]")
|
||||||
|
|
||||||
proc deallocAvlNode(a: var MemRegion, n: PAvlNode) {.inline.} =
|
proc deallocAvlNode(a: var MemRegion, n: PAvlNode) {.inline.} =
|
||||||
n.link[0] = a.freeAvlNodes
|
n.link[0] = a.freeAvlNodes
|
||||||
a.freeAvlNodes = n
|
a.freeAvlNodes = n
|
||||||
|
|
||||||
proc addHeapLink(a: var MemRegion; p: PBigChunk, size: int) =
|
proc addHeapLink(a: var MemRegion; p: PBigChunk, size: int) =
|
||||||
var it = addr(a.heapLinks)
|
var it = addr(a.heapLinks)
|
||||||
|
|
@ -308,7 +312,8 @@ proc addHeapLink(a: var MemRegion; p: PBigChunk, size: int) =
|
||||||
it.chunks[L] = (p, size)
|
it.chunks[L] = (p, size)
|
||||||
inc it.len
|
inc it.len
|
||||||
|
|
||||||
include "system/avltree"
|
when not defined(gcDestructors):
|
||||||
|
include "system/avltree"
|
||||||
|
|
||||||
proc llDeallocAll(a: var MemRegion) =
|
proc llDeallocAll(a: var MemRegion) =
|
||||||
var it = a.llmem
|
var it = a.llmem
|
||||||
|
|
@ -686,64 +691,6 @@ else:
|
||||||
template trackSize(x) = discard
|
template trackSize(x) = discard
|
||||||
template untrackSize(x) = discard
|
template untrackSize(x) = discard
|
||||||
|
|
||||||
when false:
|
|
||||||
# not yet used by the GCs
|
|
||||||
proc rawTryAlloc(a: var MemRegion; requestedSize: int): pointer =
|
|
||||||
sysAssert(allocInv(a), "rawAlloc: begin")
|
|
||||||
sysAssert(roundup(65, 8) == 72, "rawAlloc: roundup broken")
|
|
||||||
sysAssert(requestedSize >= sizeof(FreeCell), "rawAlloc: requested size too small")
|
|
||||||
var size = roundup(requestedSize, MemAlign)
|
|
||||||
inc a.occ, size
|
|
||||||
trackSize(size)
|
|
||||||
sysAssert(size >= requestedSize, "insufficient allocated size!")
|
|
||||||
#c_fprintf(stdout, "alloc; size: %ld; %ld\n", requestedSize, size)
|
|
||||||
if size <= SmallChunkSize-smallChunkOverhead():
|
|
||||||
# allocate a small block: for small chunks, we use only its next pointer
|
|
||||||
var s = size div MemAlign
|
|
||||||
var c = a.freeSmallChunks[s]
|
|
||||||
if c == nil:
|
|
||||||
result = nil
|
|
||||||
else:
|
|
||||||
sysAssert c.size == size, "rawAlloc 6"
|
|
||||||
if c.freeList == nil:
|
|
||||||
sysAssert(c.acc + smallChunkOverhead() + size <= SmallChunkSize,
|
|
||||||
"rawAlloc 7")
|
|
||||||
result = cast[pointer](cast[ByteAddress](addr(c.data)) +% c.acc)
|
|
||||||
inc(c.acc, size)
|
|
||||||
else:
|
|
||||||
result = c.freeList
|
|
||||||
sysAssert(c.freeList.zeroField == 0, "rawAlloc 8")
|
|
||||||
c.freeList = c.freeList.next
|
|
||||||
dec(c.free, size)
|
|
||||||
sysAssert((cast[ByteAddress](result) and (MemAlign-1)) == 0, "rawAlloc 9")
|
|
||||||
if c.free < size:
|
|
||||||
listRemove(a.freeSmallChunks[s], c)
|
|
||||||
sysAssert(allocInv(a), "rawAlloc: end listRemove test")
|
|
||||||
sysAssert(((cast[ByteAddress](result) and PageMask) - smallChunkOverhead()) %%
|
|
||||||
size == 0, "rawAlloc 21")
|
|
||||||
sysAssert(allocInv(a), "rawAlloc: end small size")
|
|
||||||
else:
|
|
||||||
inc size, bigChunkOverhead()
|
|
||||||
var fl, sl: int
|
|
||||||
mappingSearch(size, fl, sl)
|
|
||||||
sysAssert((size and PageMask) == 0, "getBigChunk: unaligned chunk")
|
|
||||||
let c = findSuitableBlock(a, fl, sl)
|
|
||||||
if c != nil:
|
|
||||||
removeChunkFromMatrix2(a, c, fl, sl)
|
|
||||||
if c.size >= size + PageSize:
|
|
||||||
splitChunk(a, c, size)
|
|
||||||
# set 'used' to to true:
|
|
||||||
c.prevSize = 1
|
|
||||||
incl(a, a.chunkStarts, pageIndex(c))
|
|
||||||
dec(a.freeMem, size)
|
|
||||||
result = addr(c.data)
|
|
||||||
sysAssert((cast[ByteAddress](c) and (MemAlign-1)) == 0, "rawAlloc 13")
|
|
||||||
sysAssert((cast[ByteAddress](c) and PageMask) == 0, "rawAlloc: Not aligned on a page boundary")
|
|
||||||
if a.root == nil: a.root = getBottom(a)
|
|
||||||
add(a, a.root, cast[ByteAddress](result), cast[ByteAddress](result)+%size)
|
|
||||||
else:
|
|
||||||
result = nil
|
|
||||||
|
|
||||||
proc rawAlloc(a: var MemRegion, requestedSize: int): pointer =
|
proc rawAlloc(a: var MemRegion, requestedSize: int): pointer =
|
||||||
when defined(nimTypeNames):
|
when defined(nimTypeNames):
|
||||||
inc(a.allocCounter)
|
inc(a.allocCounter)
|
||||||
|
|
@ -809,8 +756,9 @@ proc rawAlloc(a: var MemRegion, requestedSize: int): pointer =
|
||||||
result = addr(c.data)
|
result = addr(c.data)
|
||||||
sysAssert((cast[ByteAddress](c) and (MemAlign-1)) == 0, "rawAlloc 13")
|
sysAssert((cast[ByteAddress](c) and (MemAlign-1)) == 0, "rawAlloc 13")
|
||||||
sysAssert((cast[ByteAddress](c) and PageMask) == 0, "rawAlloc: Not aligned on a page boundary")
|
sysAssert((cast[ByteAddress](c) and PageMask) == 0, "rawAlloc: Not aligned on a page boundary")
|
||||||
if a.root == nil: a.root = getBottom(a)
|
when not defined(gcDestructors):
|
||||||
add(a, a.root, cast[ByteAddress](result), cast[ByteAddress](result)+%size)
|
if a.root == nil: a.root = getBottom(a)
|
||||||
|
add(a, a.root, cast[ByteAddress](result), cast[ByteAddress](result)+%size)
|
||||||
inc a.occ, c.size
|
inc a.occ, c.size
|
||||||
trackSize(c.size)
|
trackSize(c.size)
|
||||||
sysAssert(isAccessible(a, result), "rawAlloc 14")
|
sysAssert(isAccessible(a, result), "rawAlloc 14")
|
||||||
|
|
@ -868,8 +816,9 @@ proc rawDealloc(a: var MemRegion, p: pointer) =
|
||||||
dec a.occ, c.size
|
dec a.occ, c.size
|
||||||
untrackSize(c.size)
|
untrackSize(c.size)
|
||||||
sysAssert a.occ >= 0, "rawDealloc: negative occupied memory (case B)"
|
sysAssert a.occ >= 0, "rawDealloc: negative occupied memory (case B)"
|
||||||
a.deleted = getBottom(a)
|
when not defined(gcDestructors):
|
||||||
del(a, a.root, cast[int](addr(c.data)))
|
a.deleted = getBottom(a)
|
||||||
|
del(a, a.root, cast[int](addr(c.data)))
|
||||||
if c.size >= HugeChunkSize: freeHugeChunk(a, c)
|
if c.size >= HugeChunkSize: freeHugeChunk(a, c)
|
||||||
else: freeBigChunk(a, c)
|
else: freeBigChunk(a, c)
|
||||||
sysAssert(allocInv(a), "rawDealloc: end")
|
sysAssert(allocInv(a), "rawDealloc: end")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue