allocator: disable unnecessary stuff for ORC [backport] (#20489)

This commit is contained in:
Andreas Rumpf 2022-10-03 18:33:45 +02:00 • committed by GitHub
commit 7aaeb75ebd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -108,6 +108,7 @@ type
next: ptr HeapLinks next: ptr HeapLinks
MemRegion = object MemRegion = object
when not defined(gcDestructors):
minLargeObj, maxLargeObj: int minLargeObj, maxLargeObj: int
freeSmallChunks: array[0..SmallChunkSize div MemAlign-1, PSmallChunk] freeSmallChunks: array[0..SmallChunkSize div MemAlign-1, PSmallChunk]
flBitmap: uint32 flBitmap: uint32
@ -117,9 +118,11 @@ 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
when not defined(gcDestructors):
root, deleted, last, freeAvlNodes: PAvlNode 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
when not defined(gcDestructors):
bottomData: AvlNode bottomData: AvlNode
heapLinks: HeapLinks heapLinks: HeapLinks
when defined(nimTypeNames): when defined(nimTypeNames):
@ -264,6 +267,7 @@ proc llAlloc(a: var MemRegion, size: int): pointer =
inc(a.llmem.acc, size) inc(a.llmem.acc, size)
zeroMem(result, size) zeroMem(result, size)
when not defined(gcDestructors):
proc getBottom(a: var MemRegion): PAvlNode = proc getBottom(a: var MemRegion): PAvlNode =
result = addr(a.bottomData) result = addr(a.bottomData)
if result.link[0] == nil: if result.link[0] == nil:
@ -308,6 +312,7 @@ 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
when not defined(gcDestructors):
include "system/avltree" include "system/avltree"
proc llDeallocAll(a: var MemRegion) = proc llDeallocAll(a: var MemRegion) =
@ -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,6 +756,7 @@ 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")
when not defined(gcDestructors):
if a.root == nil: a.root = getBottom(a) if a.root == nil: a.root = getBottom(a)
add(a, a.root, cast[ByteAddress](result), cast[ByteAddress](result)+%size) add(a, a.root, cast[ByteAddress](result), cast[ByteAddress](result)+%size)
inc a.occ, c.size inc a.occ, c.size
@ -868,6 +816,7 @@ 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)"
when not defined(gcDestructors):
a.deleted = getBottom(a) a.deleted = getBottom(a)
del(a, a.root, cast[int](addr(c.data))) del(a, a.root, cast[int](addr(c.data)))
if c.size >= HugeChunkSize: freeHugeChunk(a, c) if c.size >= HugeChunkSize: freeHugeChunk(a, c)