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

Reconcile how LOH allocations are tracked in allocation contexts #13734

Closed
VSadov opened this issue Nov 5, 2019 · 4 comments
Closed

Reconcile how LOH allocations are tracked in allocation contexts #13734

VSadov opened this issue Nov 5, 2019 · 4 comments
Milestone

Comments

@VSadov
Copy link
Member

VSadov commented Nov 5, 2019

Alloc uses per-thread context
AllocLHeap uses per-heap context.

We probably should use only one way. Using per-heap context consistently is attractive, since we can make allocation contexts smaller by removing alloc_bytes_loh

However, consider GetAllocatedBytesForCurrentThread API - does it actually see allocations done via AllocLHeap ? Should it?

@Suchiman
Copy link
Contributor

Suchiman commented Nov 6, 2019

However, consider GetAllocatedBytesForCurrentThread API - does it actually see allocations done via AllocLHeap ?

It appears that it does not, if you attempt to allocate an array that crosses the LOH threshold, it is not measured, which would explain why the allocations did not show in my benchmark in #13451 .
Following program will print 45648 for before and after.

using System;

class Program
{
    static void Main(string[] args)
    {
        long before = GC.GetAllocatedBytesForCurrentThread();

        var result = new char[50000];

        long after = GC.GetAllocatedBytesForCurrentThread();

        Console.WriteLine(before);
        Console.WriteLine(after);
    }
}

a new string(new char[50000]) interestingly enough gets measured (but only for the string allocation)

Should it?

Why shouldn't it? I would expect that it shows all allocations made on my current thread.

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@msftgits msftgits added this to the 5.0 milestone Jan 31, 2020
@Maoni0
Copy link
Member

Maoni0 commented Mar 10, 2020

the reason why AllocLHeap was there was to allocate objects smaller than LOH threshold on LOH. I have not looked at your PR yet, but I hope that was kept in mind.

@VSadov
Copy link
Member Author

VSadov commented Mar 11, 2020

@Maoni0 - yes, forcing allocations of smaller objects to go into LOH is still possible. I also plan to use a similar mechanism (flags) as a way to request POH allocations.
Thanks for reviewing!!

@VSadov
Copy link
Member Author

VSadov commented Mar 11, 2020

Fixed in #33402

@VSadov VSadov closed this as completed Mar 11, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants