Thanks for providing the fix. This is most likely the cause, as my own test program is essentially the same as yours, except that I collect the samples separately rather than checking for the memory decrease immediately.
Alex. On Wednesday, December 16, 2020 at 10:11:25 AM UTC+8 Matthew Flatt wrote: > At Tue, 15 Dec 2020 17:00:42 -0800 (PST), Alex Harsanyi wrote: > > I am trying to use `(current-process-memory 'cumulative)` to determine > the > > total memory used by an application, including the memory that was > > reclaimed by the garbage collector. I would expect the results from the > > call to be constantly increasing, and this is indeed the case at a > "global" > > scale: [...] > > > > However, occasionally, there seems to be a drop in the reported memory > use, > > I'm able to replicate that with > > #lang racket > > (define (work n) > (length (let loop ([n n]) > (if (zero? n) > '() > (cons (make-vector n) (loop (sub1 n))))))) > > (let loop ([u (current-memory-use 'cumulative)]) > (work (random 1000)) > (let ([u2 (current-memory-use 'cumulative)]) > (if (u2 . < . u) > (error "oops") > (loop u2)))) > > which reports an error fairly quickly for me. > > > The implementation of > > (current-process-memory 'cumulative) > > is > > (+ (bytes-deallocated) (bytes-allocated)) > > It's possible for a GC to happen at the start of the call to > `bytes-allocated`, which I think would produced the blip you see (i.e., > there could be bytes not yet attributed to `bytes-deallocated`, but > they get shifted there before `bytes-allocated` runs). > > The solution is make that arithmetic atomic with respect to a GC by > disabling signals around the arithmetic. I've pushed that change, and > my test program doesn't error anymore, at least. > > > Matthew > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/1a12cc80-caef-440a-877d-556c71dfe1e1n%40googlegroups.com.

