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
+11 -20
View File
@@ -2,8 +2,8 @@
// -----------------------------------------------------------------------
// file="L4"
// 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
@@ -48,11 +48,11 @@ namespace StgSharp.HighPerformance.Memory
/// <summary>
/// Count of cache lines mapped for each prediction, used for eviction policy.
/// </summary>
private readonly MapArray* _mapCount;
private readonly int* _mapCount;
/// <summary>
/// Count of times each cache line is predicted, used for eviction policy.
/// </summary>
private readonly PredictionArray* _predictCount;
private readonly int* _predictCount;
/// <summary>
/// Original memory view for prediction span.
/// </summary>
@@ -69,12 +69,7 @@ namespace StgSharp.HighPerformance.Memory
private readonly TLSF _bufferAllocator;
public L4(
int bindedNuma,
nuint bufferSize = 8192 * 8192,
int align = 16,
nuint maxCacheLineSize = 8192
)
public L4(int bindedNuma, nuint bufferSize = 8192 * 8192, int align = 16, nuint maxCacheLineSize = 8192)
{
_bindedNuma = bindedNuma;
@@ -82,7 +77,7 @@ namespace StgSharp.HighPerformance.Memory
nuint headSize = ((nuint)Unsafe.SizeOf<CacheLineMetadata>()) * CacheLineCount; // 16 byte align
nuint predictionSize = ((nuint)Unsafe.SizeOf<CacheLineDescription>()) * PredictionCount; //16 byte align
nuint mapCountSize = SwissTable.RequestedNativeMemorySize; // 16 byte align
nuint predictionCountSize = (nuint)Unsafe.SizeOf<PredictionArray>(); // 16 byte align
nuint predictionCountSize = sizeof(int) * CacheLineCount; // 16 byte align
nuint normalizedBufferSize = (bufferSize + (PageSize - 1)) & (~(PageSize - 1)); // align to 4096 byte, page size
ByteCapacity = normalizedBufferSize;
@@ -103,9 +98,9 @@ namespace StgSharp.HighPerformance.Memory
ptr += predictionSize;
_map = SwissTable.Create(ptr, _ => { });
ptr += mapCountSize;
_predictCount = (PredictionArray*)ptr;
_predictCount = (int*)ptr;
ptr += predictionCountSize;
_mapCount = (MapArray*)ptr;
_mapCount = (int*)ptr;
ptr += predictionCountSize;
M512* mPtr = (M512*)_head;
@@ -121,9 +116,7 @@ namespace StgSharp.HighPerformance.Memory
// public IL4Predict PrefetchPredict { get; set; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ContinueOnce(
Handle line
)
public void ContinueOnce(Handle line)
{
if (line.Address > 0) {
_ = Interlocked.Decrement(ref _aheadCount);
@@ -156,9 +149,7 @@ namespace StgSharp.HighPerformance.Memory
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Handle Map(
ref CacheLineDescription prediction
)
public Handle Map(ref CacheLineDescription prediction)
{
if ((_aheadCount < PredictionLeastAhead) && !_exhausted)
{
@@ -186,7 +177,7 @@ namespace StgSharp.HighPerformance.Memory
CacheLineMetadata* entry = (CacheLineMetadata*)entryHandle;
if (Interlocked.Increment(ref entry->RefCount) > 0)
{
(*_predictCount)[entry->Id] = 0;
_predictCount[entry - _head] = 0;
_ = Interlocked.Decrement(ref _aheadCount);
_ = Interlocked.Decrement(ref (*_mapCount)[entry->Id]);
return new Handle((nuint)entry->Position, ref entry->RefCount);