From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1791) id 51E0D3858005; Wed, 29 Nov 2023 12:31:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 51E0D3858005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1701261073; bh=thJjgQsbaU1+CCaInmkHWz3V61KLWW0qxaSPiJQaxSo=; h=From:To:Subject:Date:From; b=nSOccse4GojdVJzqvMKvGTEqLN2MmlHQwAeu0dzqKJXj9QCnkjJmIaaImyhiky4hC tsulr7RL78RCg8JDkTcLu8Xdf7gldo7kVqhrjsLQB9uNYUls6jrHOaT8MRKNgVykBo af4YCuSsrzDD0Ilc/6wryTxGmcV9Eb6Iw17ZSOTU= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Adhemerval Zanella To: glibc-cvs@sourceware.org Subject: [glibc] malloc: Improve MAP_HUGETLB with glibc.malloc.hugetlb=2 X-Act-Checkin: glibc X-Git-Author: Adhemerval Zanella X-Git-Refname: refs/heads/master X-Git-Oldrev: a4c3f5f46e850c977cda81c251036475aab8313c X-Git-Newrev: bc6d79f4ae99206e7ec7d6a8c5abf26cdefc8bff Message-Id: <20231129123113.51E0D3858005@sourceware.org> Date: Wed, 29 Nov 2023 12:31:13 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=bc6d79f4ae99206e7ec7d6a8c5abf26cdefc8bff commit bc6d79f4ae99206e7ec7d6a8c5abf26cdefc8bff Author: Adhemerval Zanella Date: Thu Nov 23 14:29:15 2023 -0300 malloc: Improve MAP_HUGETLB with glibc.malloc.hugetlb=2 Even for explicit large page support, allocation might use mmap without the hugepage bit set if the requested size is smaller than mmap_threshold. For this case where mmap is issued, MAP_HUGETLB is set iff the allocation size is larger than the used large page. To force such allocations to use large pages, also tune the mmap_threhold (if it is not explicit set by a tunable). This forces allocation to follow the sbrk path, which will fall back to mmap (which will try large pages before galling back to default mmap). Checked on x86_64-linux-gnu. Reviewed-by: DJ Delorie Tested-by: Zhangfei Gao Diff: --- malloc/arena.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/malloc/arena.c b/malloc/arena.c index a1a75e5a2b..c73f68890d 100644 --- a/malloc/arena.c +++ b/malloc/arena.c @@ -312,10 +312,17 @@ ptmalloc_init (void) # endif TUNABLE_GET (mxfast, size_t, TUNABLE_CALLBACK (set_mxfast)); TUNABLE_GET (hugetlb, size_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; + { + /* Force mmap for main arena instead of sbrk, so MAP_HUGETLB is always + tried. Also tune the mmap threshold, so allocation smaller than the + large page will also try to use large pages by falling back + to sysmalloc_mmap_fallback on sysmalloc. */ + if (!TUNABLE_IS_INITIALIZED (mmap_threshold)) + do_set_mmap_threshold (mp_.hp_pagesize); + __always_fail_morecore = true; + } } /* Managing heaps and arenas (for concurrent threads) */