public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: DJ Delorie <dj@redhat.com>
To: Patrick McGehearty <patrick.mcgehearty@oracle.com>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH v2] Remove upper limit on tunable MALLOC_MMAP_THRESHOLD
Date: Tue, 09 Nov 2021 19:36:07 -0500	[thread overview]
Message-ID: <xnr1bo6e4o.fsf@greed.delorie.com> (raw)
In-Reply-To: <03e480f8-c6c5-3247-5726-8982b02123af@oracle.com>

Patrick McGehearty <patrick.mcgehearty@oracle.com> writes:
> If a chunk smaller than the mmap_threshold is requested,
> then MORECORE [typically sbrk()] is called and HEAP_MAX
> is not considered by the malloc code.  Heaps are only used
> for mmap()ed allocations, not sbrk()'ed allocations,
> so far as I can tell in reading the code.

There are two types of arenas: the sbrk-based arena (limited in size by
ulimit), and zero or more mmap-based arenas (limited by HEAP_MAX).  The
sbrk-based one is used when the program is single threaded; the
mmap-based ones are used when the program is multi-threaded.  Your
original email made it sound like you were concerned with the
multi-threaded case, where the mmap-based heaps are used.

In either case, a malloc() request may be satisfied by pulling a free
chunk out of either type of arena (possibly growing the arena if needed
and possible), or by calling mmap() directly to satisfy that one
request.

I would think mmap_threshold should still apply if you're using the
mmap'd heaps, so you can reserve the heaps for smaller chunks, but that
is meaningless if mmap_threshold is larger than the heap size.  I could
not find an obvious place in the code where mmap_threshold is used to
bypass the mmap'd heaps, though.

So while I have no problems with allowing larger mmap_threshold settings
for the sbrk-based arena, I still wonder what happens to requests that
go through an mmap-based arena that are larger than HEAP_MAX but still
under the mmap_threshold.

Of course, I've spent more time typing this response than it would take
to write a test program and see what happens ;-)

> It might be desirable to also allow HEAP_MAX to be set by
> the user before the first call to malloc, but I see that
> as a separate task.

Our current implementation requires that the heap size be a compile-time
constant, but... yeah.


  reply	other threads:[~2021-11-10  0:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-01 21:48 Patrick McGehearty
2021-11-02  0:27 ` DJ Delorie
2021-11-09 22:33   ` Patrick McGehearty
2021-11-10  0:36     ` DJ Delorie [this message]
2021-11-25  0:52       ` Patrick McGehearty
2021-11-29 20:42         ` DJ Delorie
2021-11-29 21:35           ` Patrick McGehearty
2021-12-07 19:51           ` Patrick McGehearty
2021-12-07 20:35             ` DJ Delorie

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=xnr1bo6e4o.fsf@greed.delorie.com \
    --to=dj@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=patrick.mcgehearty@oracle.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).