From f8a879c4da1cf47c309ce2d7180bdca1e37e587d Mon Sep 17 00:00:00 2001 From: Youmu Liu <105042599+Nitload-NSI@users.noreply.github.com> Date: Mon, 16 Mar 2026 18:27:32 +0800 Subject: [PATCH] fix severe bug --- .../HighPerformance/Memory/L4.Prefetch.cs | 22 +++++++++---------- StgSharp.Common/HighPerformance/Memory/L4.cs | 3 ++- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/StgSharp.Common/HighPerformance/Memory/L4.Prefetch.cs b/StgSharp.Common/HighPerformance/Memory/L4.Prefetch.cs index dc0fcee9..0a96cb6a 100644 --- a/StgSharp.Common/HighPerformance/Memory/L4.Prefetch.cs +++ b/StgSharp.Common/HighPerformance/Memory/L4.Prefetch.cs @@ -2,8 +2,8 @@ // ----------------------------------------------------------------------- // file="L4.Prefetch" // 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 @@ -25,13 +25,6 @@ // // ----------------------------------------------------------------------- // ----------------------------------------------------------------------- -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Cryptography.X509Certificates; -using System.Text; -using System.Threading.Tasks; - namespace StgSharp.HighPerformance.Memory { public unsafe partial class L4 @@ -67,17 +60,22 @@ namespace StgSharp.HighPerformance.Memory { continue; } - if (!TryGetEmptyLine(out int index)) { + + // TODO 未经初始化的_idMux可能会导致TryGetEmptyLine失败,导致无法预取,最好添加末尾指针计数 + if (!TryGetEmptyLine(out int index)) + { throw new OverflowException("L4 has no empty cache line."); } CacheLineHead* head = &_head[index]; // pre fetch them here - PrefetchPredict.Prefetch(head->_origin, _head->_profile, _head->_address); + _ = PrefetchPredict.Prefetch(head->_origin, head->_profile, head->_address); } } - private partial bool TestHit(nuint origin) + private partial bool TestHit( + nuint origin + ) { if (_map.TryGet(origin, out nuint handle)) { diff --git a/StgSharp.Common/HighPerformance/Memory/L4.cs b/StgSharp.Common/HighPerformance/Memory/L4.cs index d856f51c..5b80839a 100644 --- a/StgSharp.Common/HighPerformance/Memory/L4.cs +++ b/StgSharp.Common/HighPerformance/Memory/L4.cs @@ -78,7 +78,7 @@ namespace StgSharp.HighPerformance.Memory _prediction = (CacheLinePrediction*)ptr; ptr += predictionSize; _map = SwissTable.Create(_baseAddress + cacheSize + entrySize, _ => { }); - _prediction = (CacheLinePrediction*)ptr; + ptr += mapSize; _eviction = (EvictionArray*)ptr; ptr += rrpvSize; _idMux = new UnmanagedStack((int*)ptr, CacheLineCount, _ => { }); @@ -132,6 +132,7 @@ namespace StgSharp.HighPerformance.Memory _prefetching = 0; } } + Thread.Sleep(0); } } while (true)