You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GetGCMemoryInfo.TotalAvailableMemoryBytes returns negative value on ARM32 #65466
This has been reported by an ImageSharp user in SixLabors/ImageSharp#2001 for Raspberry Pi OS 11 - Bullseye. I don't have the HW to repro it unfortunately. ImageSharp implemented a sub-optimal workaround to deal with this issue.
Was there a change in the runtime that potentially addressed this?
This has been reported by an ImageSharp user in SixLabors/ImageSharp#2001 for Raspberry Pi OS 11 - Bullseye. I don't have the HW to repro it, unfortunately. ImageSharp implemented a sub-optimal workaround to deal with this issue.
Was there a change in the runtime that potentially addressed this?
I confirmed that the managed API, GetGCMemoryInfo.TotalAvailableMemoryBytes, faithfully reports the value stored in gc_heap::total_physical_mem, the field is a uint64_t, which cannot be negative (but of course, could be a wrong value). The property GetGCMemoryInfo.TotalAvailableMemoryBytes is a long, which is a 64-bit signed integer, and there is a possibility that the conversion generated a negative number)
Indeed, if I hard code gc_heap::total_physical_mem to 0xF000 0000 0000 0000`, it is possible to force the API to return a negative value.
If I hard code gc_heap::total_physical_mem to 0xF000 0000, the GetGCMemoryInfo.TotalAvailableMemoryBytes returned a positive number just fine.
Analyzing the code further, it must be the case that GCToOSInterface::GetPhysicalMemoryLimit. That API returns a uint64_t, but it could return a bogus value that is larger than 2^63-1.
For Linux, the detection of memory info is based on sysctl. For that, unfortunately, without the repro hardware, there is no way to look at that further.
There is indeed something suspicious in the underlying code, something along this line.
Activity
workaround for #2001 / dotnet/runtime#65466
cshung commentedon Aug 2, 2022
@antonfirsov, @brianpopow can you still reproduce the issue?
antonfirsov commentedon Aug 2, 2022
This has been reported by an ImageSharp user in SixLabors/ImageSharp#2001 for Raspberry Pi OS 11 - Bullseye. I don't have the HW to repro it unfortunately. ImageSharp implemented a sub-optimal workaround to deal with this issue.
Was there a change in the runtime that potentially addressed this?
cshung commentedon Aug 2, 2022
I confirmed that the managed API,
GetGCMemoryInfo.TotalAvailableMemoryBytes, faithfully reports the value stored ingc_heap::total_physical_mem, the field is auint64_t, which cannot be negative (but of course, could be a wrong value). The propertyGetGCMemoryInfo.TotalAvailableMemoryBytesis a long, which is a 64-bit signed integer, and there is a possibility that the conversion generated a negative number)Indeed, if I hard code
gc_heap::total_physical_memto 0xF000 0000 0000 0000`, it is possible to force the API to return a negative value.If I hard code
gc_heap::total_physical_memto0xF000 0000, theGetGCMemoryInfo.TotalAvailableMemoryBytesreturned a positive number just fine.Analyzing the code further, it must be the case that
GCToOSInterface::GetPhysicalMemoryLimit. That API returns auint64_t, but it could return a bogus value that is larger than 2^63-1.For Linux, the detection of memory info is based on
sysctl. For that, unfortunately, without the repro hardware, there is no way to look at that further.There is indeed something suspicious in the underlying code, something along this line.
runtime/src/coreclr/gc/unix/cgroup.cpp
Lines 507 to 516 in 18d0367
That case is specific to containers though - note that
size_tis an unsigned 32-bit integer on a Linux ARM machine.In various places, I also see
size_tis used in the available physical memory code path, which could be a reason.cshung commentedon Aug 2, 2022
Turn out I am able to repro on an ARM64 device by installing an ARM dotnet SDK. I will take it from there.
antonfirsov commentedon Aug 2, 2022
If this helps or is interesting for any reason: The value reported by the user was
-456847360which is18446744073252704256unsigned.antonfirsov commentedon Aug 2, 2022
I'm stupid, and missed that @brianpopow had a repro: SixLabors/ImageSharp#2001 (comment)