Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nk0Ud-0005VQ-9S for pgsql-hackers@arkaria.postgresql.org; Thu, 28 Apr 2022 09:31:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nk0Ub-00060E-Tl for pgsql-hackers@arkaria.postgresql.org; Thu, 28 Apr 2022 09:31:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nk0Ub-000604-KM for pgsql-hackers@lists.postgresql.org; Thu, 28 Apr 2022 09:31:21 +0000 Received: from mail.dental-vision.de ([82.144.34.210]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nk0UZ-0007zK-GI for pgsql-hackers@lists.postgresql.org; Thu, 28 Apr 2022 09:31:21 +0000 Received: from MAIL.cf.local (2001:9e8:e911:7e00:58c6:ffce:82d9:8a35) by Mail.cf.local (2001:9e8:e911:7e00:58c6:ffce:82d9:8a35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.6; Thu, 28 Apr 2022 11:31:17 +0200 Received: from MAIL.cf.local ([192.168.169.216]) by Mail.cf.local ([192.168.169.216]) with mapi id 15.01.2507.006; Thu, 28 Apr 2022 11:31:17 +0200 From: Wilm Hoyer To: Julien Rouhaud CC: Michael Paquier , "pgsql-hackers@lists.postgresql.org" Subject: AW: BUG #17448: In Windows 10, version 1703 and later, huge_pages doesn't work. Thread-Topic: BUG #17448: In Windows 10, version 1703 and later, huge_pages doesn't work. Thread-Index: AQHYQLLari2s00oie0yrcUkVcNdgtqzRF5eAgAAr+QCAAC3FgIAGApsAgAFhPgCAAC2tgIAABR2AgAAuZoCAAASEgIABhzwQgCbuaICAAcnTAIAAPCWggABU8ACAASmTcA== Date: Thu, 28 Apr 2022 09:31:17 +0000 Message-ID: <6389b5a88e114bee85593af2853c08cd@dental-vision.de> References: <20220331045908.bm5edcacvymgwwv2@jrouhaud> <20220331080055.hjrrsrd4lxwlt7f5@jrouhaud> <20220331104659.ol6pqe7s3tpkymuk@jrouhaud> <20220331110309.ws25d6dl5yyzprye@jrouhaud> <9178d683d05d420a887369ffb38d8fbd@dental-vision.de> <20220427165228.dkxndmm4lsrd5zgg@jrouhaud> In-Reply-To: <20220427165228.dkxndmm4lsrd5zgg@jrouhaud> Accept-Language: de-DE, en-US Content-Language: de-DE X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.168.169.196] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Apr 27, 2022 at 03:04:23PM +0000, Wilm Hoyer wrote: >> >> I used the following hack to get the "real" Major and Minor Version of=20 >> Windows - it's in C# (.Net) and needs to be adjusted (you can compile=20 >> as x64 and use a long-long as return value ) to return the Service=20 >> Number too and translated it into C. >> I share it anyways, as it might help - please be kind, as it really is=20 >> a little hack. >> >> Situation: >> Main Application can't or is not willing to add a manifest file into=20 >> its resources. >> >> Solution: >> Start a small executable (which has a manifest file compiled into its=20 >> resources), let it read the OS Version and code the Version into its=20 >> return Code. > Thanks for sharing. You are welcome. > Having to compile another tool just for that seems like a very high price= to pay, especially since we don't have any C# code in the tree. I'm not e= ven sure that compiling this wouldn't need additional requirements and/or = if it would work on our oldest supported Windows versions. With "translate it into C" I meant "tread it as pseudo code, for a solution= in plain C" (e.g. substitude Environment.OSVersion with IsWindowsVersionOr= Greater or GetVersion ) On Wed, Apr 27, 2022 at 05:13:12PM +0900, Michael Paquier wrote: > On Tue, Apr 26, 2022 at 12:54:35PM +0800, Julien Rouhaud wrote: > > so I'm still on the opinion that we should unconditionally use the=20 > > FILE_MAP_LARGE_PAGES flag if it's defined and call it a day. >=20 > Are we sure that this is not going to cause failures in environments=20 > where the flag is not supported? I'm not that familiar with the Microsoft OS or C (that's why I haven't migr= ated the c# code to C in the first place) to have a clear answer to that qu= estion. If there is any risk and you want to avoid it, I can share a search result = when I faced the same issue for our application. I declined this solution i= n favor of the previously shared one. It's from NUnit (and needs migration to C as well - but since it just invol= ves the Registry this should be pretty forward). Just in case the Framework is not known: NUnit is the most popular .Net por= t of the Unit Testing Framework JUnit. There exits a C port too (CUnit) May= be in there you can find an OS Version check too. // Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - = see LICENSE.txt [...] namespace NUnit.Framework.Internal { [SecuritySafeCritical] public class OSPlatform { [...] /// /// Gets the actual OS Version, not the incorrect value that might = be /// returned for Win 8.1 and Win 10 /// /// /// If an application is not manifested as Windows 8.1 or Windows 1= 0, /// the version returned from Environment.OSVersion will not be 6.3= and 10.0 /// respectively, but will be 6.2 and 6.3. The correct value can be= found in /// the registry. /// /// The original version /// The correct OS version private static Version GetWindows81PlusVersion(Version version) { try { using (var key =3D Registry.LocalMachine.OpenSubKey(@"SOFTW= ARE\Microsoft\Windows NT\CurrentVersion")) { if (key !=3D null) { var buildStr =3D key.GetValue("CurrentBuildNumber")= as string; int.TryParse(buildStr, out var build); // These two keys are in Windows 10 only and are DW= ORDS var major =3D key.GetValue("CurrentMajorVersionNumb= er") as int?; var minor =3D key.GetValue("CurrentMinorVersionNumb= er") as int?; if (major.HasValue && minor.HasValue) { return new Version(major.Value, minor.Value, bu= ild); } // If we get here, we are not Windows 10, so we are= Windows 8 // or 8.1. 8.1 might report itself as 6.2, but will= have 6.3 // in the registry. We can't do this earlier becaus= e for backwards // compatibility, Windows 10 also has 6.3 for this = key. var currentVersion =3D key.GetValue("CurrentVersion= ") as string; if(currentVersion =3D=3D "6.3") { return new Version(6, 3, build); } } } } catch (Exception) { } return version; } [...] } } Finally, my reasoning to use the executable solution in favor of the NUnit = one:=20 I found no guarantee from Microsoft regarding the keys and values in the re= gistry - hence a change with an update or in a newer Windows is not likely,= but still possible. That's no problem for a heavily used and supported fra= mework like NUnit - they are likely to adopt within days of a new Windows r= elease. I on the other hand wanted a solution with small to no support. Tha= t's why I decided to implement a solution that's as in line as possible wit= h the official Microsoft advice for targeting newer OS Versions. Best regards Wilm.