public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: Martin Beynon <mebeyn@gmail.com>
To: "Carlos O'Donell" <carlos@redhat.com>
Cc: Paul Pluzhnikov <ppluzhnikov@google.com>, libc-help@sourceware.org
Subject: Re: fopen from within a pthread
Date: Mon, 04 Jun 2018 16:13:00 -0000	[thread overview]
Message-ID: <CADpW=+3vaD0-9hn72STF-kP3LCOeHSxPKY2wHmGcecZAV3mncQ@mail.gmail.com> (raw)
In-Reply-To: <36777c73-b695-0438-a916-86caae518128@redhat.com>

Thanks Carlos (and Paul),

I am aware of this...what I wasn't aware of was thread specific arenas.

However that said and understood...it does generate a couple of questions
in my mind:

1) Why doesn't the main program [thread] allocate a 64MB arena? In that
little test program I posted the heap is only 132KB; which leaves me to
wonder why can't the same approach be used for child threads? If I reduce
the MALLOC_ARENA_MAX to 1, the [virtual] memory consumption is the same for
both tests (fopen in thread or in main)...

2) Why can't the initial / default [thread-specific] arena size be changed?

Cheers,

Martin

On 4 June 2018 at 15:38, Carlos O'Donell <carlos@redhat.com> wrote:

> On 06/02/2018 06:48 PM, Paul Pluzhnikov via libc-help wrote:
> > On Sat, Jun 2, 2018 at 3:31 PM Martin Beynon <mebeyn@gmail.com> wrote:
> >>
> >> Is this erroneous behaviour, or can this be explained in some way?
> >
> >
> > There is nothing erroneous about it.
> >
> > What you are observing is the creation of thread-specific arena, from
> > which malloc will return memory to the new thread.
> >
> > GLIBC uses thread-specific arenas to avoid having to lock malloc
> > internal structures when multiple threads allocate and free memory.
> > Additional info can be found here:
> > https://sourceware.org/glibc/wiki/MallocInternals
>
> Also note that VM size is not the same as RSS.
>
> The new thread arena, usually ~64MiB in size on 64-bit, is only taking
> up VM space, but not consuming any real memory (RSS).
>
> Therefore this is just an accounting procedure. Real memory will only
> be used as you dirty the pages.
>
> Cheers,
> Carlos.
>
>

      reply	other threads:[~2018-06-04 16:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-02 22:30 Martin Beynon
2018-06-02 22:49 ` Paul Pluzhnikov via libc-help
2018-06-04 14:38   ` Carlos O'Donell
2018-06-04 16:13     ` Martin Beynon [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADpW=+3vaD0-9hn72STF-kP3LCOeHSxPKY2wHmGcecZAV3mncQ@mail.gmail.com' \
    --to=mebeyn@gmail.com \
    --cc=carlos@redhat.com \
    --cc=libc-help@sourceware.org \
    --cc=ppluzhnikov@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).