in file.go [657:694]
func computeMmapSize(minSize, maxSize, pageSize uint) (uint, reason) {
if maxSize != 0 {
// return maxSize as multiple of pages. Round downwards in case maxSize
// is not multiple of pages
if minSize > maxSize {
maxSize = minSize
}
sz := ((maxSize + pageSize - 1) / pageSize) * pageSize
if sz < initSize {
return 0, raiseInvalidParamf("max size of %v bytes is too small", maxSize)
}
return sz, nil
}
if minSize < doubleLimit {
// grow by next power of 2, starting at 64KB
initBits := uint(16) // 64KB min
power2Bits := uint(64 - bits.LeadingZeros64(uint64(minSize)))
if power2Bits < initBits {
power2Bits = initBits
}
return 1 << power2Bits, nil
}
// allocate number of 1GB blocks to fulfill minSize
sz := ((minSize + (sz1GB - 1)) / sz1GB) * sz1GB
if sz > maxMmapSize {
return 0, raiseInvalidParamf("mmap size of %v bytes is too large", sz)
}
// ensure we have a multiple of pageSize
sz = ((sz + pageSize - 1) / pageSize) * pageSize
return sz, nil
}