Rust-1.6でvalgrindを使うとSEGVすることがある場合の対処
一応解決済。
概要
Rust-1.6でコンパイルしたコードのプロファイリングをvalgrindを使って行おうとしたところ、SEGVした。 もちろんvalgrindを使わず実行した場合にはSEGVしない。 unsafeなコードを書いていないこともあり、まずRustかjemallocか何かのバグだろうとは思うのだが、原因がわからないのでどうしようもない。
というわけで、とりあえず対処だけ。
このレスを参考に、環境変数をJE_MALLOC_CONF=quarantine:0
のように設定する。これでおしまい。
# (*'-')<(ok) 2016/03/17-13:18:15@1458188295 pts/12 (git:feature/reimplement-faster-fbx-loader) # larry@veg:~lp1 $ valgrind --tool=memcheck ./target/debug/new-loader ==18749== Memcheck, a memory error detector ==18749== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al. ==18749== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info ==18749== Command: ./target/debug/new-loader ==18749== ==18749== Invalid read of size 4 ==18749== at 0x50439F4: pthread_mutex_lock (pthread_mutex_lock.c:68) ==18749== by 0x1E40E4: je_malloc_mutex_lock (mutex.h:77) ==18749== by 0x1E40E4: je_arena_dalloc_bin (arena.c:1804) ==18749== by 0x1F2399: je_arena_dalloc (arena.h:1162) ==18749== by 0x1F2399: je_idalloct (jemalloc_internal.h:770) ==18749== by 0x1F2399: je_idalloc (jemalloc_internal.h:793) ==18749== by 0x1F2399: quarantine_grow (quarantine.c:68) ==18749== by 0x1F2399: je_quarantine (quarantine.c:117) ==18749== by 0x1DF83A: je_isqalloc (jemalloc_internal.h:811) ==18749== by 0x1DF83A: isfree (jemalloc.c:1257) ==18749== by 0x1DF83A: je_sdallocx (jemalloc.c:1896) ==18749== by 0x117A07: heap::deallocate::h0a17c8e2da255a4a4ea (heap.rs:111) ==18749== by 0x1208E2: raw_vec::_$LT$impl$GT$::drop::drop::h16868981604614779235 (raw_vec.rs:472) ==18749== by 0x1207ED: alloc..raw_vec..RawVec$LT$fbx_direct..common..OwnedProperty$GT$::drop.5849::haf21a87197ef2e30 (in /home/larry/development/rust_progress1/last_progress1/target/debug/new-loader) ==18749== by 0x1207D5: collections..vec..Vec$LT$fbx_direct..common..OwnedProperty$GT$::drop.5846::h5a5c3b3b2f5cbdff (in /home/larry/development/rust_progress1/last_progress1/target/debug/new-loader) ==18749== by 0x1203D9: collections..vec..Vec$LT$fbx_direct..common..OwnedProperty$GT$::drop.5842::h5a5c3b3b2f5cbdff (in /home/larry/development/rust_progress1/last_progress1/target/debug/new-loader) ==18749== by 0x1276C4: fbx_direct..reader..FbxEvent::drop.6598::h0f7cc59733d5e2ce (in /home/larry/development/rust_progress1/last_progress1/target/debug/new-loader) ==18749== by 0x136832: node_loader::ignore_current_node::ignore_current_node::h13884145912320270413 (node_loader.rs:52) ==18749== by 0x135552: scene::_$LT$impl$GT$::on_child_node::on_child_node::h16000248940111934485 (scene.rs:52) ==18749== Address 0x10 is not stack'd, malloc'd or (recently) free'd ==18749== ==18749== ==18749== Process terminating with default action of signal 11 (SIGSEGV): dumping core ==18749== Access not within mapped region at address 0x10 ==18749== at 0x50439F4: pthread_mutex_lock (pthread_mutex_lock.c:68) ==18749== by 0x1E40E4: je_malloc_mutex_lock (mutex.h:77) ==18749== by 0x1E40E4: je_arena_dalloc_bin (arena.c:1804) ==18749== by 0x1F2399: je_arena_dalloc (arena.h:1162) ==18749== by 0x1F2399: je_idalloct (jemalloc_internal.h:770) ==18749== by 0x1F2399: je_idalloc (jemalloc_internal.h:793) ==18749== by 0x1F2399: quarantine_grow (quarantine.c:68) ==18749== by 0x1F2399: je_quarantine (quarantine.c:117) ==18749== by 0x1DF83A: je_isqalloc (jemalloc_internal.h:811) ==18749== by 0x1DF83A: isfree (jemalloc.c:1257) ==18749== by 0x1DF83A: je_sdallocx (jemalloc.c:1896) ==18749== by 0x117A07: heap::deallocate::h0a17c8e2da255a4a4ea (heap.rs:111) ==18749== by 0x1208E2: raw_vec::_$LT$impl$GT$::drop::drop::h16868981604614779235 (raw_vec.rs:472) ==18749== by 0x1207ED: alloc..raw_vec..RawVec$LT$fbx_direct..common..OwnedProperty$GT$::drop.5849::haf21a87197ef2e30 (in /home/larry/development/rust_progress1/last_progress1/target/debug/new-loader) ==18749== by 0x1207D5: collections..vec..Vec$LT$fbx_direct..common..OwnedProperty$GT$::drop.5846::h5a5c3b3b2f5cbdff (in /home/larry/development/rust_progress1/last_progress1/target/debug/new-loader) ==18749== by 0x1203D9: collections..vec..Vec$LT$fbx_direct..common..OwnedProperty$GT$::drop.5842::h5a5c3b3b2f5cbdff (in /home/larry/development/rust_progress1/last_progress1/target/debug/new-loader) ==18749== by 0x1276C4: fbx_direct..reader..FbxEvent::drop.6598::h0f7cc59733d5e2ce (in /home/larry/development/rust_progress1/last_progress1/target/debug/new-loader) ==18749== by 0x136832: node_loader::ignore_current_node::ignore_current_node::h13884145912320270413 (node_loader.rs:52) ==18749== by 0x135552: scene::_$LT$impl$GT$::on_child_node::on_child_node::h16000248940111934485 (scene.rs:52) ==18749== If you believe this happened as a result of a stack ==18749== overflow in your program's main thread (unlikely but ==18749== possible), you can try to increase the size of the ==18749== main thread stack using the --main-stacksize= flag. ==18749== The main thread stack size used in this run was 8388608. ==18749== ==18749== HEAP SUMMARY: ==18749== in use at exit: 66,632 bytes in 14 blocks ==18749== total heap usage: 1,043 allocs, 1,029 frees, 105,168 bytes allocated ==18749== ==18749== LEAK SUMMARY: ==18749== definitely lost: 0 bytes in 0 blocks ==18749== indirectly lost: 0 bytes in 0 blocks ==18749== possibly lost: 0 bytes in 0 blocks ==18749== still reachable: 66,632 bytes in 14 blocks ==18749== suppressed: 0 bytes in 0 blocks ==18749== Rerun with --leak-check=full to see details of leaked memory ==18749== ==18749== For counts of detected and suppressed errors, rerun with: -v ==18749== ERROR SUMMARY: 2 errors from 1 contexts (suppressed: 0 from 0) zsh: segmentation fault (core dumped) valgrind --tool=memcheck ./target/debug/new-loader # (*;_;)<(139) 2016/03/17-13:18:25@1458188305 pts/12 (git:feature/reimplement-faster-fbx-loader) # larry@veg:~lp1 $
# (*'-')<(ok) 2016/03/17-13:32:27@1458189147 pts/12 (git:feature/reimplement-faster-fbx-loader) # larry@veg:~lp1 $ JE_MALLOC_CONF=quarantine:0 valgrind --tool=memcheck ./target/debug/new-loader ==30102== Memcheck, a memory error detector ==30102== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al. ==30102== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info ==30102== Command: ./target/debug/new-loader ==30102== ==30102== ==30102== HEAP SUMMARY: ==30102== in use at exit: 0 bytes in 0 blocks ==30102== total heap usage: 38,872 allocs, 38,872 frees, 47,548,016 bytes allocated ==30102== ==30102== All heap blocks were freed -- no leaks are possible ==30102== ==30102== For counts of detected and suppressed errors, rerun with: -v ==30102== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) job: JE_MALLOC_CONF=quarantine:0 valgrind --tool=memcheck ./target/debug/new-loade User: 60.70s Kernel: 0.12s Elapsed: 60.82s CPU: 100% # (*'-')<(ok) 2016/03/17-13:33:29@1458189209 pts/12 (git:feature/reimplement-faster-fbx-loader) # larry@veg:~lp1 $
JE_MALLOC_CONF
を設定した場合の実行例やっぱ滅茶苦茶遅くなるな。
本当はmemcheckじゃなくてcallgrind使おうとしてたんだけど、正直あまり良いデータ得られなかったのでやっぱ使わなくていいや。 lifetimeに圧倒的感謝。