public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin/cygwin-3_4-branch] Cygwin: open_shared: always bump next_address
Date: Wed, 18 Jan 2023 19:35:09 +0000 (GMT)	[thread overview]
Message-ID: <20230118193509.DC3F43858D28@sourceware.org> (raw)

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

commit 0aa1c038196d04d0dfc8dc0f0f30e247e0c1e1e3
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Wed Jan 18 19:59:48 2023 +0100
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Wed Jan 18 20:17:23 2023 +0100

    Cygwin: open_shared: always bump next_address
    
    The new loop in open_shared has a subtil performance problem.
    Next_address is bumped only if mapping at this address
    failed.  Every subsequent call to open_shared has a high probability
    having to call MapViewOfFileEx twice, because next_address is still
    set to the address of the last successful mapping.
    
    Avoid this by bumping next_address every time.
    
    While at it, fix a comment.
    
    Conflict: Missing backport of 31302b267b86 ("Cygwin: drop fixed addresses for standard shared regions")
    Fixes: dc0fe7742b8c ("Cygwin: open_shared: try harder allocating a shared region")
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/mm/shared.cc | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/winsup/cygwin/mm/shared.cc b/winsup/cygwin/mm/shared.cc
index d23cc8e0e510..2ea3a4336351 100644
--- a/winsup/cygwin/mm/shared.cc
+++ b/winsup/cygwin/mm/shared.cc
@@ -184,25 +184,21 @@ open_shared (const WCHAR *name, int n, HANDLE& shared_h, DWORD size,
     {
       /* Locate shared regions in the area between SHARED_REGIONS_ADDRESS_LOW
 	 and SHARED_REGIONS_ADDRESS_HIGH, retrying until we have a slot.
-	 Don't use MapViewOfFile3 (loader deadlock during fork. */
+	 Don't use MapViewOfFile3 (STATUS_DLL_INIT_FAILED during fork). */
       bool loop = false;
 
-      addr = (void *) next_address;
       do
 	{
+	  addr = (void *) next_address;
 	  shared = MapViewOfFileEx (shared_h, FILE_MAP_READ | FILE_MAP_WRITE,
 				    0, 0, 0, addr);
-	  if (!shared)
+	  next_address += wincap.allocation_granularity ();
+	  if (next_address >= SHARED_REGIONS_ADDRESS_HIGH)
 	    {
-	      next_address += wincap.allocation_granularity ();
-	      if (next_address >= SHARED_REGIONS_ADDRESS_HIGH)
-		{
-		  if (loop)
-		    break;
-		  next_address = SHARED_REGIONS_ADDRESS_LOW;
-		  loop = true;
-		}
-	      addr = (void *) next_address;
+	      if (!shared && loop)
+		break;
+	      next_address = SHARED_REGIONS_ADDRESS_LOW;
+	      loop = true;
 	    }
 	}
       while (!shared);

                 reply	other threads:[~2023-01-18 19:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230118193509.DC3F43858D28@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).