Discussion:
Program uses less memory under Valgrind Massif
(too old to reply)
Frederick Gotham
2021-06-03 12:20:51 UTC
Permalink
I have a Linux program that starts out with one thread, and it uses 88 kB of RAM.

It then spawns a 2nd thread for a TCP connection, and a 3rd thread for sending digital audio samples to ALSA.

When the 2nd and 3rd thread start together, the memory usage jumps from 88 kB to 157 MB. I don't know where this extra memory is being allocated.

So next I run my program under Valgrind Massif, but my program no longer spikes from 88 kB to 157 MB. My program runs fine under Valgrind Massif without any memory spike -- it stays constant at about 88 kB.

Anyone seen this kind of thing before?
Frederick Gotham
2021-06-03 13:19:58 UTC
Permalink
Post by Frederick Gotham
I have a Linux program that starts out with one thread, and it uses 88 kB of RAM.
It then spawns a 2nd thread for a TCP connection, and a 3rd thread for sending digital audio samples to ALSA.
When the 2nd and 3rd thread start together, the memory usage jumps from 88 kB to 157 MB. I don't know where this extra memory is being allocated.
So next I run my program under Valgrind Massif, but my program no longer spikes from 88 kB to 157 MB. My program runs fine under Valgrind Massif without any memory spike -- it stays constant at about 88 kB.
Anyone seen this kind of thing before?
I used 'pmap' just now on the process when it has jumped up to 157 MB, and I see:

0000007f80021000 65404K ---p [ anon ]
0000007f88021000 65404K ---p [ anon ]

There are two allocations of ~64 MB each. I wonder if it's 64 MB for each thread I spawn? I have one guy telling me it's probably glib.
Scott Lurndal
2021-06-03 14:00:32 UTC
Permalink
Post by Frederick Gotham
I have a Linux program that starts out with one thread, and it uses 88 kB of RAM.
How do you know that it uses 88kb of RAM? Where did
you find that number? Is it RSS? VAS? RSS+SWAP?
Lew Pitcher
2021-06-03 18:43:53 UTC
Permalink
Post by Frederick Gotham
I have a Linux program that starts out with one thread, and it uses 88 kB of RAM.
[snip]
Post by Frederick Gotham
Anyone seen this kind of thing before?
You multi-posted your question to comp.lang.c, instead of cross-posting it.
You can find my reply, such as it is, in comp.lang.c.

Short answer: Valgrind Massif doesn't account for memory that's directly
allocated through naked mmap(2) calls. My guess is that your process has
some code (either in /your/ code, or in the support logic you invoke)
that allocates storage directly through mmap(2), and that the ACTUAL
memory usage DOES NOT vary between the unmonitored run and the Valgrind run.
--
Lew Pitcher
"In Skills, We Trust"
Loading...