HLSf use nuint rather than long, L4 now uses hlsf rather than array to alloc cache line.

This commit is contained in:
Youmu Liu
2026-04-20 18:10:14 +08:00
parent 1b7c929be4
commit 2e2d64a2ce
38 changed files with 796 additions and 465 deletions
@@ -34,6 +34,8 @@ using System.Runtime.Intrinsics.X86;
using System.Text;
using System.Threading.Tasks;
using Hlsf = StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocator;
namespace StgSharp.HighPerformance.Memory
{
public partial class L4
@@ -78,7 +80,7 @@ namespace StgSharp.HighPerformance.Memory
{
// EvictLine(i + index);
_ = _map.TryRemove(head->_origin, out _);
int id = (int)head->_predictor;
int id = head->_predictor;
IL4Predict predict = pSpan[id] ??
throw new L4PredictUnregisteredException(id);
predict.WriteBack(head->_origin, head->_profile, new ReadOnlySpan<byte>((byte*)head->_address, Unsafe.SizeOf<CacheLineData>()));
@@ -97,23 +99,29 @@ namespace StgSharp.HighPerformance.Memory
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void RecycleLine(
int id
private unsafe void RecycleLine(
int id
)
{
_idMux.Push(id);
Hlsf.Entry* entry = _entryManager._basePtr + id;
_bufferAllocator.Free(entry);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool TryGetEmptyLine(
out int index
private unsafe bool TryGetEmptyLine(
nuint size,
out int index,
out HlsfHandle handle
)
{
if (_idMux.TryPop(out index)) {
return true;
if (!_bufferAllocator.TryAlloc(size, out handle))
{
index = 0;
return false;
}
index = _maxId;
return Interlocked.Increment(ref _maxId) <= CacheLineCount;
Hlsf.Entry* entry = handle.EntryHandle;
index = (int)(entry - _entryManager._basePtr);
return true;
}
}