aboutsummaryrefslogtreecommitdiff
path: root/freelist.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2016-12-22 17:22:44 -0800
committerJosh Bleecher Snyder <josharian@gmail.com>2016-12-23 09:18:57 -0800
commit7adfa44e02041a6d9b571025a8237a13fa6fbde8 (patch)
treef7b614d155c749de5a7ee6e5e6e44adf1a33b19c /freelist.go
parentPrecalculate size of pending pgids in freelist.copyall (diff)
downloaddedo-7adfa44e02041a6d9b571025a8237a13fa6fbde8.tar.gz
dedo-7adfa44e02041a6d9b571025a8237a13fa6fbde8.tar.xz
Fix freelist.size calculation for large freelists
freelist.size did not account for the extra fake freelist item used to hold the number of elements when the freelist is large.
Diffstat (limited to '')
-rw-r--r--freelist.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/freelist.go b/freelist.go
index de59aaa..aba48f5 100644
--- a/freelist.go
+++ b/freelist.go
@@ -24,7 +24,12 @@ func newFreelist() *freelist {
// size returns the size of the page after serialization.
func (f *freelist) size() int {
- return pageHeaderSize + (int(unsafe.Sizeof(pgid(0))) * f.count())
+ n := f.count()
+ if n >= 0xFFFF {
+ // The first element will be used to store the count. See freelist.write.
+ n++
+ }
+ return pageHeaderSize + (int(unsafe.Sizeof(pgid(0))) * n)
}
// count returns count of pages on the freelist