-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Windows Server 2022 - Setting affinity in .NET 6 application errors #72441
Comments
Tagging subscribers to this area: @dotnet/area-system-diagnostics-process Issue DetailsHi, I have a Windows Server 2022 machine with 40 cores and 80 logical processors. Whenever I try and run my application on this machine and attempt to set it's affinity in code or via Task Manager, I get errors. The error I get in code is: When I try and set it via Task Manager (as an admin with UAC disabled) I get: Also, when I try and get the affinity mask for the process in code, I get My theory is that I am unable to set the affinity for my application because it is performing actions on threads across multiple processor groups.
But I just get the So for me, is it possible to set a .NET 6 application to ONLY run in a single processor group on Windows Server 2022 before the application runs, so I can then set its affinity mask?
|
Related conversation: #68639 (comment) cc @AntonLapounov @stephentoub @kouvel @Maoni0 @kunalspathak |
Do you have |
Chances are that there are other non-.NET components loaded into the process that do not follow this restriction. For example, what is the Windows threadpool behavior - does it restrict itself from creating threads in multiple processor groups? |
That OS behavior change has been implemented in backward compatible manner. A process must explicitly declare itself multigroup-aware (by calling a relevant API) to break the existing APIs like
One can use |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
It will use other processor groups as well; however, that doesn't make the process multigroup-aware. FWIW, I just tried the code snippet below on an 80 core Windows Server 2022 Build 25058.1000 with the latest ARM64 SDK 6.0.302 and it worked fine: Process proc = Process.GetCurrentProcess();
long affinityMask = (long)proc.ProcessorAffinity;
affinityMask &= 15; // First 4 processors
proc.ProcessorAffinity = (IntPtr)affinityMask; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Another possibility is that something in your app calls We would appreciate a lot if you can help us to find out what's causing the affinity setting to fail in your app. |
Thanks for the responses, I am also unable to run the app under a debugger on that machine as it is a machine that can not be used for development. Another point that I should mention, is that when we downgrade the app to .NET 5, it works fine and affinity can be set. I will keep looking but if there is anything you know I could try without using a debugger, that would be really great, Thanks. |
So I've been able to find the line of code in the application where by affinity cannot be set after that line has been executed.
So it appears that something in ASPNET is not multi-group aware and is breaking our application on machines with more than 64 processors. |
The initialization of the Quic protocol handler is calling
Nit: It is the exact opposite. This code is multi-group aware and that breaks affinity setting APIs. In other words, the existing Process affinity settings API do not work on multi-group aware processes. |
That makes sense. So how would one go about setting a multi-group aware process to be affinitised to the first 4 cores in a single processor group? |
I do not think that there is a way to do that today. The affinity has to be set during process startup or before the process becomes multi-group aware. @AntonLapounov Is that right? |
Ok, thanks very much for the help. I will do some more testing to see if it can be worked around. It would maybe be a good idea to have a kestrel option to disable the use of Quic? so that when upgrading to .NET 6 it can be ignored until an appropriate time to implement support for multi-group awareness. Also, from my reading it wasn't made clear in any breaking changes document that on Windows 11/Server 2022 with more than 64 processors that upgrading to .NET 6 would break setting the process affinity after a kestrel host has been instantiated. Possibly an addition in the docs there too. |
Quic is just a tip of the iceberg. There are number of other components that call I agree that this needs to be documented better. |
If this is true, then that would good to know. |
That is correct, once the process becomes multigroup-aware, the |
Closing this issue as external to the runtime. |
Hi,
I have a Windows Server 2022 machine with 40 cores and 80 logical processors. Whenever I try and run my application on this machine and attempt to set it's affinity in code or via Task Manager, I get errors.
The error I get in code is:
Win32Exception (87): The parameter is incorrect
When I try and set it via Task Manager (as an admin with UAC disabled) I get:
Unable to access or set process affinity
Also, when I try and get the affinity mask for the process in code, I get
0
back.After reading the docs:
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getprocessaffinitymask
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setprocessaffinitymask
https://docs.microsoft.com/en-us/windows/win32/procthread/processor-groups
It is clear that on Windows 11 and Server 2022 that threads are not bound to a single processor group any more if there are more than 64 processors and can run across multiple processor groups.
My theory is that I am unable to set the affinity for my application because it is performing actions on threads across multiple processor groups.
I have tried setting the affinity mask at startup in my application using:
But I just get the
Win32Exception (87): The parameter is incorrect
And when I try to get the affinity mask at start up it is set to
0
meaning it was unable to get it because there are threads in multiple groups.So for me, is it possible to set a .NET 6 application to ONLY run in a single processor group on Windows Server 2022 before the application runs, so I can then set its affinity mask?
The text was updated successfully, but these errors were encountered: