public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Cc: Norbert Manthey <nmanthey@conp-solutions.com>,
	Guillaume Morin <guillaume@morinfr.org>,
	Siddhesh Poyarekar <siddhesh@sourceware.org>
Subject: [PATCH v4 7/7] malloc: Enable huge page support on main arena
Date: Mon, 30 Aug 2021 15:52:15 -0300	[thread overview]
Message-ID: <20210830185215.449572-8-adhemerval.zanella@linaro.org> (raw)
In-Reply-To: <20210830185215.449572-1-adhemerval.zanella@linaro.org>

This patch adds support huge page support on main arena allocation,
enable with tunable glibc.malloc.hugetlb=2.  The patch essentially
disable the __glibc_morecore() sbrk() call (similar when memory
tag does when sbrk() call does not support it) and fallback to
default page size if the memory allocation fails.

Checked on x86_64-linux-gnu.
---
 malloc/arena.c    |  4 ++++
 malloc/malloc.c   | 12 ++++++++++--
 malloc/morecore.c |  2 --
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/malloc/arena.c b/malloc/arena.c
index 81dc2f93d1..0d38cad9b8 100644
--- a/malloc/arena.c
+++ b/malloc/arena.c
@@ -357,6 +357,10 @@ ptmalloc_init (void)
 # endif
   TUNABLE_GET (mxfast, size_t, TUNABLE_CALLBACK (set_mxfast));
   TUNABLE_GET (hugetlb, int32_t, TUNABLE_CALLBACK (set_hugetlb));
+  if (mp_.hp_pagesize > 0)
+    /* Force mmap() for main arena instead of sbrk(), so hugepages are
+       explicitly used.  */
+    __always_fail_morecore = true;
 #else
   if (__glibc_likely (_environ != NULL))
     {
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 3421a0b5da..616aaf9e59 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -2742,8 +2742,16 @@ sysmalloc (INTERNAL_SIZE_T nb, mstate av)
              segregated mmap region.
            */
 
-	  char *mbrk = sysmalloc_mmap_fallback (&size, nb, old_size, pagesize,
-						MMAP_AS_MORECORE_SIZE, 0, av);
+	  char *mbrk = MAP_FAILED;
+#if HAVE_TUNABLES
+	  if (mp_.hp_pagesize > 0)
+	    mbrk = sysmalloc_mmap_fallback (&size, nb, old_size,
+					    mp_.hp_pagesize, mp_.hp_pagesize,
+					    mp_.hp_flags, av);
+#endif
+	  if (mbrk == MAP_FAILED)
+	    mbrk = sysmalloc_mmap_fallback (&size, nb, old_size, pagesize,
+					    MMAP_AS_MORECORE_SIZE, 0, av);
 	  if (mbrk != MAP_FAILED)
 	    {
 	      /* We do not need, and cannot use, another sbrk call to find end */
diff --git a/malloc/morecore.c b/malloc/morecore.c
index 8168ef158c..1ace85a37d 100644
--- a/malloc/morecore.c
+++ b/malloc/morecore.c
@@ -15,9 +15,7 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#if defined(SHARED) || defined(USE_MTAG)
 static bool __always_fail_morecore = false;
-#endif
 
 /* Allocate INCREMENT more bytes of data space,
    and return the start of data space, or NULL on errors.
-- 
2.30.2


      parent reply	other threads:[~2021-08-30 18:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-30 18:52 [PATCH v4 0/7] malloc: Improve Huge Page support Adhemerval Zanella
2021-08-30 18:52 ` [PATCH v4 1/7] malloc: Add madvise support for Transparent Huge Pages Adhemerval Zanella
2021-08-30 18:52 ` [PATCH v4 2/7] malloc: Add THP/madvise support for sbrk Adhemerval Zanella
2021-08-30 18:52 ` [PATCH v4 3/7] malloc: Move mmap logic to its own function Adhemerval Zanella
2021-08-30 18:52 ` [PATCH v4 4/7] malloc: Add Huge Page support for mmap() Adhemerval Zanella
2021-08-30 18:52 ` [PATCH v4 5/7] malloc: Add huge page support to arenas Adhemerval Zanella
2021-08-30 18:52 ` [PATCH v4 6/7] malloc: Move MORECORE fallback mmap to sysmalloc_mmap_fallback Adhemerval Zanella
2021-08-30 18:52 ` Adhemerval Zanella [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=20210830185215.449572-8-adhemerval.zanella@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=guillaume@morinfr.org \
    --cc=libc-alpha@sourceware.org \
    --cc=nmanthey@conp-solutions.com \
    --cc=siddhesh@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).