public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: cygheap: make bucket_val a static const array
@ 2022-10-28 15:02 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2022-10-28 15:02 UTC (permalink / raw)
  To: cygwin-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=3e80956d63eb26c40d05ecc44990b157a44db99a

commit 3e80956d63eb26c40d05ecc44990b157a44db99a
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Fri Oct 28 17:02:05 2022 +0200

    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>

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_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);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-28 15:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-28 15:02 [newlib-cygwin] Cygwin: cygheap: make bucket_val a static const array Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).