Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ internal UniformUnmanagedMemoryPoolMemoryAllocator(
this.nonPoolAllocator = new UnmanagedMemoryAllocator(unmanagedBufferSizeInBytes);
}

// This delegate allows overriding the method returning the available system memory,
// so we can test our workaround for https://github.com/dotnet/runtime/issues/65466
internal static Func<long> GetTotalAvailableMemoryBytes { get; set; } = () => GC.GetGCMemoryInfo().TotalAvailableMemoryBytes;

/// <inheritdoc />
protected internal override int GetBufferCapacityInBytes() => this.poolBufferSizeInBytes;

Expand Down Expand Up @@ -155,20 +151,14 @@ internal override MemoryGroup<T> AllocateGroupCore<T>(

private static long GetDefaultMaxPoolSizeBytes()
{
// On 64 bit set the pool size to a portion of the total available memory.
// https://github.com/dotnet/runtime/issues/55126#issuecomment-876779327
if (Environment.Is64BitProcess)
{
long total = GetTotalAvailableMemoryBytes();

// Workaround for https://github.com/dotnet/runtime/issues/65466
if (total > 0)
{
return (long)((ulong)total / 8);
}
// On 64 bit set the pool size to a portion of the total available memory.
GCMemoryInfo info = GC.GetGCMemoryInfo();
return info.TotalAvailableMemoryBytes / 8;
}

// Stick to a conservative value of 128 Megabytes on other platforms and 32 bit .NET 5.0:
// Stick to a conservative value of 128 Megabytes on 32 bit.
return 128 * OneMegabyte;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -409,19 +409,6 @@ private static void AllocateSingleAndForget(UniformUnmanagedMemoryPoolMemoryAllo
g = null;
}

[Fact]
public void Issue2001_NegativeMemoryReportedByGc()
{
RemoteExecutor.Invoke(RunTest).Dispose();

static void RunTest()
{
// Emulate GC.GetGCMemoryInfo() issue https://github.com/dotnet/runtime/issues/65466
UniformUnmanagedMemoryPoolMemoryAllocator.GetTotalAvailableMemoryBytes = () => -402354176;
_ = MemoryAllocator.Create();
}
}

[Fact]
public void Allocate_OverLimit_ThrowsInvalidMemoryOperationException()
{
Expand Down
Loading