Repository navigation
Closed
Labels
area-GC-coreclrquestionAnswer questions and provide assistance, not an issue with source code or documentation.Answer questions and provide assistance, not an issue with source code or documentation.
Milestone
Description
s_useThreadAllocationContexts is ever false for win-x86/x64 and single processor:
runtime/src/coreclr/vm/gcheaputilities.cpp
Line 376 in 0682b04
| s_useThreadAllocationContexts = !useGlobalAllocationContext && (IsServerHeap() || ::g_SystemInfo.dwNumberOfProcessors != 1 || CPUGroupInfo::CanEnableGCCPUGroups()); |
In some places they have specialized optimizations, e.g. this win-x64 only branch:
runtime/src/coreclr/vm/jitinterfacegen.cpp
Lines 85 to 98 in 0682b04
| else | |
| { | |
| // Replace the 1p slow allocation helpers with faster version | |
| // | |
| // When we're running Workstation GC on a single proc box we don't have | |
| // InlineGetThread versions because there is no need to call GetThread | |
| SetJitHelperFunction(CORINFO_HELP_NEWSFAST, JIT_TrialAllocSFastSP); | |
| SetJitHelperFunction(CORINFO_HELP_NEWSFAST_ALIGN8, JIT_TrialAllocSFastSP); | |
| SetJitHelperFunction(CORINFO_HELP_BOX, JIT_BoxFastUP); | |
| SetJitHelperFunction(CORINFO_HELP_NEWARR_1_VC, JIT_NewArr1VC_UP); | |
| SetJitHelperFunction(CORINFO_HELP_NEWARR_1_OBJ, JIT_NewArr1OBJ_UP); | |
| ECall::DynamicallyAssignFCallImpl(GetEEFuncEntryPoint(AllocateStringFastUP), ECall::FastAllocateString); | |
| } |
Are these relevant? If not, we can delete these paths.
Metadata
Metadata
Assignees
Labels
area-GC-coreclrquestionAnswer questions and provide assistance, not an issue with source code or documentation.Answer questions and provide assistance, not an issue with source code or documentation.
Activity
dotnet-policy-service commentedon Apr 27, 2025
Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.
am11 commentedon Apr 27, 2025
I was looking at JIT_Box for HMF removal and found that
JIT_BoxFastUPis yet another variant, which also falls back to (allocating) JIT_Box when it fails.JIT_BoxFastUPis supposed to be a "fast" helper for this case but defined in a file calledJitHelpers_Slow.asmfor some reason.JIT_Box variants:
src/coreclr/vm/i386/jitinterfacex86.cppIf UseThreadAllocationContexts is not relevant, we can start by cleaning that up as part of JIT_Box non-HMF implementation.
cc @jkotas, @filipnavara
EgorBo commentedon Apr 27, 2025
Global allocation context allows to avoid slow TLS loads in allocators (workstation gc, low/single number of cpu cores). It would make sense to benchmark it for docker/linux where it's a popular case when just 1 cpu core is assigned, but the current logic only supports Windows.
jkotas commentedon Apr 27, 2025
This is a question for @dotnet/gc. They wanted to keep this special path alive in the past.
dotnet-policy-service commentedon Apr 27, 2025
Tagging subscribers to this area: @dotnet/gc
See info in area-owners.md if you want to be subscribed.
filipnavara commentedon Apr 27, 2025
Purely from the support perspective: Windows 10 is the last version of Windows to support uniprocessor and it goes out of support on October 14, 2025. Last Intel single-core processor was Celeron G4xx released in 2013.
The code paths don't seem to trigger for containers restricted to single processor. That's basically the only use case where I would consider this relevant. Then again, that's more relevant on Linux where we currently don't have this code path enabled.
I'm a bit torn on this. As @EgorBo said, it would be interesting to see if this makes any difference for containers but that's a separate effort...
jkotas commentedon Apr 27, 2025
This path requires 1 affinitized core assigned. The popular docker case is 1 non-affinitized core assigned. This special path is not usable for that.
filipnavara commentedon Apr 27, 2025
I don't see much good reasons to keep x86 special.
I'd be in favor of moving this to .S/.asm files, possibly even sharing some of it with NativeAOT. Then again, that's a separate task. If we could reduce the number of code paths then it would save some effort on such consolidation.(comment was not relevant toBoxspecifically, NativeAOT has the impl. in managed code, CoreCLR in C++ and the portable versions may be good enough)am11 commentedon Apr 27, 2025
That is one possibility, and while at it, we can replace
JIT_Box_MP_FastPortablewith asm code, includingJIT_Boximplementation. JIT_BoxFastUP implementation inJitHelpers_Slow.asmsuggests that we may be able to use ASM offsets similar to AllocFast.S/asm in NativeAOT.Alternatively..
AFAICT, the only reason JIT_Box requires HMF is the call to AllocateObject(). Other than IL_Throw/Rethrow (which you have already ported with win-x86 funclets), all remaining HMFs are related to Allocate{Object,String,Array} and FOH (#95695). We already have
InternalAllocandInternalAllocNoChecksexposed inRuntimeHandles.cs, perhaps we can implement JIT_Box in C# (following #109135)?filipnavara commentedon Apr 27, 2025
Sounds reasonable to me. It will take some effort and benchmarking but I don't expect the code to be too dissimilar to
RhBoxin NativeAOT.am11 commentedon Apr 27, 2025
Initial implementation: main...am11:runtime:feature/HMF-removal/JIT_Box
Currently throws:
Also, for fast alloc, we would need to figure out if we can expose thread local
ee_alloc_context* eeAllocContext = &t_runtime_thread_locals.alloc_contexton managed code (I haven't checked if we already have an existing helper).EgorBo commentedon Apr 28, 2025
I wonder if we don't need it at all given jit knows how to inline boxing as is (but does it only in tier1), we just need to make it always-expand probably.
We probably can, but the whole allocator has to be marked as nogc somehow..
am11 commentedon Apr 28, 2025
That would be cleaner. We can then delete getBoxHelper and JIT_Box helpers similar to https://github.com/dotnet/runtime/pull/114754/files. :)
jkotas commentedon Apr 28, 2025
Can we measure the Tier0 JIT throughput and code size regression from doing this? Are there are pathological cases where this can generate a lot of new temps?
EgorBo commentedon Apr 28, 2025
At the same time, we unroll copies even in tier0 and unlike the helper, in JIT we always know the size of the object. But hard to say without measurements
am11 commentedon Apr 28, 2025
#115134 is testing to see the impact.
cshung commentedon Apr 30, 2025
From a usage perspective, here is relatively recent case where customer is still using x86 single core back in 2022.
dotnet/diagnostics#2929
I can't remember where did the dump come from - probably internal given I could not share at that point.