Skip to content

Conversation

@filipnavara
Copy link
Member

@filipnavara filipnavara commented Sep 19, 2022

Originally reported here:

The code for determining the L3 cache size returns incorrect value on osx-x64. The machine I use for testing is running macOS 12.2.1 on Intel i5-8500B processor. This processor has 9MB of L3 cache but only 256Kb of L2 cache. The ARM64 fix for checking hw.perflevel0.l2cachesize mistakenly returns the L2 cache size on this machine. This in turn results in abysmal GC performance (on debug builds, at least) and frequent garbage collections.

Values on Intel:

teamcity@172-4-1-71 runtime % sysctl hw.perflevel0.l2cachesize
hw.perflevel0.l2cachesize: 262144
teamcity@172-4-1-71 runtime % sysctl hw.perflevel0.l3cachesize
hw.perflevel0.l3cachesize: 9437184
teamcity@172-4-1-71 runtime % sysctl hw.l3cachesize           
hw.l3cachesize: 9437184

Values on M1:

filipnavara@172-4-1-20 runtime % sysctl hw.perflevel0.l2cachesize
hw.perflevel0.l2cachesize: 12582912
filipnavara@172-4-1-20 runtime % sysctl hw.perflevel0.l3cachesize
filipnavara@172-4-1-20 runtime % sysctl hw.l3cachesize

@ghost ghost added area-GC-coreclr community-contribution Indicates that the PR has been added by a community member labels Sep 19, 2022
@ghost
Copy link

ghost commented Sep 19, 2022

Tagging subscribers to this area: @dotnet/gc
See info in area-owners.md if you want to be subscribed.

Issue Details

Originally reported here:

The code for determining the L3 cache size returns incorrect value on osx-x64. The machine I use for testing is running macOS 12.2.1 on Intel i5-8500B processor. This processor has 9MB of L3 cache but only 256Kb of L2 cache. The ARM64 fix for checking hw.perflevel0.l2cachesize mistakenly returns the L2 cache size on this machine. This in turn results in abysmal GC performance and frequent garbage collections.

Values on Intel:

teamcity@172-4-1-71 runtime % sysctl hw.perflevel0.l2cachesize
hw.perflevel0.l2cachesize: 262144
teamcity@172-4-1-71 runtime % sysctl hw.perflevel0.l3cachesize
hw.perflevel0.l3cachesize: 9437184
teamcity@172-4-1-71 runtime % sysctl hw.l3cachesize           
hw.l3cachesize: 9437184

Values on M1:

filipnavara@172-4-1-20 runtime % sysctl hw.perflevel0.l2cachesize
hw.perflevel0.l2cachesize: 12582912
filipnavara@172-4-1-20 runtime % sysctl hw.perflevel0.l3cachesize
filipnavara@172-4-1-20 runtime % sysctl hw.l3cachesize
Author: filipnavara
Assignees: -
Labels:

area-GC-coreclr

Milestone: -

// macOS-arm64: Since macOS 12.0, Apple added ".perflevelX." to determinate cache sizes for efficiency
// macOS: Since macOS 12.0, Apple added ".perflevelX." to determinate cache sizes for efficiency
// and performance cores separately. "perflevel0" stands for "performance"
|| sysctlbyname("hw.perflevel0.l3cachesize", &cacheSizeFromSysctl, &sz, nullptr, 0) == 0
Copy link
Member

Choose a reason for hiding this comment

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

Ah, I didn't add it because it wasn't used on arm64 🙂

Copy link
Member

@EgorBo EgorBo left a comment

Choose a reason for hiding this comment

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

Thanks!

@filipnavara
Copy link
Member Author

We should probably backport this to release/7.0.

@EgorBo EgorBo merged commit 7dad0f3 into dotnet:main Sep 20, 2022
@EgorBo
Copy link
Member

EgorBo commented Sep 20, 2022

We should probably backport this to release/7.0.

Probably indeed makes sense as 256kb is quite small for gen0 budget (is heuristic the same for workstation gc?)
and might hurt VSfM/Rider/etc apps (unlikely anyone is hosting web services on mac, right?)

@filipnavara
Copy link
Member Author

is heuristic the same for workstation gc?

Yep, I hit it on workstation GC in the first place.

@EgorBo
Copy link
Member

EgorBo commented Sep 20, 2022

/backport to release/7.0-rc2

@github-actions
Copy link
Contributor

Started backporting to release/7.0-rc2: https://github.com/dotnet/runtime/actions/runs/3086969575

@ghost ghost locked as resolved and limited conversation to collaborators Oct 20, 2022
@filipnavara filipnavara deleted the l3-size-os-x64 branch June 5, 2025 07:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-GC-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants