Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable W^X by default #69672

Merged
merged 1 commit into from
May 24, 2022
Merged

Conversation

janvorli
Copy link
Member

This change enables the W^X by default. In the recent past, I've made
some changes to the related runtime code to improve the startup
performance with W^X enabled by reducing the number of times writeable
mappings need to be created. The current startup time regression is
about 5..10% (measured using ASPNet plaintext, json, fortunes and
orchard benchmarks on x64 windows and linux and arm64 linux).
The steady state performance is the same with and without the W^X
enabled.
There are still opportunities for improving the startup performance,
e.g. in the dynamic helpers, but it is time to enable W^X by default so
that if there are unexpected consequences that were not caught by the
benchmarking, we still have time to fix them for .NET 7.

This change enables the W^X by default. In the recent past, I've made
some changes to the related runtime code to improve the startup
performance with W^X enabled by reducing the number of times writeable
mappings need to be created. The current startup time regression is
about 5..10% (measured using ASPNet plaintext, json, fortunes and
orchard benchmarks on x64 windows and linux and arm64 linux).
The steady state performance is the same with and without the W^X
enabled.
There are still opportunities for improving the startup performance,
e.g. in the dynamic helpers, but it is time to enable W^X by default so
that if there are unexpected consequences that were not caught by the
benchmarking, we still have time to fix them for .NET 7.
@janvorli janvorli added this to the 7.0.0 milestone May 23, 2022
@janvorli janvorli requested a review from jkotas May 23, 2022 14:01
@janvorli janvorli self-assigned this May 23, 2022
@janvorli
Copy link
Member Author

cc: @mangod9, @sebastienros, @adamsitnik, @kunalspathak

@janvorli
Copy link
Member Author

The System.Text.RegularExpressions.Tests failed on x64 and arm64 with an assert in the PAL around virtual memory mapping. I am investigating it.

@janvorli
Copy link
Member Author

I've found the culprit causing the libraries test failure and fixed it here: #69697

@janvorli janvorli closed this May 24, 2022
@janvorli janvorli reopened this May 24, 2022
@janvorli janvorli merged commit 01fa120 into dotnet:main May 24, 2022
@janvorli janvorli deleted the enable-wxorx-by-default branch May 24, 2022 19:52
@AndyAyersMS
Copy link
Member

AndyAyersMS commented May 27, 2022

Suspect we may be seeing some perf wins from this... maybe?

dotnet/perf-autofiling-issues#5562
dotnet/perf-autofiling-issues#5551

@EgorBo
Copy link
Member

EgorBo commented Jun 2, 2022

image

Can confirm - up to +10% for time-to-first request

@sebastienros
Copy link
Member

sebastienros commented Jun 2, 2022

perf wins

can confirm

Not a win ;)

Sorry, didn't see the intermediate messages, my sarcasm will get me fired someday.

@mangod9
Copy link
Member

mangod9 commented Jun 2, 2022

Interesting that Time-to-First-Request (aka startup) is seeing an improvement. We were thinking that it will be slightly slower.

@EgorBo
Copy link
Member

EgorBo commented Jun 2, 2022

Interesting that Time-to-First-Request (aka startup) is seeing an improvement. We were thinking that it will be slightly slower.

No, that is a regression - it means it takes more time to respond on the first request 🙂 but I assume the additional security from W^X worth it, I just hope it didn't eat all the benefits we got by enabling OSR for 7.0 😆

@mangod9
Copy link
Member

mangod9 commented Jun 2, 2022

Ok, that makes sense. Sorry should have looked at the charts closely, but Andy's comment above threw me off :(

@ghost ghost locked as resolved and limited conversation to collaborators Jul 12, 2022
@mrsharm
Copy link
Member

mrsharm commented Aug 11, 2022

From our analysis while creating the perf report for August, we found the following regressions that seemed to line up with this PR specifically for Ubuntu 18.04 x64:

  • System.Security.Cryptography.X509Certificates.Tests.X509ChainTests.BuildX509ChainContoso:

image

  • System.Text.RegularExpressions.Tests.Perf_Regex_Common.CtorInvoke(Options: IgnoreCase, Compiled) and System.Text.RegularExpressions.Tests.Perf_Regex_Common.CtorInvoke(Options: Compiled):

image

System.Security.Cryptography.X509Certificates.Tests.X509ChainTests.BuildX509ChainContoso

