Remove id from L4 head, and other some useless types.

This commit is contained in:
Nitload
2026-06-02 00:35:08 +08:00
parent 9a09d32960
commit 07f8178431
6 changed files with 98 additions and 219 deletions
@@ -2,8 +2,8 @@
// -----------------------------------------------------------------------
// file="L4.Evict"
// Project: StgSharp
// AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved.
// 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
@@ -52,63 +52,37 @@ namespace StgSharp.HighPerformance.Memory
/// Count of lines not evicted
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private unsafe int Evict(
int count = 1
)
private unsafe int Evict(int count = 1)
{
count = (count < 0) ? 0 : count;
int* pPtr = (int*)_predictCount, mPtr = (int*)_mapCount;
int* pPtr = _predictCount, mPtr = _mapCount;
int remain = count;
ConcurrentFlexibleArray<IL4Predict> predictors = _predictors;
predictors.RequestSpanOperation();
Span<IL4Predict> pSpan = predictors.AsSpan();
try
for (int i = 0; i < CacheLineCount; i++)
{
for (int i = 0; i < CacheLineCount; i++)
if (pPtr[i] > mPtr[i])
{
if (pPtr[i] > mPtr[i])
{
continue;
}
remain -= TryEvictAt(i, pSpan) ? 1 : 0;
continue;
}
}
finally
{
predictors.ReleaseSpanOperation();
remain -= TryEvictAt(i) ? 1 : 0;
}
return remain;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private unsafe void RecycleLine(
int id
)
{
_bufferAllocator.Free(id);
/**/
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private unsafe bool TryEvictAt(
int index,
Span<IL4Predict> predictorSpan
)
private unsafe bool TryEvictAt(int index)
{
CacheLineMetadata* head = &_head[index];
if (Interlocked.CompareExchange(ref head->RefCount, int.MinValue, 0) == 0)
{
// EvictLine(i + index);
_ = _map.TryRemove(head->Origin, out _);
int id = head->Predictor;
IL4Predict predict = predictorSpan[id] ??
throw new L4PredictUnregisteredException(id);
IL4Predict predict = CurrentPredict;
predict.WriteBack(head->Origin, head->Profile, new ReadOnlySpan<byte>((byte*)(ulong)head->Position, (int)(ulong)head->SizeForAllocator));
RecycleLine(index);
(*_mapCount)[index] = 0;
(*_predictCount)[index] = int.MaxValue;
_bufferAllocator.Free(index);
_mapCount[index] = 0;
_predictCount[index] = int.MaxValue;
return true;
}
return false;