Fix max mmap check for 32-bit arch.

This commit is contained in:
Ben Johnson 2015-01-28 16:27:06 -05:00
parent dacc1873d1
commit 338d8e78e2

22
db.go
View File

@ -225,24 +225,30 @@ func (db *DB) mmapSize(size int) (int, error) {
} }
} }
// Verify the map size is not above the maximum allowed. // Verify the requested size is not above the maximum allowed.
if size > maxMapSize-maxMmapStep { if size > maxMapSize {
return 0, fmt.Errorf("mmap too large") return 0, fmt.Errorf("mmap too large")
} }
// If larger than 1GB then grow by 1GB at a time. // If larger than 1GB then grow by 1GB at a time.
size += maxMmapStep sz := int64(size) + int64(maxMmapStep)
if remainder := size % maxMmapStep; remainder > 0 { if remainder := sz % int64(maxMmapStep); remainder > 0 {
size -= remainder sz -= remainder
} }
// Ensure that the mmap size is a multiple of the page size. // Ensure that the mmap size is a multiple of the page size.
// This should always be true since we're incrementing in MBs. // This should always be true since we're incrementing in MBs.
if (size % db.pageSize) != 0 { pageSize := int64(db.pageSize)
size = ((size / db.pageSize) + 1) * db.pageSize if (sz % pageSize) != 0 {
sz = ((sz / pageSize) + 1) * pageSize
} }
return size, nil // If we've exceeded the max size then only grow up to the max size.
if sz > maxMapSize {
sz = maxMapSize
}
return int(sz), nil
} }
// init creates a new database file and initializes its meta pages. // init creates a new database file and initializes its meta pages.