Browse Source

Merge branch 'main' into dependabot/github_actions/actions/upload-artifact-6

pull/3058/head
James Jackson-South 5 months ago
committed by GitHub
parent
commit
ae57078ed4
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 8
      .github/workflows/build-and-test.yml
  2. 4
      .github/workflows/code-coverage.yml
  3. 18
      src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs
  4. 13
      tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedPoolMemoryAllocatorTests.cs

8
.github/workflows/build-and-test.yml

@ -49,7 +49,7 @@ jobs:
run: echo "lfs_key=$LFS_KEY" >> "$GITHUB_OUTPUT"
- name: Git Setup LFS Cache
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: .git/lfs
key: ${{ steps.expose-key.outputs.lfs_key }}
@ -144,7 +144,7 @@ jobs:
# Use the warmed key from WarmLFS. Do not recompute or recreate .lfs-assets-id here.
- name: Git Setup LFS Cache
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: .git/lfs
key: ${{ needs.WarmLFS.outputs.lfs_key }}
@ -157,7 +157,7 @@ jobs:
uses: NuGet/setup-nuget@v2
- name: NuGet Setup Cache
uses: actions/cache@v4
uses: actions/cache@v5
id: nuget-cache
with:
path: ~/.nuget
@ -236,7 +236,7 @@ jobs:
uses: NuGet/setup-nuget@v2
- name: NuGet Setup Cache
uses: actions/cache@v4
uses: actions/cache@v5
id: nuget-cache
with:
path: ~/.nuget

4
.github/workflows/code-coverage.yml

@ -46,7 +46,7 @@ jobs:
run: git lfs ls-files -l | awk '{print $1}' | sort > .lfs-assets-id
- name: Git Setup LFS Cache
uses: actions/cache@v4
uses: actions/cache@v5
id: lfs-cache
with:
path: .git/lfs
@ -59,7 +59,7 @@ jobs:
uses: NuGet/setup-nuget@v2
- name: NuGet Setup Cache
uses: actions/cache@v4
uses: actions/cache@v5
id: nuget-cache
with:
path: ~/.nuget

18
src/ImageSharp/Memory/Allocators/UniformUnmanagedMemoryPoolMemoryAllocator.cs

@ -71,10 +71,6 @@ internal sealed class UniformUnmanagedMemoryPoolMemoryAllocator : MemoryAllocato
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;
@ -155,20 +151,14 @@ internal sealed class UniformUnmanagedMemoryPoolMemoryAllocator : MemoryAllocato
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;
}
}

13
tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedPoolMemoryAllocatorTests.cs

@ -409,19 +409,6 @@ public class UniformUnmanagedPoolMemoryAllocatorTests
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()
{

Loading…
Cancel
Save