Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2022-10-28 18:02:05 +0300
committerCorinna Vinschen <corinna@vinschen.de>2022-10-28 18:02:05 +0300
commit3e80956d63eb26c40d05ecc44990b157a44db99a (patch)
tree792bbab44a49a13d21320be79ce9d84eb1bce6e1
parent389f071f443ae1003d062649679aae79c248b3af (diff)
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: 61522196c715 ("* Merge in cygwin-64bit-branch.)" Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
-rw-r--r--winsup/cygwin/local_includes/cygheap.h1
-rw-r--r--winsup/cygwin/mm/cygheap.cc30
2 files changed, 16 insertions, 15 deletions
diff --git a/winsup/cygwin/local_includes/cygheap.h b/winsup/cygwin/local_includes/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 ()
}
}
+/* 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
cygheap_init ()
{
@@ -272,16 +285,6 @@ cygheap_init ()
- CYGHEAP_STORAGE_LOW,
MEM_COMMIT, PAGE_READWRITE);
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. */
cygheap->locale.mbtowc = __utf8_mbtowc;
/* Set umask to a sane default. */
@@ -351,7 +354,7 @@ _cmalloc (unsigned size)
unsigned b;
/* 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;
if (b >= NBUCKETS)
return NULL;
@@ -365,8 +368,7 @@ _cmalloc (unsigned size)
}
else
{
- rvc = (_cmalloc_entry *) _csbrk (cygheap->bucket_val[b]
- + sizeof (_cmalloc_entry));
+ rvc = (_cmalloc_entry *) _csbrk (bucket_val[b] + sizeof (_cmalloc_entry));
if (!rvc)
{
cygheap_protect.release ();
@@ -400,7 +402,7 @@ _crealloc (void *ptr, unsigned size)
newptr = _cmalloc (size);
else
{
- unsigned oldsize = cygheap->bucket_val[to_cmalloc (ptr)->b];
+ unsigned oldsize = bucket_val[to_cmalloc (ptr)->b];
if (size <= oldsize)
return ptr;
newptr = _cmalloc (size);