[Rd] Issue with memory deallocation/fragmentation on systems which use glibc

Dmitriy Selivanov selivanov.dmitriy at gmail.com
Fri Jul 28 12:11:48 CEST 2017


I would like to submit issue to wishlist at the bug reporting system (
https://www.r-project.org/bugs.html) based on my emails. Unfortunately I
don't have bugzilla account. Can someone from R-core help to obtain it? (I
see that I should *"ask an R Core member to add you manually to R’s
Bugzilla members"*)

   - https://stat.ethz.ch/pipermail/r-devel/2017-June/074487.html
   - https://stat.ethz.ch/pipermail/r-devel/2017-June/074500.html
   - https://stat.ethz.ch/pipermail/r-devel/2017-July/074614.html


2017-07-09 13:12 GMT+03:00 Dmitriy Selivanov <selivanov.dmitriy at gmail.com>:

> Dear R-devel mailing list and especially R-core, is there any chance to
> receive feedback on issue I described in previous emails? I would consider
> such behaviour as a bug.
>
> As a work-around I've created small "clean-up" function:
>
> malloc_trim_finalizer = function(e) {
>   res = NULL
>   if(R.version$os == "linux-gnu") {
>     flog.debug("Calling malloc_trim(0L) to trigger glibc to release
> memory\n")
>     res = malloc_trim(0L)
>   }
>   res
> }
>
> And at the end of each function which produce a lot of intermediate small
> objects I provide it to reg.finalizer():
> some_function = function(...) {
>   # do some useful work
>   result = TRUE
>   # register finalizer
>   e = environment()
>   reg.finalizer(e, malloc_trim_finalizer)
>   return(result)
> }
>
> 2017-06-22 11:12 GMT+04:00 Dmitriy Selivanov <selivanov.dmitriy at gmail.com>
> :
>
>> A few additional details. According to Linux Programmer's Manual
>>
>>    1. http://man7.org/linux/man-pages/man3/mallopt.3.html
>>    2. http://man7.org/linux/man-pages/man3/malloc_trim.3.html
>>
>> And if I understood everything correctly `free` could trigger
>> `malloc_trim` based on value of several environment variables -
>> MALLOC_TOP_PAD_ and MALLOC_TRIM_THRESHOLD_. However setting them as low as
>> 1 or 0 doesn't have any effect (but as I wrote in previous email manual
>> call of `malloc_trim` helps to release memory).
>>
>
>
>
> --
> Regards
> Dmitriy Selivanov
>



-- 
Regards
Dmitriy Selivanov

	[[alternative HTML version deleted]]



More information about the R-devel mailing list