usage: a start's log blocks are of log-v1.bin's pages, not the heap (#2278)
logDiskRead read log-v1.bin whole with os.ReadFile, and the kept blocks' Archives were slices of that copy, so a 240k-call history held ~7 MB of file bytes in the heap for good. GOGC then let the heap grow by about as much again. Where the system maps the file, the blocks are now of its pages, the same way requests-v1.bin's blocks already are (diskMapping, readMapped, m.read()). Elsewhere it is read into the heap as before. Run at the pushed head, on mote, through mote-run: - go vet ./internal/usage: ok. GOOS=linux and GOOS=windows go vet ./internal/usage: ok. - go test ./internal/usage: ok. go test ./internal/usageapi: ok. - New TestLogDiskBlocksMapped: 2 full blocks plus a tail are written, the log is restarted and read again, and each full block's Archive must be inside the mapping. Broken by hand (c.mapped = m dropped): red, "block 0: read from the file into the heap". Green again restored. - go test ./internal/gui: FAIL on the AppKit window tests only (TestDockJoinLeadsCommandTab, TestPanelCloseHidesIt, TestMainWindowCorners and 7 others), killed at their deadline on mote under load ~24. These are #4125 and #2645, and the same tests fail without this change. Bench on mote, with the real 240k-row history: a warm restart while the Sessions tab polls, and the heap profiled at 200 s. - In use: 174.1 and 175.0 MB with this change, 187.6 MB without. - Footprint at 200 s: 290 and 297 MB with it, 297 MB without. mote's load (~24) makes this ±20 MB, so the footprint gain is not resolved. Not tried: Windows, where the file is still read into the heap.
This commit is contained in:
@@ -70,12 +70,29 @@ type logDiskProbe struct {
|
||||
}
|
||||
|
||||
// logDiskRead is the file's snapshot of the log at path, when the log's
|
||||
// first bytes are still the ones it was written of.
|
||||
// first bytes are still the ones it was written of. Where the system maps
|
||||
// the file, the blocks are of its pages, as requests-v1.bin's are
|
||||
// (diskMapping): read into the heap, a 240k-call history's 7 MB of them
|
||||
// stayed there for good, and the collector let the heap grow by as much
|
||||
// again (#2278).
|
||||
func logDiskRead(path string, size int64) *logDisk {
|
||||
if m, ok := mapDiskFile(logDiskPath()); ok {
|
||||
var d *logDisk
|
||||
if !readMapped(m, func() { d = logDiskOf(m.data, m, path, size) }) {
|
||||
d = nil
|
||||
}
|
||||
m.read()
|
||||
return d
|
||||
}
|
||||
b, err := os.ReadFile(logDiskPath())
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return logDiskOf(b, nil, path, size)
|
||||
}
|
||||
|
||||
// logDiskOf is logDiskRead of the file's bytes b, of m's pages with m.
|
||||
func logDiskOf(b []byte, m *diskMapping, path string, size int64) *logDisk {
|
||||
header, b, ok := cutDiskEntry(b)
|
||||
if !ok {
|
||||
return nil
|
||||
@@ -137,7 +154,7 @@ func logDiskRead(path string, size int64) *logDisk {
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
c.serial = nextChunkSerial()
|
||||
c.serial, c.mapped = nextChunkSerial(), m
|
||||
d.blocks = append(d.blocks, c)
|
||||
}
|
||||
if len(b) != 0 {
|
||||
|
||||
@@ -251,3 +251,31 @@ func TestArchiveSpillFailedMadeAgain(t *testing.T) {
|
||||
t.Errorf("spill left: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// The log's full blocks a start reads from log-v1.bin are of the file's
|
||||
// pages too, not of the heap (#2278).
|
||||
func TestLogDiskBlocksMapped(t *testing.T) {
|
||||
pageHome(t)
|
||||
settleLogClock(t)
|
||||
t.Cleanup(restartLog)
|
||||
restartLog()
|
||||
logLines(t, 0, 2*logBlockRows+300)
|
||||
readLogSnapshot()
|
||||
if _, err := os.Stat(logDiskPath()); err != nil {
|
||||
t.Fatalf("the full blocks weren't kept: %v", err)
|
||||
}
|
||||
restartLog()
|
||||
s := readLogSnapshot()
|
||||
if len(s.blocks) < 2 {
|
||||
t.Fatalf("%d blocks", len(s.blocks))
|
||||
}
|
||||
for i, c := range s.blocks[:2] {
|
||||
if c.mapped == nil {
|
||||
t.Fatalf("block %d: read from the file into the heap", i)
|
||||
}
|
||||
at, start := uintptr(unsafe.Pointer(unsafe.SliceData(c.Archive))), uintptr(unsafe.Pointer(unsafe.SliceData(c.mapped.data)))
|
||||
if at < start || at+uintptr(len(c.Archive)) > start+uintptr(len(c.mapped.data)) {
|
||||
t.Fatalf("block %d: archive outside the mapping", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user