Skip to content

Commit

Permalink
Add FreeBSD case to gcenv. (#91524)
Browse files Browse the repository at this point in the history
Closes #64935
  • Loading branch information
Thefrank authored Sep 5, 2023
1 parent 7329c4b commit 46d8834
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
46 changes: 29 additions & 17 deletions src/coreclr/gc/unix/gcenv.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,34 @@ uint64_t GetAvailablePhysicalMemory()
uint64_t available = 0;

// Get the physical memory available.
#ifndef __APPLE__
#if defined(__APPLE__)
vm_size_t page_size;
mach_port_t mach_port;
mach_msg_type_number_t count;
vm_statistics_data_t vm_stats;
mach_port = mach_host_self();
count = sizeof(vm_stats) / sizeof(natural_t);
if (KERN_SUCCESS == host_page_size(mach_port, &page_size))
{
if (KERN_SUCCESS == host_statistics(mach_port, HOST_VM_INFO, (host_info_t)&vm_stats, &count))
{
available = (int64_t)vm_stats.free_count * (int64_t)page_size;
}
}
mach_port_deallocate(mach_task_self(), mach_port);
#elif defined(__FreeBSD__)
size_t inactive_count = 0, laundry_count = 0, free_count = 0;
size_t sz = sizeof(inactive_count);
sysctlbyname("vm.stats.vm.v_inactive_count", &inactive_count, &sz, NULL, 0);

sz = sizeof(laundry_count);
sysctlbyname("vm.stats.vm.v_laundry_count", &laundry_count, &sz, NULL, 0);

sz = sizeof(free_count);
sysctlbyname("vm.stats.vm.v_free_count", &free_count, &sz, NULL, 0);

available = (inactive_count + laundry_count + free_count) * sysconf(_SC_PAGESIZE);
#else // Linux
static volatile bool tryReadMemInfo = true;

if (tryReadMemInfo)
Expand All @@ -1176,22 +1203,7 @@ uint64_t GetAvailablePhysicalMemory()
// Fall back to getting the available pages using sysconf.
available = sysconf(SYSCONF_PAGES) * sysconf(_SC_PAGE_SIZE);
}
#else // __APPLE__
vm_size_t page_size;
mach_port_t mach_port;
mach_msg_type_number_t count;
vm_statistics_data_t vm_stats;
mach_port = mach_host_self();
count = sizeof(vm_stats) / sizeof(natural_t);
if (KERN_SUCCESS == host_page_size(mach_port, &page_size))
{
if (KERN_SUCCESS == host_statistics(mach_port, HOST_VM_INFO, (host_info_t)&vm_stats, &count))
{
available = (int64_t)vm_stats.free_count * (int64_t)page_size;
}
}
mach_port_deallocate(mach_task_self(), mach_port);
#endif // __APPLE__
#endif

return available;
}
Expand Down
1 change: 0 additions & 1 deletion src/libraries/System.Runtime/tests/System/GCTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,6 @@ public static void GetAllocatedBytesForCurrentThread(int size)

private static bool IsNotArmProcessAndRemoteExecutorSupported => PlatformDetection.IsNotArmProcess && RemoteExecutor.IsSupported;

[ActiveIssue("https://github.com/dotnet/runtime/issues/64935", TestPlatforms.FreeBSD)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/73167", TestRuntimes.Mono)]
[ConditionalFact(nameof(IsNotArmProcessAndRemoteExecutorSupported))] // [ActiveIssue("https://github.com/dotnet/runtime/issues/29434")]
public static void GetGCMemoryInfo()
Expand Down

0 comments on commit 46d8834

Please sign in to comment.