From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 8AB3E385840E; Fri, 1 Mar 2024 21:37:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8AB3E385840E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1709329037; bh=1IsxNuoNYXd/Vcnzefcij1KDtqPRebGYRk6ed8eNXMw=; h=From:To:Subject:Date:From; b=WBxfqRhBeo/EKvLmn40AJ4uR8Y38pcs/O1Y/MQ9oQLPbBpkSIWh2KQaTXNRAAhyxz uEVk+d4d4j+cADG8qcG4qA5t2ngsIeY7LgsHN2eulPJ7NR27TVsKM+QdJiIm9lneYG 0OI1hafqZcHl8byNHF9x2oLpSRpEwCXHZyFIrUGg= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/main] Cygwin: cygheap: compute bucket instead of looping over it X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/main X-Git-Oldrev: 5d3e79ec6bb7362cb56765025a5ca756da41a293 X-Git-Newrev: abb532a87ff6ed37f6ee2c8a58c65178a15aa345 Message-Id: <20240301213717.8AB3E385840E@sourceware.org> Date: Fri, 1 Mar 2024 21:37:17 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Dabb532a87ff= 6ed37f6ee2c8a58c65178a15aa345 commit abb532a87ff6ed37f6ee2c8a58c65178a15aa345 Author: Corinna Vinschen AuthorDate: Fri Mar 1 22:27:40 2024 +0100 Commit: Corinna Vinschen CommitDate: Fri Mar 1 22:35:22 2024 +0100 Cygwin: cygheap: compute bucket instead of looping over it =20 Start at index 0 and use 32 bytes as minimal allocation size. Reduce NBUCKETS, we don't have such big objects on the cygheap anyway. =20 Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/local_includes/cygheap.h | 2 +- winsup/cygwin/mm/cygheap.cc | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/winsup/cygwin/local_includes/cygheap.h b/winsup/cygwin/local_i= ncludes/cygheap.h index b6acdf7f18b7..9edd61c28abd 100644 --- a/winsup/cygwin/local_includes/cygheap.h +++ b/winsup/cygwin/local_includes/cygheap.h @@ -487,7 +487,7 @@ struct mini_cygheap cygheap_locale locale; }; =20 -#define NBUCKETS 40 +#define NBUCKETS 32 =20 struct threadlist_t { diff --git a/winsup/cygwin/mm/cygheap.cc b/winsup/cygwin/mm/cygheap.cc index c763a0967388..4cc851716fbe 100644 --- a/winsup/cygwin/mm/cygheap.cc +++ b/winsup/cygwin/mm/cygheap.cc @@ -264,15 +264,15 @@ init_cygheap::init_installation_root () =20 /* Initialize bucket_val. The value is the max size of a block fitting into the bucket. The values are powers of two and their - medians: 24, 32, 48, 64, ... + medians: 32, 48, 64, 96, ... The idea is to have better matching bucket sizes (not wasting space) without trading in performance compared to the old powers of 2 method. */ static const uint32_t bucket_val[NBUCKETS] =3D { - 0, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048, - 3072, 4096, 6144, 8192, 12288, 16384, 24576, 32768, 49152, 65536, 98304, - 131072, 196608, 262144, 393216, 524288, 786432, 1048576, 1572864, 209715= 2, - 3145728, 4194304, 6291456, 8388608, 12582912 + 32, 48, 64, 96, 128, 192, 256, 384, + 512, 768, 1024, 1536, 2048, 3072, 4096, 6144, + 8192, 12288, 16384, 24576, 32768, 49152, 65536, 98304, + 131072, 196608, 262144, 393216, 524288, 786432, 1048576, 1572864 }; =20 void @@ -355,11 +355,15 @@ static void * _cmalloc (unsigned size) { _cmalloc_entry *rvc; - unsigned b; + unsigned b =3D 0; =20 /* Calculate "bit bucket". */ - for (b =3D 1; b < NBUCKETS && bucket_val[b] < size; b++) - continue; + if (size > bucket_val[0]) + { + const unsigned clz =3D __builtin_clzl (size - 1); + b =3D (59 - clz) << 1; + b -=3D !((size - 1) & (1 << (62 - clz))); + } if (b >=3D NBUCKETS) return NULL;