Optimize the map/unmap physical memory svcs
This commit is contained in:
parent
bec39a10e4
commit
fd1d68db34
1 changed files with 26 additions and 28 deletions
|
@ -591,25 +591,24 @@ namespace Ryujinx.HLE.OsHle.Handles
|
||||||
{
|
{
|
||||||
long MappedSize = 0;
|
long MappedSize = 0;
|
||||||
|
|
||||||
long CurrPosition = Position;
|
KMemoryInfo Info;
|
||||||
|
|
||||||
|
LinkedListNode<KMemoryBlock> BaseNode = FindBlockNode(Position);
|
||||||
|
|
||||||
|
LinkedListNode<KMemoryBlock> Node = BaseNode;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
KMemoryInfo Info = FindBlock(CurrPosition).GetInfo();
|
Info = Node.Value.GetInfo();
|
||||||
|
|
||||||
if (Info.State != MemoryState.Unmapped)
|
if (Info.State != MemoryState.Unmapped)
|
||||||
{
|
{
|
||||||
MappedSize += GetSizeInRange(Info, Position, End);
|
MappedSize += GetSizeInRange(Info, Position, End);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Info.Size == 0)
|
Node = Node.Next;
|
||||||
{
|
|
||||||
throw new InvalidOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
CurrPosition = Info.Position + Info.Size;
|
|
||||||
}
|
}
|
||||||
while ((ulong)CurrPosition < (ulong)End);
|
while ((ulong)(Info.Position + Info.Size) < (ulong)End && Node != null);
|
||||||
|
|
||||||
if (MappedSize == Size)
|
if (MappedSize == Size)
|
||||||
{
|
{
|
||||||
|
@ -623,29 +622,24 @@ namespace Ryujinx.HLE.OsHle.Handles
|
||||||
return MakeError(ErrorModule.Kernel, KernelErr.OutOfMemory);
|
return MakeError(ErrorModule.Kernel, KernelErr.OutOfMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrPosition = Position;
|
Node = BaseNode;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
KMemoryInfo Info = FindBlock(CurrPosition).GetInfo();
|
Info = Node.Value.GetInfo();
|
||||||
|
|
||||||
if (Info.State == MemoryState.Unmapped)
|
if (Info.State == MemoryState.Unmapped)
|
||||||
{
|
{
|
||||||
long CurrSize = GetSizeInRange(Info, Position, End);
|
long CurrSize = GetSizeInRange(Info, Position, End);
|
||||||
|
|
||||||
CpuMemory.Map(CurrPosition, PA, CurrSize);
|
CpuMemory.Map(Info.Position, PA, CurrSize);
|
||||||
|
|
||||||
PA += CurrSize;
|
PA += CurrSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Info.Size == 0)
|
Node = Node.Next;
|
||||||
{
|
|
||||||
throw new InvalidOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
CurrPosition = Info.Position + Info.Size;
|
|
||||||
}
|
}
|
||||||
while ((ulong)CurrPosition < (ulong)End);
|
while ((ulong)(Info.Position + Info.Size) < (ulong)End && Node != null);
|
||||||
|
|
||||||
PersonalMmHeapUsage += RemainingSize;
|
PersonalMmHeapUsage += RemainingSize;
|
||||||
|
|
||||||
|
@ -675,9 +669,13 @@ namespace Ryujinx.HLE.OsHle.Handles
|
||||||
|
|
||||||
long CurrPosition = Position;
|
long CurrPosition = Position;
|
||||||
|
|
||||||
|
KMemoryInfo Info;
|
||||||
|
|
||||||
|
LinkedListNode<KMemoryBlock> Node = FindBlockNode(CurrPosition);
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
KMemoryInfo Info = FindBlock(CurrPosition).GetInfo();
|
Info = Node.Value.GetInfo();
|
||||||
|
|
||||||
if (Info.State == MemoryState.Heap)
|
if (Info.State == MemoryState.Heap)
|
||||||
{
|
{
|
||||||
|
@ -693,14 +691,9 @@ namespace Ryujinx.HLE.OsHle.Handles
|
||||||
return MakeError(ErrorModule.Kernel, KernelErr.NoAccessPerm);
|
return MakeError(ErrorModule.Kernel, KernelErr.NoAccessPerm);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Info.Size == 0)
|
Node = Node.Next;
|
||||||
{
|
|
||||||
throw new InvalidOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
CurrPosition = Info.Position + Info.Size;
|
|
||||||
}
|
}
|
||||||
while ((ulong)CurrPosition < (ulong)End);
|
while ((ulong)(Info.Position + Info.Size) < (ulong)End && Node != null);
|
||||||
|
|
||||||
if (HeapMappedSize == 0)
|
if (HeapMappedSize == 0)
|
||||||
{
|
{
|
||||||
|
@ -1055,6 +1048,11 @@ namespace Ryujinx.HLE.OsHle.Handles
|
||||||
}
|
}
|
||||||
|
|
||||||
private KMemoryBlock FindBlock(long Position)
|
private KMemoryBlock FindBlock(long Position)
|
||||||
|
{
|
||||||
|
return FindBlockNode(Position)?.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private LinkedListNode<KMemoryBlock> FindBlockNode(long Position)
|
||||||
{
|
{
|
||||||
ulong Addr = (ulong)Position;
|
ulong Addr = (ulong)Position;
|
||||||
|
|
||||||
|
@ -1071,7 +1069,7 @@ namespace Ryujinx.HLE.OsHle.Handles
|
||||||
|
|
||||||
if (Start <= Addr && End - 1 >= Addr)
|
if (Start <= Addr && End - 1 >= Addr)
|
||||||
{
|
{
|
||||||
return Block;
|
return Node;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node = Node.Next;
|
Node = Node.Next;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue