Daily update on 20260312-004950 by Nitload Youmu. Additional Message : use one single index mux as replacement of two slab allocators for L4.
Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -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
|
||||
@@ -42,33 +42,36 @@ namespace StgSharp.HighPerformance.Memory
|
||||
|
||||
private const int CacheLineCount = 8192;
|
||||
private const int PredictionCount = 2048;
|
||||
private const int PredictionLeaseAhead = 1024;
|
||||
private const int PredictionLeastAhead = 1024;
|
||||
|
||||
private readonly CacheLineData* _data;
|
||||
|
||||
private readonly EvictionArray* _eviction;
|
||||
|
||||
private readonly CacheLineHead* _head;
|
||||
private readonly CacheLinePrediction* _prediction;
|
||||
|
||||
private bool _disposed;
|
||||
private int _activeCount;
|
||||
|
||||
private int _aheadCount;
|
||||
private int _maxId;
|
||||
private readonly nuint _baseAddress;
|
||||
private readonly SlabAllocator<CacheLineData> _cacheLineAllocator;
|
||||
|
||||
private readonly SlabAllocator<CacheLineHead> _entryAllocator;
|
||||
|
||||
private readonly SwissTable _map;
|
||||
private readonly UnmanagedStack<int> _idMux;
|
||||
|
||||
public L4()
|
||||
{
|
||||
int cacheSize = Unsafe.SizeOf<CacheLineData>() * CacheLineCount;
|
||||
int entrySize = Unsafe.SizeOf<CacheLineHead>() * CacheLineCount;
|
||||
int stackSize = sizeof(int) * CacheLineCount;
|
||||
int mapSize = SwissTable.RequestedNativeMemorySize;
|
||||
int pprvSize = Unsafe.SizeOf<EvictionArray>();
|
||||
_baseAddress = (nuint)NativeMemory.AlignedAlloc((nuint)(cacheSize + entrySize + mapSize), 16);
|
||||
int predictionSize = Unsafe.SizeOf<CacheLinePrediction>() * PredictionCount;
|
||||
int rrpvSize = Unsafe.SizeOf<EvictionArray>();
|
||||
_baseAddress = (nuint)NativeMemory.AlignedAlloc((nuint)(cacheSize + entrySize + stackSize + mapSize + predictionSize + rrpvSize), 16);
|
||||
nuint _buffer = _baseAddress;
|
||||
_cacheLineAllocator = SlabAllocator.FromBuffer<CacheLineData>(_buffer, CacheLineCount, _ => { });
|
||||
_entryAllocator = SlabAllocator.FromBuffer<CacheLineHead>(_buffer + (nuint)cacheSize, CacheLineCount, _ => { });
|
||||
_data = (CacheLineData*)_buffer;
|
||||
_head = (CacheLineHead*)(_buffer + (nuint)cacheSize);
|
||||
_prediction = (CacheLinePrediction*)(_buffer + (nuint)(cacheSize + entrySize));
|
||||
_map = SwissTable.Create(_baseAddress + (nuint)(cacheSize + entrySize), _ => { });
|
||||
_eviction = (EvictionArray*)(_baseAddress + (nuint)(cacheSize + entrySize + mapSize));
|
||||
}
|
||||
@@ -89,13 +92,12 @@ namespace StgSharp.HighPerformance.Memory
|
||||
return;
|
||||
}
|
||||
_disposed = true;
|
||||
_map.Dispose();
|
||||
NativeMemory.AlignedFree((void*)_baseAddress);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public CacheLine Map(
|
||||
nuint origin
|
||||
)
|
||||
public CacheLine Map(nuint origin)
|
||||
{
|
||||
if (_map.TryGet(origin, out nuint entryHandle))
|
||||
{
|
||||
@@ -114,9 +116,7 @@ namespace StgSharp.HighPerformance.Memory
|
||||
|
||||
private partial void Prefetch();
|
||||
|
||||
private partial bool TestHit(
|
||||
nuint origin
|
||||
);
|
||||
private partial bool TestHit(nuint origin);
|
||||
|
||||
public ref struct CacheLine : IDisposable
|
||||
{
|
||||
@@ -125,11 +125,7 @@ namespace StgSharp.HighPerformance.Memory
|
||||
private ref int _refCount;
|
||||
private nuint _handle;
|
||||
|
||||
internal CacheLine(
|
||||
nuint handle,
|
||||
ref int activeCount,
|
||||
ref int cacheRefCount
|
||||
)
|
||||
internal CacheLine(nuint handle, ref int activeCount, ref int cacheRefCount)
|
||||
{
|
||||
_handle = handle;
|
||||
_refCount = ref cacheRefCount;
|
||||
|
||||
Reference in New Issue
Block a user