Cygwin: cygheap: make bucket_val a static const array

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.

Make bucket_val a local const array, statically initialized
instead.

Fixes: 61522196c7 ("* Merge in cygwin-64bit-branch.)"
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2022-10-28 17:02:05 +02:00
parent 389f071f44
commit 3e80956d63
2 changed files with 16 additions and 15 deletions

View File

@ -555,7 +555,6 @@ struct threadlist_t
struct init_cygheap: public mini_cygheap struct init_cygheap: public mini_cygheap
{ {
_cmalloc_entry *chain; _cmalloc_entry *chain;
unsigned bucket_val[NBUCKETS];
char *buckets[NBUCKETS]; char *buckets[NBUCKETS];
UNICODE_STRING installation_root; UNICODE_STRING installation_root;
WCHAR installation_root_buf[PATH_MAX]; WCHAR installation_root_buf[PATH_MAX];

View File

@ -257,6 +257,19 @@ init_cygheap::init_installation_root ()
} }
} }
/* 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] = {
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, 2097152,
3145728, 4194304, 6291456, 8388608, 12582912
};
void void
cygheap_init () cygheap_init ()
{ {
@ -272,16 +285,6 @@ cygheap_init ()
- CYGHEAP_STORAGE_LOW, - CYGHEAP_STORAGE_LOW,
MEM_COMMIT, PAGE_READWRITE); MEM_COMMIT, PAGE_READWRITE);
cygheap_max = (char *) cygheap + sizeof (*cygheap); cygheap_max = (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 == 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] = { 16, 24 }; /* sizeof cygheap_entry == 16 */
for (unsigned b = 1; b < NBUCKETS; b++, sz[b & 1] <<= 1)
cygheap->bucket_val[b] = sz[b & 1];
/* Default locale settings. */ /* Default locale settings. */
cygheap->locale.mbtowc = __utf8_mbtowc; cygheap->locale.mbtowc = __utf8_mbtowc;
/* Set umask to a sane default. */ /* Set umask to a sane default. */
@ -351,7 +354,7 @@ _cmalloc (unsigned size)
unsigned b; unsigned b;
/* Calculate "bit bucket". */ /* Calculate "bit bucket". */
for (b = 1; b < NBUCKETS && cygheap->bucket_val[b] < size; b++) for (b = 1; b < NBUCKETS && bucket_val[b] < size; b++)
continue; continue;
if (b >= NBUCKETS) if (b >= NBUCKETS)
return NULL; return NULL;
@ -365,8 +368,7 @@ _cmalloc (unsigned size)
} }
else else
{ {
rvc = (_cmalloc_entry *) _csbrk (cygheap->bucket_val[b] rvc = (_cmalloc_entry *) _csbrk (bucket_val[b] + sizeof (_cmalloc_entry));
+ sizeof (_cmalloc_entry));
if (!rvc) if (!rvc)
{ {
cygheap_protect.release (); cygheap_protect.release ();
@ -400,7 +402,7 @@ _crealloc (void *ptr, unsigned size)
newptr = _cmalloc (size); newptr = _cmalloc (size);
else else
{ {
unsigned oldsize = cygheap->bucket_val[to_cmalloc (ptr)->b]; unsigned oldsize = bucket_val[to_cmalloc (ptr)->b];
if (size <= oldsize) if (size <= oldsize)
return ptr; return ptr;
newptr = _cmalloc (size); newptr = _cmalloc (size);