Memory leak in minecraft (many dri/renderD128 regions in /proc/[id]/maps)
System information
System:
Host: abominationII Kernel: 5.4.0-37-generic x86_64 bits: 64 compiler: gcc
v: 9.3.0 Desktop: Gnome 3.36.4 wm: gnome-shell dm: GDM3
Distro: Ubuntu 20.04.1 LTS (Focal Fossa)
CPU:
Topology: Quad Core model: AMD Ryzen 5 2500U with Radeon Vega Mobile Gfx
bits: 64 type: MT MCP arch: Zen L2 cache: 2048 KiB
flags: avx avx2 lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm
bogomips: 31941
Speed: 1387 MHz min/max: 1600/2000 MHz Core speeds (MHz): 1: 1388 2: 1387
3: 3469 4: 3456 5: 1390 6: 1387 7: 1391 8: 1388
Graphics:
Device-1: AMD Raven Ridge [Radeon Vega Series / Radeon Vega Mobile Series]
vendor: Hewlett-Packard driver: amdgpu v: kernel bus ID: 04:00.0
chip ID: 1002:15dd
Display: x11 server: X.Org 1.20.8 driver: none compositor: gnome-shell
resolution: 1920x1080~60Hz
OpenGL: renderer: AMD Radeon Vega 8 Graphics (RAVEN DRM 3.35.0
5.4.0-37-generic LLVM 11.0.0)
v: 4.6 Mesa 20.3.0-devel (git-57d3178 2020-10-17 focal-oibaf-ppa)
direct render: Yes
Describe the issue
This old issue.
Minecraft (so far it's the only app with such issue I've seen) leaks memory in form of memory regions mapped to /dev/dri/renderD128
(new ones appear, old ones stay until process is terminated. memory usage seems to be proportional to amount of these regions), seemingly with no limit (given time, it can take up all the available ram and force swap usage). I'm convinced it's because drawing surfaces are not freed correctly, because if player stands in one place after some time no new renderD128
regions will appear in maps file, if after that player increases render distance, many more regions will appear, if after that player lowers render distance (at which point further parts of terrain will unload) to initial value, these new renderD128
regions will still be there, and increasing rendering distance again will trigger appearance of new renderD128
regions.
I can reliably reproduce it by replaying apitrace trace (see attached files) (i.e. no need to download and launch minecraft to test it), but it seems it can't be reproduced by others (see that old issue, there's reply from Denis stating that issue doesn't appear for him when he replays trace. But I'd say it's still worth trying to reproduce. Exact way I count these regions:
#!/bin/bash
trace_file=$1
if [ -z $trace_file ]; then
echo "Usage: $0 <trace_file>"
exit
fi
LOGFILE=$1'.trace_log'
stdbuf -oL glretrace --singlethread --wait $1 &>$LOGFILE &
pid=$!
trap "kill $pid 2>/dev/null" EXIT
stdbuf -oL tail --pid=$(($BASHPID+2)) -f $LOGFILE | grep --line-buffered 'Rendered' | read line
cat /proc/$pid/maps | grep dri/render -c
Crude but works, just give it path to trace file and it'll replay it and output count of problematic regions at the last frame of replay. It always counts 98 for me (on this trace).
It's definitely a memory leak (i.e. minecraft is not supposed to rapidly consume all your ram, usually it takes only slightly more than you allocate for java vm), but apitrace leak
seemingly doesn't find much (or maybe that's entire leak, I'm not sure how to check):
$ apitrace leaks trace1
2088: error: texture 2 was not destroyed until 1752739
2114: error: texture 3 was not destroyed until 1752739
5783: error: texture 11 was not destroyed until 1752739
Same for valgrind:
$ valgrind glretrace --singlethread trace1
. . .
Rendered 537 frames in 288.131 secs, average of 1.86373 fps
==15154==
==15154== HEAP SUMMARY:
==15154== in use at exit: 3,140,954 bytes in 13,749 blocks
==15154== total heap usage: 9,460,977 allocs, 9,447,228 frees, 700,539,218 bytes allocated
==15154==
==15154== LEAK SUMMARY:
==15154== definitely lost: 17,536 bytes in 47 blocks
==15154== indirectly lost: 530,427 bytes in 2,080 blocks
==15154== possibly lost: 2,234,608 bytes in 8,335 blocks
==15154== still reachable: 358,383 bytes in 3,287 blocks
==15154== of which reachable via heuristic:
==15154== multipleinheritance: 64,400 bytes in 128 blocks
==15154== suppressed: 0 bytes in 0 blocks
==15154== Rerun with --leak-check=full to see details of leaked memory
==15154==
==15154== For lists of detected and suppressed errors, rerun with: -s
==15154== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
Replaying the trace gives some shader warnings (errors?), not sure if these are relevant:
2071: message: shader compiler issue 1: Shader Stats: SGPRS: 16 VGPRS: 32 Code Size: 16 LDS: 0 Scratch: 0 Max Waves: 8 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
2071: message: shader compiler issue 1: Shader Stats: SGPRS: 32 VGPRS: 12 Code Size: 228 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
2072: message: shader compiler issue 1: Shader Stats: SGPRS: 16 VGPRS: 8 Code Size: 112 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
2072: message: shader compiler issue 1: Shader Stats: SGPRS: 24 VGPRS: 28 Code Size: 60 LDS: 0 Scratch: 0 Max Waves: 9 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
2072: message: shader compiler issue 1: Shader Stats: SGPRS: 24 VGPRS: 8 Code Size: 72 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
2072: message: shader compiler issue 1: Shader Stats: SGPRS: 24 VGPRS: 8 Code Size: 40 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
2159: message: shader compiler issue 1: Shader Stats: SGPRS: 16 VGPRS: 28 Code Size: 24 LDS: 0 Scratch: 0 Max Waves: 9 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
2159: message: shader compiler issue 1: Shader Stats: SGPRS: 16 VGPRS: 8 Code Size: 60 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
2167: message: shader compiler issue 1: Shader Stats: SGPRS: 24 VGPRS: 32 Code Size: 108 LDS: 0 Scratch: 0 Max Waves: 8 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
2167: message: shader compiler issue 1: Shader Stats: SGPRS: 32 VGPRS: 16 Code Size: 228 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
2176: message: shader compiler issue 1: Shader Stats: SGPRS: 32 VGPRS: 28 Code Size: 140 LDS: 0 Scratch: 0 Max Waves: 9 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
2191: message: shader compiler issue 1: Shader Stats: SGPRS: 24 VGPRS: 12 Code Size: 164 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
2308: message: shader compiler issue 1: Shader Stats: SGPRS: 24 VGPRS: 12 Code Size: 208 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
3010: message: shader compiler issue 1: Shader Stats: SGPRS: 32 VGPRS: 8 Code Size: 156 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
11779: message: shader compiler issue 1: Shader Stats: SGPRS: 24 VGPRS: 12 Code Size: 208 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
396433: message: shader compiler issue 1: Shader Stats: SGPRS: 24 VGPRS: 28 Code Size: 116 LDS: 0 Scratch: 0 Max Waves: 9 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
396453: message: shader compiler issue 1: Shader Stats: SGPRS: 40 VGPRS: 12 Code Size: 280 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
396536: message: shader compiler issue 1: Shader Stats: SGPRS: 32 VGPRS: 28 Code Size: 216 LDS: 0 Scratch: 0 Max Waves: 9 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
480498: message: shader compiler issue 1: Shader Stats: SGPRS: 32 VGPRS: 28 Code Size: 132 LDS: 0 Scratch: 0 Max Waves: 9 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
480556: message: shader compiler issue 1: Shader Stats: SGPRS: 24 VGPRS: 8 Code Size: 144 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
480580: message: shader compiler issue 1: Shader Stats: SGPRS: 40 VGPRS: 32 Code Size: 200 LDS: 0 Scratch: 0 Max Waves: 8 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
480639: message: shader compiler issue 1: Shader Stats: SGPRS: 48 VGPRS: 20 Code Size: 852 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
480639: message: shader compiler issue 1: Shader Stats: SGPRS: 40 VGPRS: 32 Code Size: 184 LDS: 0 Scratch: 0 Max Waves: 8 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
480657: message: shader compiler issue 1: Shader Stats: SGPRS: 64 VGPRS: 20 Code Size: 812 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
480657: message: shader compiler issue 1: Shader Stats: SGPRS: 24 VGPRS: 12 Code Size: 164 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
481006: message: shader compiler issue 1: Shader Stats: SGPRS: 24 VGPRS: 12 Code Size: 164 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
482176: message: shader compiler issue 1: Shader Stats: SGPRS: 24 VGPRS: 32 Code Size: 128 LDS: 0 Scratch: 0 Max Waves: 8 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
883646: message: shader compiler issue 1: Shader Stats: SGPRS: 40 VGPRS: 32 Code Size: 284 LDS: 0 Scratch: 0 Max Waves: 8 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
883745: message: shader compiler issue 1: Shader Stats: SGPRS: 56 VGPRS: 20 Code Size: 484 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
883830: message: shader compiler issue 1: Shader Stats: SGPRS: 32 VGPRS: 16 Code Size: 228 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
885037: message: shader compiler issue 1: Shader Stats: SGPRS: 56 VGPRS: 20 Code Size: 1004 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
885137: message: shader compiler issue 1: Shader Stats: SGPRS: 64 VGPRS: 20 Code Size: 948 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
886370: message: shader compiler issue 1: Shader Stats: SGPRS: 64 VGPRS: 20 Code Size: 832 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
886414: message: shader compiler issue 1: Shader Stats: SGPRS: 16 VGPRS: 28 Code Size: 24 LDS: 0 Scratch: 0 Max Waves: 9 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
887730: message: shader compiler issue 1: Shader Stats: SGPRS: 64 VGPRS: 20 Code Size: 968 LDS: 0 Scratch: 0 Max Waves: 10 Spilled SGPRs: 0 Spilled VGPRs: 0 PrivMem VGPRs: 0
Regression
It didn't work at the moment I created that old issue (link at the beginning of this issue), but I didn't check it since then (but I guess it wasn't fixed and accidentally broken again since that time).
Log files as attachment
Apitrace trace: trace1 ;
I've straced the replay with stack trace active, there are 92 very similar calls (mmap(NULL, 1048576, PROT_READ|PROT_WRITE, MAP_SHARED, 7,
), all of which correspond to dri/render regions in proc maps, so I assume these are the problematic calls. trace1.strace + memmap (grepped with filter "dri/render")
Any extra information would be greatly appreciated
I've tried playing minecraft on windows (on same pc), there's no such problem as "memory leak that will eventually crash client", but it lags horribly once in a while. I suspect the problem is in faulty gpu and/or bios, I guess HP modified official driver to work around this by doing something like garbage collector pass that runs once in a while, and that results in those random lags, but I don't have any proofs to back that up. I think I can try to implement something similar (some kernel level module that runs on timer and identifies and force unmaps "lost" memory pages), but that sounds complicated, so I guess it's last resort just in case all else fails.