Skip to content

Fix LLC cache issue on Apple M1 - #64576

Merged
EgorBo merged 3 commits into
dotnet:mainfrom
EgorBo:fix-cache-l3-apple-m1
Feb 1, 2022
Merged

Fix LLC cache issue on Apple M1#64576
EgorBo merged 3 commits into
dotnet:mainfrom
EgorBo:fix-cache-l3-apple-m1

Conversation

@EgorBo

@EgorBoEgorBo commented Jan 31, 2022

Copy link
Copy Markdown
Member

Addresses the L3 cache issue we've found in #60166 but for macOS-arm64

It seems that since macOS 12.0, Apple added more entries for sysctl (see #62832 (comment)). And it turns out the keys we were using report cache size for the "efficiency cores", not the performance ones. As the result, PAL_GetLogicalProcessorCacheSizeFromOS used to return 4mb instead of expected 12mb.

This change shows nice improvements for GC-bound benchmarks and should address #60616 (comment)

usingSystem;usingSystem.Runtime.CompilerServices;usingBenchmarkDotNet.Attributes;usingBenchmarkDotNet.Running;publicclassTest{publicstaticvoidMain(string[]args)=>BenchmarkSwitcher.FromAssembly(typeof(Test).Assembly).Run(args);[Benchmark][Arguments(10000)][Arguments(128)]publicchar[]AllocateUninit(intlen)=>GC.AllocateUninitializedArray<char>(len);[Benchmark][Arguments(2000)][Arguments(256)]publicchar[]AllocateArray(intlen)=>newchar[len];[Benchmark]publicobjectSmallAllocation()=>newobject[]{new(),new()};[Benchmark]publicstringIntToString()=>42.ToString();}

Results (Apple M1 mac mini):

MethodToolchainlenMeanErrorStdDevRatio
SmallAllocation/Core_Root/corerun?12.695 ns0.0422 ns0.0352 ns1.10
SmallAllocation/Core_Root_PR/corerun?11.534 ns0.0453 ns0.0423 ns1.00
IntToString/Core_Root/corerun?6.239 ns0.0058 ns0.0052 ns1.08
IntToString/Core_Root_PR/corerun?5.782 ns0.0074 ns0.0069 ns1.00
AllocateUninit/Core_Root/corerun12814.195 ns0.1914 ns0.1790 ns1.43
AllocateUninit/Core_Root_PR/corerun1289.952 ns0.0622 ns0.0582 ns1.00
AllocateArray/Core_Root/corerun25626.071 ns0.3068 ns0.2562 ns1.46
AllocateArray/Core_Root_PR/corerun25617.843 ns0.1272 ns0.1190 ns1.00
AllocateArray/Core_Root/corerun2000180.445 ns3.6465 ns3.4110 ns1.66
AllocateArray/Core_Root_PR/corerun2000108.966 ns0.9273 ns0.8674 ns1.00
AllocateUninit/Core_Root/corerun10000529.512 ns3.2077 ns3.0005 ns2.51
AllocateUninit/Core_Root_PR/corerun10000211.415 ns3.5344 ns3.3060 ns1.00

@ghostghost added the area-PAL-coreclr only for closed issues label Jan 31, 2022
@ghostghost assigned EgorBoJan 31, 2022
@EgorBo

Copy link
Copy Markdown
MemberAuthor

Unrelated to this PR, when I play with DOTNET_GCgen0size with bigger values I get even better results for these benchmarks.

@EgorBo

Copy link
Copy Markdown
MemberAuthor

cc @dotnet/gc @janvorli

Comment threadsrc/coreclr/pal/src/misc/sysinfo.cpp
Comment threadsrc/coreclr/pal/src/misc/sysinfo.cpp
@EgorBo

Copy link
Copy Markdown
MemberAuthor

Btw, here is what sysctrl -a reports on my M1: https://gist.github.com/EgorBo/df63dfe24f5463009fbf2490e406b39c

@janvorli

Copy link
Copy Markdown
Member

Thanks @EgorBo for sharing the output of the sysctrl -a! There is much more interesting information than I expected.

@janvorlijanvorli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@EgorBo
EgorBo merged commit 69b9000 into dotnet:mainFeb 1, 2022
@JulieLeeMSFTJulieLeeMSFT added this to the 7.0.0 milestone Feb 8, 2022
@ghostghost locked as resolved and limited conversation to collaborators Mar 10, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-PAL-coreclronly for closed issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@EgorBo@janvorli@jkotas@mangod9@JulieLeeMSFT