hlsf goes bad
This commit is contained in:
+69
-36
@@ -2,8 +2,8 @@
|
||||
// -----------------------------------------------------------------------
|
||||
// file="hlsf-test"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics.Memory;
|
||||
using StgSharp.HighPerformance.Memory;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -40,44 +40,77 @@ namespace StgSharp
|
||||
|
||||
public static void TestHlsf()
|
||||
{
|
||||
// HLSF test arena
|
||||
Console.WriteLine(
|
||||
"=== HLSF (Hybrid Layer Segregated Fit Allocator) Single-threaded Stress Test ===\n");
|
||||
HybridLayerSegregatedFitAllocator hlsfAllocator = new HybridLayerSegregatedFitAllocator(1024 * 1024 * 1024);
|
||||
|
||||
// === 简洁交替测试:100次alloc与100次free交替进行,直到触发异常或达到最大循环 ===
|
||||
Console.WriteLine("\n=== 简洁交替测试:100次alloc + 100次free 交替 ===");
|
||||
|
||||
int maxRounds = 10000; // 可调整
|
||||
uint[] sizes = {
|
||||
64u,
|
||||
128u,
|
||||
256u,
|
||||
512u,
|
||||
1024u };
|
||||
Random rnd = new Random(42);
|
||||
for (int round = 1; round <= maxRounds; round++)
|
||||
unchecked
|
||||
{
|
||||
// 100 次分配
|
||||
List<hlsfHandle> batch = new List<hlsfHandle>(100);
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
uint sz = sizes[rnd.Next(sizes.Length)];
|
||||
batch.Add(hlsfAllocator.Alloc(sz));
|
||||
Console.WriteLine($"alloced:{i}");
|
||||
}
|
||||
nuint size = (nuint)(4UL * 1024UL * 1024UL * 1024UL);
|
||||
|
||||
// 100 次释放(逆序)
|
||||
for (int i = batch.Count - 1; i >= 0; i--)
|
||||
// HLSF test arena
|
||||
Console.WriteLine(
|
||||
"=== HLSF (Hybrid Layer Segregated Fit Allocator) Single-threaded Stress Test ===\n");
|
||||
HybridLayerSegregatedFitAllocator hlsfAllocator = new(size);
|
||||
|
||||
// === 简洁交替测试:100次alloc与100次free交替进行,直到触发异常或达到最大循环 ===
|
||||
Console.WriteLine("\n=== 简洁交替测试:100次alloc + 100次free 交替 ===");
|
||||
|
||||
int maxRounds = 10000; // 可调整
|
||||
int maxCount = 10000;
|
||||
uint[] sizes = [
|
||||
64u,
|
||||
128u,
|
||||
256u,
|
||||
512u,
|
||||
1024u,
|
||||
4096u,
|
||||
16384u,
|
||||
65536u,
|
||||
262144u,
|
||||
1048576u
|
||||
];
|
||||
int[] offset = [
|
||||
-4,
|
||||
-3,
|
||||
-2,
|
||||
-1,
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4
|
||||
];
|
||||
Random rnd = new Random(42);
|
||||
for (int round = 1; round <= maxRounds; round++)
|
||||
{
|
||||
hlsfAllocator.Free(batch[i]);
|
||||
Console.WriteLine($"freed:{i}");
|
||||
}
|
||||
if (round % 100 == 0) {
|
||||
Console.WriteLine($"[交替测试] 已完成 {round} 轮 100alloc+100free");
|
||||
List<HlsfHandle> batch = new(maxCount);
|
||||
for (int i = 0; i < maxCount; i++)
|
||||
{
|
||||
uint sz = sizes[rnd.Next(sizes.Length)];
|
||||
batch.Add(hlsfAllocator.Alloc(sz));
|
||||
|
||||
// Console.WriteLine($"alloced:{i}");
|
||||
}
|
||||
for (int i = 5; i < maxCount; i += 10)
|
||||
{
|
||||
HlsfHandle origin = batch[i];
|
||||
int index = i + offset[rnd.Next(offset.Length)];
|
||||
batch[i] = batch[index];
|
||||
batch[index] = origin;
|
||||
}
|
||||
for (int i = batch.Count - 1; i >= 0; i--)
|
||||
{
|
||||
hlsfAllocator.Free(batch[i]);
|
||||
|
||||
// Console.WriteLine($"freed:{i}");
|
||||
}
|
||||
if (round % 100 == 0)
|
||||
{
|
||||
Console.WriteLine($"[交替测试] 已完成 {round} 轮 {maxCount}alloc+{maxCount}free");
|
||||
hlsfAllocator.DumpPositionChain(false, 10);
|
||||
hlsfAllocator.Collect();
|
||||
hlsfAllocator.DumpPositionChain(false, 10);
|
||||
}
|
||||
}
|
||||
Console.WriteLine("[交替测试] 正常结束,无异常触发");
|
||||
}
|
||||
Console.WriteLine("[交替测试] 正常结束,无异常触发");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user