public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Siddhesh Poyarekar <siddhesh@gotplt.org>
To: Florian Weimer <fweimer@redhat.com>, libc-alpha@sourceware.org
Subject: Re: [PATCH] malloc: Do not use MAP_NORESERVE to allocate heap segments
Date: Mon, 15 Aug 2022 09:14:54 -0400	[thread overview]
Message-ID: <6a5f85aa-9b7c-01e2-fe02-dc2da3ccf284@gotplt.org> (raw)
In-Reply-To: <87fsi4hb2m.fsf@oldenburg.str.redhat.com>



On 2022-08-10 02:22, Florian Weimer via Libc-alpha wrote:
> Address space for heap segments is reserved in a mmap call with
> MAP_ANONYMOUS | MAP_PRIVATE and protection flags PROT_NONE.  This
> reservation does not count against the RSS limit of the process or
> system.  Backing memory is allocated using mprotect in alloc_new_heap
> and grow_heap, and at this point, the allocator expects the kernel
> to provide memory (subject to memory overcommit).
> 
> The SIGSEGV that might generate due to MAP_NORESERVE (according to
> the mmap manual page) does not seem to occur in practice, it's always
> SIGKILL from the OOM killer.  Even if there is a way that SIGSEGV
> could be generated, it is confusing to applications that this only
> happens for secondary heaps, not for large mmap-based allocations,
> and not for the main arena.
> 
> ---
>   malloc/arena.c  | 5 +----
>   malloc/malloc.c | 4 ----
>   2 files changed, 1 insertion(+), 8 deletions(-)

LGTM.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>

> 
> diff --git a/malloc/arena.c b/malloc/arena.c
> index defd25c8a6..074ecbc09f 100644
> --- a/malloc/arena.c
> +++ b/malloc/arena.c
> @@ -559,16 +559,13 @@ new_heap (size_t size, size_t top_pad)
>   #if HAVE_TUNABLES
>     if (__glibc_unlikely (mp_.hp_pagesize != 0))
>       {
> -      /* MAP_NORESERVE is not used for huge pages because some kernel may
> -	 not reserve the mmap region and a subsequent access may trigger
> -	 a SIGBUS if there is no free pages in the pool.  */
>         heap_info *h = alloc_new_heap (size, top_pad, mp_.hp_pagesize,
>   				     mp_.hp_flags);
>         if (h != NULL)
>   	return h;
>       }
>   #endif
> -  return alloc_new_heap (size, top_pad, GLRO (dl_pagesize), MAP_NORESERVE);
> +  return alloc_new_heap (size, top_pad, GLRO (dl_pagesize), 0);
>   }
>   
>   /* Grow a heap.  size is automatically rounded up to a
> diff --git a/malloc/malloc.c b/malloc/malloc.c
> index 914052eb69..29fa71b3b2 100644
> --- a/malloc/malloc.c
> +++ b/malloc/malloc.c
> @@ -1110,10 +1110,6 @@ static mchunkptr mremap_chunk(mchunkptr p, size_t new_size);
>   # define MAP_ANONYMOUS MAP_ANON
>   #endif
>   
> -#ifndef MAP_NORESERVE
> -# define MAP_NORESERVE 0
> -#endif
> -
>   #define MMAP(addr, size, prot, flags) \
>    __mmap((addr), (size), (prot), (flags)|MAP_ANONYMOUS|MAP_PRIVATE, -1, 0)
>   
> 

      reply	other threads:[~2022-08-15 13:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-10  6:22 Florian Weimer
2022-08-15 13:14 ` Siddhesh Poyarekar [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=6a5f85aa-9b7c-01e2-fe02-dc2da3ccf284@gotplt.org \
    --to=siddhesh@gotplt.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /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).