-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ci] [R-package] Fix memory leaks found by valgrind #3443
Changes from all commits
52a981e
d8dff36
6af267d
7718339
5fcd2fe
1d3762e
3f217a3
f5729ed
e80b68d
d8b9a84
4f20e36
1c65707
53f82f5
5828e43
74676c3
7a91f40
e64183c
23290db
4355c75
3179f4e
bd53bfe
d53c9eb
e4fff30
b7b0bf3
ec77314
78a66c8
70caf8e
ec6ee58
24b9513
e93db3a
d621d5f
c0e9219
a45ec0a
650cb32
ba3ee79
1daf3c0
e5c6bf1
d91c9ff
a55801c
ef74a8f
432bf22
3a24bb6
5bcf90b
7221adb
a024e5c
a1e2b59
9e3d97a
767938b
11874c7
4e30578
5f888a9
e9343f1
66aeb47
25d2ff9
c1eeb58
77f2c81
e6dfaca
6fb20eb
020ffae
06f783e
350e330
5dd74aa
2164ba8
14cb184
a35ffb3
af1bbf7
a2faca1
d865182
d7e7a0c
9526762
cbbbd4d
b946388
b03d863
974ab17
44afb1d
cefb3dd
d8856bd
0374e87
e9c46aa
5d435f6
265400c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/bin/bash | ||
|
||
cd R-package/tests | ||
|
||
ALL_LOGS_FILE="out.log" | ||
VALGRIND_LOGS_FILE="valgrind-logs.log" | ||
|
||
RDvalgrind \ | ||
--no-readline \ | ||
--vanilla \ | ||
-d "valgrind --tool=memcheck --leak-check=full --track-origins=yes" \ | ||
-f testthat.R \ | ||
2>&1 > ${ALL_LOGS_FILE} || exit -1 | ||
|
||
cat ${ALL_LOGS_FILE} | ||
|
||
cat ${ALL_LOGS_FILE} | grep -E "^\=" > ${VALGRIND_LOGS_FILE} | ||
|
||
bytes_definitely_lost=$( | ||
cat ${VALGRIND_LOGS_FILE} \ | ||
| grep -E "definitely lost\: .*" \ | ||
| sed 's/^.*definitely lost\: \(.*\) bytes.*$/\1/' \ | ||
| tr -d "," | ||
) | ||
if [[ ${bytes_definitely_lost} -gt 0 ]]; then | ||
echo "valgrind found ${bytes_definitely_lost} bytes definitely lost" | ||
exit -1 | ||
fi | ||
|
||
bytes_indirectly_lost=$( | ||
cat ${VALGRIND_LOGS_FILE} \ | ||
| grep -E "indirectly lost\: .*" \ | ||
| sed 's/^.*indirectly lost\: \(.*\) bytes.*$/\1/' \ | ||
| tr -d "," | ||
) | ||
if [[ ${bytes_indirectly_lost} -gt 0 ]]; then | ||
echo "valgrind found ${bytes_indirectly_lost} bytes indirectly lost" | ||
exit -1 | ||
fi | ||
|
||
# one error caused by a false positive between valgrind and openmp is allowed | ||
# ==1312== 352 bytes in 1 blocks are possibly lost in loss record 146 of 2,458 | ||
# ==1312== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) | ||
# ==1312== by 0x40149CA: allocate_dtv (dl-tls.c:286) | ||
# ==1312== by 0x40149CA: _dl_allocate_tls (dl-tls.c:532) | ||
# ==1312== by 0x5702322: allocate_stack (allocatestack.c:622) | ||
# ==1312== by 0x5702322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) | ||
# ==1312== by 0x56D0DDA: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0) | ||
# ==1312== by 0x56C88E0: GOMP_parallel (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0) | ||
# ==1312== by 0x154351B8: LGBM_DatasetCreateFromCSC (c_api.cpp:1286) | ||
# ==1312== by 0x1545789C: LGBM_DatasetCreateFromCSC_R (lightgbm_R.cpp:91) | ||
# ==1312== by 0x4941E2F: R_doDotCall (dotcode.c:634) | ||
# ==1312== by 0x494CCC6: do_dotcall (dotcode.c:1281) | ||
# ==1312== by 0x499FB01: bcEval (eval.c:7078) | ||
# ==1312== by 0x498B67F: Rf_eval (eval.c:727) | ||
# ==1312== by 0x498E414: R_execClosure (eval.c:1895) | ||
bytes_possibly_lost=$( | ||
cat ${VALGRIND_LOGS_FILE} \ | ||
| grep -E "possibly lost\: .*" \ | ||
| sed 's/^.*possibly lost\: \(.*\) bytes.*$/\1/' \ | ||
| tr -d "," | ||
) | ||
if [[ ${bytes_possibly_lost} -gt 352 ]]; then | ||
echo "valgrind found ${bytes_possibly_lost} bytes possibly lost" | ||
exit -1 | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: R valgrind tests | ||
|
||
on: | ||
pull_request_review_comment: | ||
types: [created] | ||
|
||
jobs: | ||
test-r-valgrind: | ||
name: r-package (ubuntu-latest, R-devel, valgrind) | ||
if: github.event.comment.body == '/gha run r-valgrind' && contains('OWNER,MEMBER,COLLABORATOR', github.event.comment.author_association) | ||
timeout-minutes: 120 | ||
runs-on: ubuntu-latest | ||
container: wch1/r-debug | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v1 | ||
with: | ||
fetch-depth: 5 | ||
submodules: true | ||
- name: Install packages | ||
shell: bash | ||
run: | | ||
RDscriptvalgrind -e "install.packages(c('R6', 'data.table', 'jsonlite', 'testthat'), repos = 'https://cran.r-project.org')" | ||
sh build-cran-package.sh | ||
RDvalgrind CMD INSTALL --preclean --install-tests lightgbm_*.tar.gz || exit -1 | ||
- name: Run tests with valgrind | ||
shell: bash | ||
run: ./.ci/test_r_package_valgrind.sh |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -393,7 +393,7 @@ std::string GBDT::SaveModelToString(int start_iteration, int num_iteration, int | |
ss << loaded_parameter_ << "\n"; | ||
ss << "end of parameters" << '\n'; | ||
} | ||
return ss.str(); | ||
return std::move(ss.str()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @guolinke @jameslamb I just noticed that
I wonder is there any way to avoid both valgrind error and compilation warning? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. huh I'm not sure! Think @guolinke will have to answer this one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In c++11, the compliers should be able to auto move the "local" object by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I also saw these warnings with ordinary Clang on Ubuntu. |
||
} | ||
|
||
bool GBDT::SaveModelToFile(int start_iteration, int num_iteration, int feature_importance_type, const char* filename) const { | ||
|
@@ -618,7 +618,7 @@ std::vector<double> GBDT::FeatureImportance(int num_iteration, int importance_ty | |
} else { | ||
Log::Fatal("Unknown importance type: only support split=0 and gain=1"); | ||
} | ||
return feature_importances; | ||
return std::move(feature_importances); | ||
} | ||
|
||
} // namespace LightGBM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/gha run r-valgrind-tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ this comment triggered this: https://github.com/microsoft/LightGBM/runs/1262655120?check_suite_focus=true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this succeeded! https://github.com/microsoft/LightGBM/runs/1262655120?check_suite_focus=true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/gha run r-valgrind
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/gha run-r-valgrind
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ @StrikerRUS notice that this comment I just left triggered a run that was skipped, because it wasn't part of a review:
https://github.com/microsoft/LightGBM/actions/runs/312992159
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/gha run r-valgrind
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ but this comment triggered a real run because it was part of a review
https://github.com/microsoft/LightGBM/actions/runs/312993170
I see now that I am able to keep responding to a thread with review comments as long as it's on the "Files Changed" tab (like you mentioned), so I think it's ok!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jameslamb
Please notice that
/gha run-r-valgrind
!=/gha run r-valgrind