Remove hlsf, TLSF.alloc is ok

This commit is contained in:
Youmu Liu
2026-05-11 18:08:35 +08:00
parent 5706c89563
commit b59d414e20
21 changed files with 267 additions and 1514 deletions
+23 -10
View File
@@ -2,8 +2,8 @@
// -----------------------------------------------------------------------
// file="L4"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
// AuthorGroup: Nitload
// Copyright (c) Nitload. 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
@@ -31,7 +31,7 @@ using StgSharp.HighPerformance.ProcessorAbstraction;
using System.Data;
using System.Runtime.InteropServices;
using HLSF = StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocator;
using HLSF = StgSharp.HighPerformance.Memory.TwoLayerSegregatedFitAllocator;
namespace StgSharp.HighPerformance.Memory
{
@@ -62,7 +62,12 @@ namespace StgSharp.HighPerformance.Memory
private readonly Slab _entryManager;
private readonly SwissTable _map;
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;
@@ -85,8 +90,8 @@ namespace StgSharp.HighPerformance.Memory
// init all components with the buffer, and move the buffer pointer forward.
nuint _buffer = _baseAddress + normalizedBufferSize;
_entryManager = new Slab(_buffer);
_bufferAllocator = new HLSF(entrySize, align, maxCacheLineSize, (void*)_baseAddress, static _ => { },
_entryManager);
_bufferAllocator = new HLSF(entrySize, align, maxCacheLineSize, (void*)_baseAddress,
static _ => { }/*, _entryManager/**/);
ptr += entrySize;
_head = (CacheLineHead*)ptr;
ptr += headSize;
@@ -112,7 +117,9 @@ namespace StgSharp.HighPerformance.Memory
// public IL4Predict PrefetchPredict { get; set; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ContinueOnce(L4CacheLine line)
public void ContinueOnce(
L4CacheLine line
)
{
if (line.Address > 0) {
_ = Interlocked.Decrement(ref _aheadCount);
@@ -150,7 +157,9 @@ namespace StgSharp.HighPerformance.Memory
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public L4CacheLine Map(ref CacheLineDescription prediction)
public L4CacheLine Map(
ref CacheLineDescription prediction
)
{
if ((_aheadCount < PredictionLeastAhead) && !_exhausted)
{
@@ -182,7 +191,7 @@ namespace StgSharp.HighPerformance.Memory
_ = Interlocked.Increment(ref _activeCount);
_ = Interlocked.Decrement(ref _aheadCount);
_ = Interlocked.Decrement(ref (*_mapCount)[entry->Id]);
return new L4CacheLine(entry->Address, ref _activeCount, ref entry->RefCount);
return new L4CacheLine((nuint)entry->Address, ref _activeCount, ref entry->RefCount);
} else
{
_ = Interlocked.Decrement(ref entry->RefCount);
@@ -203,7 +212,11 @@ namespace StgSharp.HighPerformance.Memory
private ref int _refCount;
private nuint _handle;
internal L4CacheLine(nuint handle, ref int activeCount, ref int cacheRefCount)
internal L4CacheLine(
nuint handle,
ref int activeCount,
ref int cacheRefCount
)
{
_handle = handle;
_refCount = ref cacheRefCount;