Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Perform PhysicalMemoryLimit check for workstation GC, refactor GetLargestOnDieCacheSize into GetCacheSizePerLogicalCpu #15975

Merged
merged 2 commits into from
Jan 29, 2018

Conversation

tmds
Copy link
Member

@tmds tmds commented Jan 23, 2018

Some time ago I was looking into gc.cpp implementation of checking physical memory: https://github.com/dotnet/coreclr/issues/14991#issuecomment-348428003

This PR is making two changes:

  • The code that checks GetPhysicalMemoryLimit is also used for workstation gc
  • Combine GCToOSInterface::GetLargestOnDieCacheSize and GetLogicalCpuCount into GetCacheSizePerLogicalCpu. These two functions are used together to determine how much cache there is per logical processor. Combining them avoids confusion what GetLogicalCpuCount is returning (e.g. physical processors on die, vs processors affinitized to process), GetLogicalCpuCount was already taking nr of cores into account to some extent and GetLogicalCpuCount returns 1 when not implemented (which may not be a proper default value).

CC @swgillespie @Maoni0

@benaadams
Copy link
Member

@jkotas jkotas requested review from Maoni0 and swgillespie January 23, 2018 13:13
@jkotas jkotas added the area-GC label Jan 23, 2018
Copy link

@swgillespie swgillespie left a comment

Choose a reason for hiding this comment

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

Looks good to me - thanks!

@@ -1854,9 +1854,10 @@ DWORD GetLogicalCpuCountFallback()

#endif // _TARGET_X86_ || _TARGET_AMD64_

size_t GetLargestOnDieCacheSize(BOOL bTrueSize)
// fix this if/when AMD does multicore or SMT

Choose a reason for hiding this comment

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

I guess this is a little outdated now... 😆

@@ -1911,6 +1912,31 @@ size_t GetLargestOnDieCacheSize(BOOL bTrueSize)
}
}

// TODO: Currently GetLogicalCpuCountFromOS() and GetLogicalCpuCountFallback() are broken on

Choose a reason for hiding this comment

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

This whole codepath seems to be really outdated to me. At one point I asked around to see if these comments still apply, and to the knowledge of everyone I talked to the OS issues that this function is working around were fixed a long time ago.

We should probably rewrite this whole thing at some point...

Copy link
Member

@Maoni0 Maoni0 Jan 24, 2018

Choose a reason for hiding this comment

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

We should be using GetLogicalProcessorInformationEx on the OS versions where it's available and fall back to cpuid where it's not. but you don't have to do it in this PR; feel free to open an issue to track if you don't want to do it in this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

@Maoni0 Maoni0 left a comment

Choose a reason for hiding this comment

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

:shipit:


int n_heaps = gc_heap::n_heaps;
#else //SERVER_GC
size_t trueSize = GCToOSInterface::GetCacheSizePerLogicalCpu(TRUE);
Copy link
Member Author

Choose a reason for hiding this comment

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

@Maoni0 @swgillespie I wonder, for workstation gc, if we want to multiply here with GCToOSInterface::GetCurrentProcessCpuCount. wdyt?

Choose a reason for hiding this comment

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

I'll leave that to @Maoni0, I don't have any thoughts - not super familiar with this math.

Copy link
Member

Choose a reason for hiding this comment

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

we don't want to do that 'cause we don't assume that processes using workstation GC will own the machine. unless you specifically affinitize your process with fewer CPUs, GetCurrentProcessCpuCount will return all CPUs.

@tmds
Copy link
Member Author

tmds commented Jan 29, 2018

@swgillespie @Maoni0 thanks for reviewing! Can one of you merge this PR?

@Maoni0 Maoni0 merged commit cb73944 into dotnet:master Jan 29, 2018
@Maoni0
Copy link
Member

Maoni0 commented Jan 29, 2018

thanks for doing this, @tmds!

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

Successfully merging this pull request may close these issues.

5 participants