From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 66F3A385AC2D; Fri, 28 Oct 2022 15:02:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 66F3A385AC2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666969342; bh=hR/sbpVanWSEVODnn7cRhwkus/9z0Kua9K8Xc+MIAAY=; h=From:To:Subject:Date:From; b=oiU8+UiqY9mF059enK3UUJkHGdmPmigcb8E/Nfo148WznyFFE8xEJQu/uuU6yJyaf np1qbFc189UAOppoOr+PfKNQjBjR+0fQw0wmTFg7ea/2A4bxUiMbooPo7P8HGFCWZO G+Lqv4TNsQmBoSVrKRXUzh26h13V+PA+tnw6KAgU= 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] Cygwin: cygheap: make bucket_val a static const array X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: 389f071f443ae1003d062649679aae79c248b3af X-Git-Newrev: 3e80956d63eb26c40d05ecc44990b157a44db99a Message-Id: <20221028150222.66F3A385AC2D@sourceware.org> Date: Fri, 28 Oct 2022 15:02:22 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D3e80956d63e= b26c40d05ecc44990b157a44db99a commit 3e80956d63eb26c40d05ecc44990b157a44db99a Author: Corinna Vinschen Date: Fri Oct 28 17:02:05 2022 +0200 Cygwin: cygheap: make bucket_val a static const array =20 Every time the cygheap is initialized, that is, on each fork or exec, cygheap_init() *again* computes the bucket size values and stores them in the cgyheap, albeit they are always the same values anyway. =20 Make bucket_val a local const array, statically initialized instead. =20 Fixes: 61522196c715 ("* Merge in cygwin-64bit-branch.)" Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/local_includes/cygheap.h | 1 - winsup/cygwin/mm/cygheap.cc | 30 ++++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/winsup/cygwin/local_includes/cygheap.h b/winsup/cygwin/local_i= ncludes/cygheap.h index 4448983ab..e671c3d32 100644 --- a/winsup/cygwin/local_includes/cygheap.h +++ b/winsup/cygwin/local_includes/cygheap.h @@ -555,7 +555,6 @@ struct threadlist_t struct init_cygheap: public mini_cygheap { _cmalloc_entry *chain; - unsigned bucket_val[NBUCKETS]; char *buckets[NBUCKETS]; UNICODE_STRING installation_root; WCHAR installation_root_buf[PATH_MAX]; diff --git a/winsup/cygwin/mm/cygheap.cc b/winsup/cygwin/mm/cygheap.cc index ac8df6a82..a305570df 100644 --- a/winsup/cygwin/mm/cygheap.cc +++ b/winsup/cygwin/mm/cygheap.cc @@ -257,6 +257,19 @@ 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, ... + 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 +}; + void cygheap_init () { @@ -272,16 +285,6 @@ cygheap_init () - CYGHEAP_STORAGE_LOW, MEM_COMMIT, PAGE_READWRITE); cygheap_max =3D (char *) cygheap + sizeof (*cygheap); - /* 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, ... With NBUCKETS =3D=3D 40, the maximum - block size is 12582912. - The idea is to have better matching bucket sizes (not wasting - space) without trading in performance compared to the old powers - of 2 method. */ - unsigned sz[2] =3D { 16, 24 }; /* sizeof cygheap_entry =3D=3D 16 */ - for (unsigned b =3D 1; b < NBUCKETS; b++, sz[b & 1] <<=3D 1) - cygheap->bucket_val[b] =3D sz[b & 1]; /* Default locale settings. */ cygheap->locale.mbtowc =3D __utf8_mbtowc; /* Set umask to a sane default. */ @@ -351,7 +354,7 @@ _cmalloc (unsigned size) unsigned b; =20 /* Calculate "bit bucket". */ - for (b =3D 1; b < NBUCKETS && cygheap->bucket_val[b] < size; b++) + for (b =3D 1; b < NBUCKETS && bucket_val[b] < size; b++) continue; if (b >=3D NBUCKETS) return NULL; @@ -365,8 +368,7 @@ _cmalloc (unsigned size) } else { - rvc =3D (_cmalloc_entry *) _csbrk (cygheap->bucket_val[b] - + sizeof (_cmalloc_entry)); + rvc =3D (_cmalloc_entry *) _csbrk (bucket_val[b] + sizeof (_cmalloc_= entry)); if (!rvc) { cygheap_protect.release (); @@ -400,7 +402,7 @@ _crealloc (void *ptr, unsigned size) newptr =3D _cmalloc (size); else { - unsigned oldsize =3D cygheap->bucket_val[to_cmalloc (ptr)->b]; + unsigned oldsize =3D bucket_val[to_cmalloc (ptr)->b]; if (size <=3D oldsize) return ptr; newptr =3D _cmalloc (size);