Skip to content

Commit 3ddf650

Browse files
committed
runtime/pprof: ignore dummy huge page mapping in /proc/self/maps
Change-Id: I72bea1450386100482b4681b20eb9a9af12c7522 Reviewed-on: https://go-review.googlesource.com/41816 Reviewed-by: Michael Matloob <[email protected]>
1 parent d1ac592 commit 3ddf650

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/runtime/pprof/proto.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,19 @@ func parseProcSelfMaps(data []byte, addMapping func(lo, hi, offset uint64, file,
442442
if err != nil {
443443
continue
444444
}
445-
next() // dev
446-
next() // inode
445+
next() // dev
446+
inode := next() // inode
447447
if line == nil {
448448
continue
449449
}
450450
file := string(line)
451+
if len(inode) == 1 && inode[0] == '0' && file == "" {
452+
// Huge-page text mappings list the initial fragment of
453+
// mapped but unpopulated memory as being inode 0.
454+
// Don't report that part.
455+
// But [vdso] and [vsyscall] are inode 0, so let non-empty file names through.
456+
continue
457+
}
451458

452459
// TODO: pprof's remapMappingIDs makes two adjustments:
453460
// 1. If there is an /anon_hugepage mapping first and it is

src/runtime/pprof/proto_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ ffffffffff600000-ffffffffff601000 r-xp 00000090 00:00 0 [vsysca
191191
7f7d77d41000 7f7d77d64000 00000000 /lib/x86_64-linux-gnu/ld-2.19.so
192192
7ffc34343000 7ffc34345000 00000000 [vdso]
193193
ffffffffff600000 ffffffffff601000 00000090 [vsyscall]
194+
195+
00400000-07000000 r-xp 00000000 00:00 0
196+
07000000-07093000 r-xp 06c00000 00:2e 536754 /path/to/gobench_server_main
197+
07093000-0722d000 rw-p 06c92000 00:2e 536754 /path/to/gobench_server_main
198+
0722d000-07b21000 rw-p 00000000 00:00 0
199+
c000000000-c000036000 rw-p 00000000 00:00 0
200+
->
201+
07000000 07093000 06c00000 /path/to/gobench_server_main
194202
`
195203

196204
func TestProcSelfMaps(t *testing.T) {
@@ -200,12 +208,15 @@ func TestProcSelfMaps(t *testing.T) {
200208
t.Fatal("malformed test case")
201209
}
202210
in, out := tt[:i], tt[i+len("->\n"):]
211+
if len(out) > 0 && out[len(out)-1] != '\n' {
212+
out += "\n"
213+
}
203214
var buf bytes.Buffer
204215
parseProcSelfMaps([]byte(in), func(lo, hi, offset uint64, file, buildID string) {
205216
fmt.Fprintf(&buf, "%08x %08x %08x %s\n", lo, hi, offset, file)
206217
})
207218
if buf.String() != out {
208-
t.Errorf("#%d: have:\n%s\nwant:\n%s", tx, buf.String(), out)
219+
t.Errorf("#%d: have:\n%s\nwant:\n%s\n%q\n%q", tx, buf.String(), out, buf.String(), out)
209220
}
210221
}
211222
}

0 commit comments

Comments
 (0)