Result Ratio Alloc Delta Operating System Bit Processor Name
Same 1.01 +0 Windows 11 Arm64 Microsoft SQ1 3.0 GHz
Same 0.99 +0 Windows 11 Arm64 Microsoft SQ1 3.0 GHz
Same 1.00 -40 macOS Monterey 12.3 Arm64 Apple M1 Max
Same 0.96 +0 Windows 10 X64 Intel Xeon CPU E5-1650 v4 3.60GHz
Same 0.98 +0 Windows 10 X64 Intel Core i7-6700 CPU 3.40GHz (Skylake)
Same 1.00 +0 Windows 10 X64 Intel Core i7-6700 CPU 3.40GHz (Skylake)
Same 0.99 +0 Windows 10 X64 Intel Core i7-8650U CPU 1.90GHz (Kaby Lake R)
Same 1.03 +0 Windows 10 X64 Intel Core i9-10900K CPU 3.70GHz
Same 0.93 +0 Windows 11 X64 AMD Ryzen Threadripper PRO 3945WX 12-Cores
Slower 0.88 +0 Windows 11 X64 AMD Ryzen 9 3950X
Same 1.00 +0 Windows 11 X64 AMD Ryzen 9 5900X
Slower 0.82 +0 Windows 11 X64 AMD Ryzen 9 5950X
Same 0.97 +0 Windows 11 X64 Intel Core i7-8700 CPU 3.20GHz (Coffee Lake)
Slower 0.82 +0 Windows 11 X64 Intel Core i9-10900K CPU 3.70GHz
Slower 0.14 +0 Windows 11 X64 11th Gen Intel Core i9-11900H 2.50GHz
Same 0.93 +8 ubuntu 18.04 X64 Intel Xeon CPU E5-1650 v4 3.60GHz
Same 1.08 +287 ubuntu 18.04 X64 Intel Core i7-2720QM CPU 2.20GHz (Sandy Bridge)
Same 0.91 +9 ubuntu 18.04 X64 Intel Core i7-8700 CPU 3.20GHz (Coffee Lake)
Same 0.95 +8 ubuntu 20.04 X64 AMD Ryzen 9 5900X
Slower 0.81 +8 ubuntu 20.04 X64 Intel Core i9-10900K CPU 3.70GHz
Same 1.00 +0 Windows 10 X86 Intel Xeon CPU E5-1650 v4 3.60GHz
Same 0.98 +0 Windows 10 X86 Intel Core i7-6700 CPU 3.40GHz (Skylake)
Same 1.00 +0 Windows 11 X86 AMD Ryzen Threadripper PRO 3945WX 12-Cores
Same 0.94 -54 macOS Big Sur 11.6.8 X64 Intel Core i5-4278U CPU 2.60GHz (Haswell)
Same 0.94 -38 macOS Monterey 12.3.1 X64 Intel Core i7-5557U CPU 3.10GHz (Broadwell)
Same 1.00 -38 macOS Monterey 12.4 X64 Intel Core i5-4278U CPU 2.60GHz (Haswell)

System.Text.RegularExpressions.Tests.Perf_Regex_Common.CtorInvoke(Options: IgnoreCase, Compiled)

Result Ratio Alloc Delta Operating System Bit Processor Name
Slower 0.85 +551 Windows 11 Arm64 Microsoft SQ1 3.0 GHz
Slower 0.80 +559 Windows 11 Arm64 Microsoft SQ1 3.0 GHz
Same 1.11 +554 macOS Monterey 12.3 Arm64 Apple M1 Max
Slower 0.87 +555 Windows 10 X64 Intel Xeon CPU E5-1650 v4 3.60GHz
Slower 0.81 +559 Windows 10 X64 Intel Core i7-6700 CPU 3.40GHz (Skylake)
Slower 0.66 +551 Windows 10 X64 Intel Core i7-6700 CPU 3.40GHz (Skylake)
Slower 0.85 +556 Windows 10 X64 Intel Core i7-8650U CPU 1.90GHz (Kaby Lake R)
Slower 0.89 +537 Windows 10 X64 Intel Core i9-10900K CPU 3.70GHz
Slower 0.88 +564 Windows 11 X64 AMD Ryzen Threadripper PRO 3945WX 12-Cores
Same 0.89 +565 Windows 11 X64 AMD Ryzen 9 3950X
Slower 0.87 +555 Windows 11 X64 AMD Ryzen 9 5900X
Slower 0.89 +568 Windows 11 X64 AMD Ryzen 9 5950X
Same 0.91 +540 Windows 11 X64 Intel Core i7-8700 CPU 3.20GHz (Coffee Lake)
Slower 0.88 +535 Windows 11 X64 Intel Core i9-10900K CPU 3.70GHz
Slower 0.87 +561 Windows 11 X64 11th Gen Intel Core i9-11900H 2.50GHz
Slower 0.89 +552 ubuntu 18.04 X64 Intel Xeon CPU E5-1650 v4 3.60GHz
Same 1.03 +541 ubuntu 18.04 X64 Intel Core i7-2720QM CPU 2.20GHz (Sandy Bridge)
Slower 0.80 +552 ubuntu 18.04 X64 Intel Core i7-8700 CPU 3.20GHz (Coffee Lake)
Same 0.93 +555 ubuntu 20.04 X64 AMD Ryzen 9 5900X
Slower 0.81 +543 ubuntu 20.04 X64 Intel Core i9-10900K CPU 3.70GHz
Slower 0.86 +547 Windows 10 X86 Intel Xeon CPU E5-1650 v4 3.60GHz
Slower 0.81 +549 Windows 10 X86 Intel Core i7-6700 CPU 3.40GHz (Skylake)
Slower 0.89 +546 Windows 11 X86 AMD Ryzen Threadripper PRO 3945WX 12-Cores
Slower 0.78 +541 macOS Big Sur 11.6.8 X64 Intel Core i5-4278U CPU 2.60GHz (Haswell)
Slower 0.79 +546 macOS Monterey 12.3.1 X64 Intel Core i7-5557U CPU 3.10GHz (Broadwell)
Slower 0.80 +552 macOS Monterey 12.4 X64 Intel Core i5-4278U CPU 2.60GHz (Haswell)

@janvorli: would you consider these regressions as "by design" as there are closed auto-filed regressions above?

@janvorli
Copy link
Member Author

@mrsharm let me look into these so that I can provide a definitive answer.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants