fix severe bug

This commit is contained in:
Youmu Liu
2026-03-16 18:27:32 +08:00
parent 8e6dfa7211
commit f8a879c4da
2 changed files with 12 additions and 13 deletions
@@ -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))
{
+2 -1
View File
@@ -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>((int*)ptr, CacheLineCount, _ => { });
@@ -132,6 +132,7 @@ namespace StgSharp.HighPerformance.Memory
_prefetching = 0;
}
}
Thread.Sleep(0);
}
}
while (true)