furrer-lab / r-containers

GNU General Public License v3.0
1 stars 0 forks source link

Container image for tracking memory usage #29

Closed j-i-l closed 2 weeks ago

j-i-l commented 2 months ago

For packages that implement some functionality in C/C++ code there is always a risk of errors in memory allocation and reading/writing outside of arrays.

Several tools allow to identify issues with memory usage which is especially useful given that an improper handling of memory allocation and access might not always become apparent when using an R package that ships with some C/C++ code.

CRAN provides an overview of the tools they use and recommend using when tracking memory usage:

https://cran.r-project.org/doc/manuals/R-exts.html#Checking-memory-access-1

To Do

We want to build an image that provides (most of) the tools recommended by CRAN to identify and track common memory-usage related errors in R packages.

j-i-l commented 2 months ago

One option would be to build R from source for this container and configure it with --enable-strict-barrier as described in the docs about memory tracking.

Similarly, for valgrind:

The configure option is --with-valgrind-instrumentation=level, where level is 0, 1 or 2. Level 0 is the default and does not add anything. Level 1 will detect some uses128 of uninitialised memory and has little impact on speed (compared to level 0). Level 2 will detect many other memory-use bugs129 but make R much slower when running under valgrind.

j-i-l commented 2 months ago

The image should also contain the binary for DrMemory (drmemory.org)

Which needs libundwind8

j-i-l commented 2 months ago

A good reference for the construction of this container image might be https://github.com/r-hub/r-minimal/tree/master

j-i-l commented 2 months ago

Use the valgrind image from r-hub as initial and follow the same procedure => container image for memory checks.