Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Play Rogue, visit exotic locations, meet strange creatures and kill them.


devel / comp.lang.c / Program uses less memory under Valgrind Massif

SubjectAuthor
* Program uses less memory under Valgrind MassifFrederick Gotham
`* Re: Program uses less memory under Valgrind MassifFrederick Gotham
 +- Re: Program uses less memory under Valgrind MassifKaz Kylheku
 `- Re: Program uses less memory under Valgrind MassifLew Pitcher

1
Program uses less memory under Valgrind Massif

<9c37f74b-0e57-48ee-a47d-009836d7e3c6n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16819&group=comp.lang.c#16819

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:86c3:: with SMTP id i186mr24362303qkd.151.1622722757802;
Thu, 03 Jun 2021 05:19:17 -0700 (PDT)
X-Received: by 2002:ae9:ed01:: with SMTP id c1mr8313369qkg.199.1622722757611;
Thu, 03 Jun 2021 05:19:17 -0700 (PDT)
Path: i2pn2.org!i2pn.org!paganini.bofh.team!usenet.pasdenom.info!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Thu, 3 Jun 2021 05:19:17 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=79.77.6.177; posting-account=w4UqJAoAAAAYC-PItfDbDoVGcg0yISyA
NNTP-Posting-Host: 79.77.6.177
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9c37f74b-0e57-48ee-a47d-009836d7e3c6n@googlegroups.com>
Subject: Program uses less memory under Valgrind Massif
From: cauldwel...@gmail.com (Frederick Gotham)
Injection-Date: Thu, 03 Jun 2021 12:19:17 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Frederick Gotham - Thu, 3 Jun 2021 12:19 UTC

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?

Re: Program uses less memory under Valgrind Massif

<ae9010bd-02b4-4a34-8c9a-a1ddaf2a41ebn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16820&group=comp.lang.c#16820

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:f612:: with SMTP id y18mr32850975qkj.436.1622726370091;
Thu, 03 Jun 2021 06:19:30 -0700 (PDT)
X-Received: by 2002:ac8:4756:: with SMTP id k22mr28924435qtp.193.1622726369878;
Thu, 03 Jun 2021 06:19:29 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Thu, 3 Jun 2021 06:19:29 -0700 (PDT)
In-Reply-To: <9c37f74b-0e57-48ee-a47d-009836d7e3c6n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=92.40.194.227; posting-account=w4UqJAoAAAAYC-PItfDbDoVGcg0yISyA
NNTP-Posting-Host: 92.40.194.227
References: <9c37f74b-0e57-48ee-a47d-009836d7e3c6n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ae9010bd-02b4-4a34-8c9a-a1ddaf2a41ebn@googlegroups.com>
Subject: Re: Program uses less memory under Valgrind Massif
From: cauldwel...@gmail.com (Frederick Gotham)
Injection-Date: Thu, 03 Jun 2021 13:19:30 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Frederick Gotham - Thu, 3 Jun 2021 13:19 UTC

On Thursday, June 3, 2021 at 1:19:23 PM UTC+1, Frederick Gotham wrote:
> 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.

Re: Program uses less memory under Valgrind Massif

<20210603071232.931@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16826&group=comp.lang.c#16826

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 563-365-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Program uses less memory under Valgrind Massif
Date: Thu, 3 Jun 2021 14:13:47 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <20210603071232.931@kylheku.com>
References: <9c37f74b-0e57-48ee-a47d-009836d7e3c6n@googlegroups.com>
<ae9010bd-02b4-4a34-8c9a-a1ddaf2a41ebn@googlegroups.com>
Injection-Date: Thu, 3 Jun 2021 14:13:47 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="e556596e6e8c06f7c1d51c401723ae14";
logging-data="26321"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18odxJ2oUfvwPSfJ+ieauuRqLYMTrN/Ir0="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:xWdBAK+bjyjNbHhMTl/j5aUmiNQ=
 by: Kaz Kylheku - Thu, 3 Jun 2021 14:13 UTC

On 2021-06-03, Frederick Gotham <cauldwell.thomas@gmail.com> wrote:
> On Thursday, June 3, 2021 at 1:19:23 PM UTC+1, Frederick Gotham wrote:
>> 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.

Run it under strace; you will likely see anonymous mmap calls.

Use an ordinary debugger, gdb, and put a breakpoint on that mmap.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Program uses less memory under Valgrind Massif

<s9b76g$fl1$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16828&group=comp.lang.c#16828

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.lang.c
Subject: Re: Program uses less memory under Valgrind Massif
Date: Thu, 3 Jun 2021 18:31:44 -0000 (UTC)
Organization: The Pitcher Digital Freehold
Lines: 49
Message-ID: <s9b76g$fl1$1@dont-email.me>
References: <9c37f74b-0e57-48ee-a47d-009836d7e3c6n@googlegroups.com>
<ae9010bd-02b4-4a34-8c9a-a1ddaf2a41ebn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 3 Jun 2021 18:31:44 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ff08899ec7822b4d3109119d88c6283d";
logging-data="16033"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19OlGUOdDH+QuGShVzoIrV/XIXgW+IFXo0="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:LFK1XiUJ64f1KGERPl/fUNK6/9c=
 by: Lew Pitcher - Thu, 3 Jun 2021 18:31 UTC

On Thu, 03 Jun 2021 06:19:29 -0700, Frederick Gotham wrote:

> On Thursday, June 3, 2021 at 1:19:23 PM UTC+1, Frederick Gotham wrote:
>> 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.

According to the Valgrind Massif webpage at
https://www.valgrind.org/docs/manual/ms-manual.html#ms-manual.not-measured,
"[B]y default Massif measures only heap memory, i.e. memory allocated with
malloc, calloc, realloc, memalign, new, new[], and a few other, similar
functions. (And it can optionally measure stack memory, of course.)
This means it does not directly measure memory allocated with lower-level
system calls such as mmap, mremap, and brk. ... Furthermore, a client
program may use these lower-level system calls directly to allocate memory.
By default, Massif does not measure these. Nor does it measure the size of
code, data and BSS segments. Therefore, the numbers reported by Massif may
be significantly smaller than those reported by tools such as top that measure
a program's total size in memory."

So, we know that Valgrind Massif DOESN'T measure memory directly allocated by
mmap(2) calls, /and/ the difference between what /you/ measure as memory usage,
and what Valgrind Massif measures as memory usage can be accounted for by a
couple of mmapped memory blocks.

My guess is that the Valgrind Massif numbers are off, and that your process
uses 157Mb whether run on it's own /or/ under Valgrind Massif. And, that memory
difference comes from something in your execution chain (your code, the TCP/IP
stack code, the ALSA stack code, or other support code) performing naked mmap(2)
calls.

HTH
--
Lew Pitcher
"In Skills, We Trust"

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor