Skip to content
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

GC.GetAllocatedBytesForCurrentThread always returns 0 when processor affinity is set to single proc #10547

Open
adamsitnik opened this issue Jun 19, 2018 · 6 comments

Comments

@adamsitnik
Copy link
Member

When the processor affinity is set in explicit way GC.GetAllocatedBytesForCurrentThread always returns 0. Even is something was allocated.

using System;

namespace gcstats
{
    class Program
    {
        static void Main(string[] args)
        {
            var before = System.GC.GetAllocatedBytesForCurrentThread();
            Console.WriteLine("Hello World!");
            var after = System.GC.GetAllocatedBytesForCurrentThread();
            Console.WriteLine($"after - before = {after - before}");
            Console.ReadLine();
        }
    }
}
start /affinity 1 dotnet.exe run
Hello World!
after - before = 0

start dotnet.exe run
Hello World!
after - before = 7552

dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.1.300-rc1-008673
 Commit:    f5e3ddbe73

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.16299
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.300-rc1-008673\

Host (useful for support):
  Version: 2.1.0-rc1
  Commit:  eb9bc92051

@jkotas @Maoni0 is this expected behavior? am I doing something wrong?

I am porting CoreCLR benchmarks from xunit-performance to BenchmarkDotNet and I have faced this issue today when I was comparing the results of some unstable benchmarks with affinity set and without.

/cc @jorive

@jkotas
Copy link
Member

jkotas commented Jun 20, 2018

Yes, this is how the API was implemented. Setting affinity to single proc will disable allocation contexts, that in turn makes this API to always return 0.

I have pointed this non-intuitive behavior when this API was introduced: dotnet/coreclr#6953 (comment). I agree that the current behavior does not sound right:

@adamsitnik
Copy link
Member Author

@jkotas once again big thanks for help!

I am going to close this issue and open a new one with a list of requirements that we have once I finish porting all repositories and the requirements are crystal clear.

@adamsitnik adamsitnik changed the title GC.GetAllocatedBytesForCurrentThread always returns 0 when processor affinity is set Why GC.GetAllocatedBytesForCurrentThread always returns 0 when processor affinity is set? Jun 20, 2018
@jkotas
Copy link
Member

jkotas commented Jun 20, 2018

I think we should keep this issue opened. It is a bug that we should look into fixing.

@jkotas jkotas reopened this Jun 20, 2018
@jkotas jkotas changed the title Why GC.GetAllocatedBytesForCurrentThread always returns 0 when processor affinity is set? GC.GetAllocatedBytesForCurrentThread always returns 0 when processor affinity is set Jun 20, 2018
@sergiy-k sergiy-k assigned VSadov and unassigned luhenry Jun 19, 2019
@Maoni0 Maoni0 changed the title GC.GetAllocatedBytesForCurrentThread always returns 0 when processor affinity is set GC.GetAllocatedBytesForCurrentThread always returns 0 when processor affinity is set to single proc Jun 25, 2019
@VSadov
Copy link
Member

VSadov commented Jun 25, 2019

Compared to other issues, this is not a ship-stopper for 3.0
At this point this should be Future.

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@msftgits msftgits added this to the Future milestone Jan 31, 2020
@mangod9 mangod9 modified the milestones: Future, 6.0.0 Sep 22, 2020
@VSadov VSadov removed their assignment Dec 3, 2020
@mangod9 mangod9 modified the milestones: 6.0.0, 7.0.0 Aug 2, 2021
@mangod9
Copy link
Member

mangod9 commented Aug 2, 2021

moving to 7

@mangod9 mangod9 modified the milestones: 7.0.0, Future Jul 19, 2022
@MikeStall
Copy link

Fyi - this appears to affect all Azure Websites.

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

Successfully merging a pull request may close this issue.

7 participants