solution to length unfixed cacheline in l4

This commit is contained in:
Nitload
2026-04-19 02:30:35 +08:00
parent f2560f3d5b
commit 5fc8e62f28
14 changed files with 421 additions and 532 deletions
+32 -29
View File
@@ -1,27 +1,30 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="HlsfStressTest"
// file="HlsfStressTest.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
@@ -149,7 +152,7 @@ namespace StgSharp
Stopwatch sw = Stopwatch.StartNew();
for (int i = 0; i < pairs; i++)
{
HybridLayerSegregatedFitAllocationHandle h = allocator.Alloc(blockSize);
hlsfHandle h = allocator.Alloc(blockSize);
allocator.Free(h);
}
sw.Stop();
@@ -175,11 +178,11 @@ namespace StgSharp
return;
}
List<HybridLayerSegregatedFitAllocationHandle> list = new List<HybridLayerSegregatedFitAllocationHandle>((int)ops);
List<hlsfHandle> list = new List<hlsfHandle>((int)ops);
Stopwatch sw = Stopwatch.StartNew();
for (long i = 0; i < ops; i++)
{
HybridLayerSegregatedFitAllocationHandle h = allocator.Alloc(blockSize);
hlsfHandle h = allocator.Alloc(blockSize);
if (touch)
{
Span<byte> span = h.BufferHandle;
@@ -193,7 +196,7 @@ namespace StgSharp
}
sw.Stop();
double allocOpsPerSec = ops / sw.Elapsed.TotalSeconds;
foreach (HybridLayerSegregatedFitAllocationHandle h in list) {
foreach (hlsfHandle h in list) {
allocator.Free(h);
}
@@ -205,13 +208,13 @@ namespace StgSharp
{
int targetBytes = targetMiB * 1024 * 1024;
Random rng = new Random(123);
List<HybridLayerSegregatedFitAllocationHandle> live = new List<HybridLayerSegregatedFitAllocationHandle>(128 * 1024);
List<hlsfHandle> live = new List<hlsfHandle>(128 * 1024);
long allocated = 0;
Stopwatch swA = Stopwatch.StartNew();
while (allocated < targetBytes)
{
uint sz = PickSize(rng);
HybridLayerSegregatedFitAllocationHandle h = allocator.Alloc(sz);
hlsfHandle h = allocator.Alloc(sz);
live.Add(h);
allocated += sz;
}
@@ -235,7 +238,7 @@ namespace StgSharp
while (allocated < targetBytes / 2)
{
uint sz = PickSize(rng);
HybridLayerSegregatedFitAllocationHandle h = allocator.Alloc(sz);
hlsfHandle h = allocator.Alloc(sz);
live.Add(h);
allocated += sz;
reCount++;
@@ -244,7 +247,7 @@ namespace StgSharp
Console.WriteLine($" phaseC re-alloc {reCount} in {swC.Elapsed.TotalSeconds:0.00}s ~{allocated / (1024.0 * 1024.0):0}MB");
Stopwatch swD = Stopwatch.StartNew();
foreach (HybridLayerSegregatedFitAllocationHandle h in live) {
foreach (hlsfHandle h in live) {
allocator.Free(h);
}
@@ -254,7 +257,7 @@ namespace StgSharp
private static void BenchFreeThroughput(HybridLayerSegregatedFitAllocator allocator, int count, uint blockSize)
{
List<HybridLayerSegregatedFitAllocationHandle> list = new List<HybridLayerSegregatedFitAllocationHandle>(count);
List<hlsfHandle> list = new List<hlsfHandle>(count);
for (int i = 0; i < count; i++) {
list.Add(allocator.Alloc(blockSize));
}
@@ -292,12 +295,12 @@ namespace StgSharp
private static void Warmup(HybridLayerSegregatedFitAllocator allocator)
{
List<HybridLayerSegregatedFitAllocationHandle> tmp = new List<HybridLayerSegregatedFitAllocationHandle>(4096);
List<hlsfHandle> tmp = new List<hlsfHandle>(4096);
for (int i = 0; i < 4096; i++) {
tmp.Add(allocator.Alloc(256));
}
foreach (HybridLayerSegregatedFitAllocationHandle h in tmp) {
foreach (hlsfHandle h in tmp) {
allocator.Free(h);
}
}
+1 -1
View File
@@ -59,7 +59,7 @@ namespace StgSharp
for (int round = 1; round <= maxRounds; round++)
{
// 100 次分配
List<HybridLayerSegregatedFitAllocationHandle> batch = new List<HybridLayerSegregatedFitAllocationHandle>(100);
List<hlsfHandle> batch = new List<hlsfHandle>(100);
for (int i = 0; i < 100; i++)
{
uint sz = sizes[rnd.Next(sizes.Length)];