Add option to disable munmap() use in the allocator.
When compiling with '-d:nimAllocNoUnmap', the allocator will not attempt to return large chunks to the OS. For certain allocation behaviors, this can be a significant speedup.
This commit is contained in:
parent
d93c612067
commit
9ea99dbf36
1 changed files with 7 additions and 4 deletions
|
|
@ -27,8 +27,11 @@ sysAssert(roundup(65, 8) == 72, "roundup broken 2")
|
||||||
# some platforms have really weird unmap behaviour: unmap(blockStart, PageSize)
|
# some platforms have really weird unmap behaviour: unmap(blockStart, PageSize)
|
||||||
# really frees the whole block. Happens for Linux/PowerPC for example. Amd64
|
# really frees the whole block. Happens for Linux/PowerPC for example. Amd64
|
||||||
# and x86 are safe though; Windows is special because MEM_RELEASE can only be
|
# and x86 are safe though; Windows is special because MEM_RELEASE can only be
|
||||||
# used with a size of 0:
|
# used with a size of 0. We also allow unmapping to be turned off with
|
||||||
const weirdUnmap = not (defined(amd64) or defined(i386)) or defined(windows)
|
# -d:nimAllocNoUnmap:
|
||||||
|
const doNotUnmap = not (defined(amd64) or defined(i386)) or
|
||||||
|
defined(windows) or defined(nimAllocNoUnmap)
|
||||||
|
|
||||||
|
|
||||||
when defined(posix):
|
when defined(posix):
|
||||||
const
|
const
|
||||||
|
|
@ -478,7 +481,7 @@ proc freeBigChunk(a: var MemRegion, c: PBigChunk) =
|
||||||
excl(a.chunkStarts, pageIndex(c))
|
excl(a.chunkStarts, pageIndex(c))
|
||||||
c = cast[PBigChunk](le)
|
c = cast[PBigChunk](le)
|
||||||
|
|
||||||
if c.size < ChunkOsReturn or weirdUnmap:
|
if c.size < ChunkOsReturn or doNotUnmap:
|
||||||
incl(a, a.chunkStarts, pageIndex(c))
|
incl(a, a.chunkStarts, pageIndex(c))
|
||||||
updatePrevSize(a, c, c.size)
|
updatePrevSize(a, c, c.size)
|
||||||
listAdd(a.freeChunksList, c)
|
listAdd(a.freeChunksList, c)
|
||||||
|
|
@ -762,7 +765,7 @@ proc deallocOsPages(a: var MemRegion) =
|
||||||
# we free every 'ordinarily' allocated page by iterating over the page bits:
|
# we free every 'ordinarily' allocated page by iterating over the page bits:
|
||||||
for p in elements(a.chunkStarts):
|
for p in elements(a.chunkStarts):
|
||||||
var page = cast[PChunk](p shl PageShift)
|
var page = cast[PChunk](p shl PageShift)
|
||||||
when not weirdUnmap:
|
when not doNotUnmap:
|
||||||
var size = if page.size < PageSize: PageSize else: page.size
|
var size = if page.size < PageSize: PageSize else: page.size
|
||||||
osDeallocPages(page, size)
|
osDeallocPages(page, size)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue