While investigating the optimizations performed by my prove CL 196679, I found out these two instances of what looks like dead code:
|
j, searchIdx := s.chunkOf(ci).find(npages, 0) |
|
if j < 0 { |
|
// We couldn't find any space in this chunk despite the summaries telling |
|
// us it should be there. There's likely a bug, so dump some state and throw. |
|
sum := s.summary[len(s.summary)-1][i] |
|
print("runtime: summary[", len(s.summary)-1, "][", i, "] = (", sum.start(), ", ", sum.max(), ", ", sum.end(), ")\n") |
|
print("runtime: npages = ", npages, "\n") |
|
throw("bad summary data") |
|
} |
|
j, searchIdx := s.chunkOf(i).find(npages, chunkPageIndex(s.searchAddr)) |
|
if j < 0 { |
|
print("runtime: max = ", max, ", npages = ", npages, "\n") |
|
print("runtime: searchIdx = ", chunkPageIndex(s.searchAddr), ", s.searchAddr = ", hex(s.searchAddr), "\n") |
|
throw("bad summary data") |
|
} |
That branch is never taken because pallocBits.find() return an unsigned number:
|
// find searches for npages contiguous free pages in pallocBits and returns |
|
// the index where that run starts, as well as the index of the first free page |
|
// it found in the search. searchIdx represents the first known free page and |
|
// where to begin the search from. |
|
// |
|
// If find fails to find any free space, it returns an index of ^uint(0) and |
|
// the new searchIdx should be ignored. |
|
// |
|
// Note that if npages == 1, the two returned values will always be identical. |
|
func (b *pallocBits) find(npages uintptr, searchIdx uint) (uint, uint) { |
Given the documentation, it looks like the failure is reported as ^uint(0) so the above checks are probably wrong.
/cc @aclements @mknyszek
While investigating the optimizations performed by my prove CL 196679, I found out these two instances of what looks like dead code:
go/src/runtime/mpagealloc.go
Lines 726 to 734 in d99fe1f
go/src/runtime/mpagealloc.go
Lines 768 to 773 in d99fe1f
That branch is never taken because
pallocBits.find()return an unsigned number:go/src/runtime/mpallocbits.go
Lines 197 to 206 in d99fe1f
Given the documentation, it looks like the failure is reported as
^uint(0)so the above checks are probably wrong./cc @aclements @mknyszek