From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 81A313858401; Wed, 18 Jan 2023 19:35:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 81A313858401 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674070515; bh=yWOv+5jttFx1v670Xf6ICLTpUVwfE7tpzXTS0EHawsA=; h=From:To:Subject:Date:From; b=SH12ZGQj89jJOzG9ug3uGb7wHtC13gj//aLWQWrcEctP0mCSpyFmRaflr7JgcZeMv E0KtrqdJ8N/KVdgdMqkci0KE9acwp6TKIagYAFFk8zrcbUUMY+P0sC+NZTMLGSLNRV TB588geCQOOqPdCClkJ6wAwtnsTW3xg518G4Aevs= 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/main] Cygwin: open_shared: always bump next_address X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/main X-Git-Oldrev: e18743072bc7fd56ec812e52dcfde5b686d1df8f X-Git-Newrev: 7e332208a0987fd91bf1afc8fa7a5647b53a5670 Message-Id: <20230118193515.81A313858401@sourceware.org> Date: Wed, 18 Jan 2023 19:35:15 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D7e332208a09= 87fd91bf1afc8fa7a5647b53a5670 commit 7e332208a0987fd91bf1afc8fa7a5647b53a5670 Author: Corinna Vinschen AuthorDate: Wed Jan 18 19:59:48 2023 +0100 Commit: Corinna Vinschen CommitDate: Wed Jan 18 20:13:36 2023 +0100 Cygwin: open_shared: always bump next_address =20 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. =20 Avoid this by bumping next_address every time. =20 While at it, fix a comment. =20 Fixes: dc0fe7742b8c ("Cygwin: open_shared: try harder allocating a shar= ed region") Signed-off-by: Corinna Vinschen 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 eb798c2ddb5f..e68b506a9fff 100644 --- a/winsup/cygwin/mm/shared.cc +++ b/winsup/cygwin/mm/shared.cc @@ -159,25 +159,21 @@ open_shared (const WCHAR *name, int n, HANDLE& shared= _h, DWORD size, =20 /* 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 =3D false; =20 - addr =3D (void *) next_address; do { + addr =3D (void *) next_address; shared =3D MapViewOfFileEx (shared_h, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0, addr); - if (!shared) + next_address +=3D wincap.allocation_granularity (); + if (next_address >=3D SHARED_REGIONS_ADDRESS_HIGH) { - next_address +=3D wincap.allocation_granularity (); - if (next_address >=3D SHARED_REGIONS_ADDRESS_HIGH) - { - if (loop) - break; - next_address =3D SHARED_REGIONS_ADDRESS_LOW; - loop =3D true; - } - addr =3D (void *) next_address; + if (!shared && loop) + break; + next_address =3D SHARED_REGIONS_ADDRESS_LOW; + loop =3D true; } } while (!shared);