WiP to realign the physical ram detection across platforms
parent
cf16839ed9
commit
ad061b4322
|
|
@ -39,6 +39,7 @@
|
|||
#elif LL_LINUX
|
||||
# include <unistd.h>
|
||||
# include <sys/resource.h>
|
||||
# inlcude <sys/sysinfo.h>
|
||||
#endif
|
||||
|
||||
#include "llmemory.h"
|
||||
|
|
@ -85,6 +86,7 @@ void LLMemory::initMaxHeapSizeGB(F32Gigabytes max_heap_size)
|
|||
void LLMemory::updateMemoryInfo()
|
||||
{
|
||||
LL_PROFILE_ZONE_SCOPED
|
||||
U32Kilobytes avail_phys; // <FS:Beq/> align MemInfo across platforms
|
||||
#if LL_WINDOWS
|
||||
PROCESS_MEMORY_COUNTERS counters;
|
||||
|
||||
|
|
@ -98,20 +100,22 @@ void LLMemory::updateMemoryInfo()
|
|||
sample(sAllocatedMem, sAllocatedMemInKB);
|
||||
sAllocatedPageSizeInKB = U32Kilobytes::convert(U64Bytes(counters.PagefileUsage));
|
||||
sample(sVirtualMem, sAllocatedPageSizeInKB);
|
||||
// <FS:Beq> align MemInfo across platforms
|
||||
// U32Kilobytes avail_phys, avail_virtual;
|
||||
// LLMemoryInfo::getAvailableMemoryKB(avail_phys, avail_virtual) ;
|
||||
// sMaxPhysicalMemInKB = llmin(avail_phys + sAllocatedMemInKB, sMaxHeapSizeInKB);
|
||||
|
||||
U32Kilobytes avail_phys, avail_virtual;
|
||||
// if(sMaxPhysicalMemInKB > sAllocatedMemInKB)
|
||||
// {
|
||||
// sAvailPhysicalMemInKB = sMaxPhysicalMemInKB - sAllocatedMemInKB ;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// sAvailPhysicalMemInKB = U32Kilobytes(0);
|
||||
// }
|
||||
U32Kilobytes avail_virtual;
|
||||
LLMemoryInfo::getAvailableMemoryKB(avail_phys, avail_virtual) ;
|
||||
sMaxPhysicalMemInKB = llmin(avail_phys + sAllocatedMemInKB, sMaxHeapSizeInKB);
|
||||
|
||||
if(sMaxPhysicalMemInKB > sAllocatedMemInKB)
|
||||
{
|
||||
sAvailPhysicalMemInKB = sMaxPhysicalMemInKB - sAllocatedMemInKB ;
|
||||
}
|
||||
else
|
||||
{
|
||||
sAvailPhysicalMemInKB = U32Kilobytes(0);
|
||||
}
|
||||
|
||||
// </FS:Beq>
|
||||
#elif defined(LL_DARWIN)
|
||||
task_vm_info info;
|
||||
mach_msg_type_number_t infoCount = TASK_VM_INFO_COUNT;
|
||||
|
|
@ -147,21 +151,47 @@ void LLMemory::updateMemoryInfo()
|
|||
if (result == KERN_SUCCESS) {
|
||||
// This is what Chrome reports as 'the "Physical Memory Free" value reported by the Memory Monitor in Instruments.'
|
||||
// Note though that inactive pages are not included here and not yet free, but could become so under memory pressure.
|
||||
sAvailPhysicalMemInKB = U32Bytes(vmstat.free_count * page_size);
|
||||
sMaxPhysicalMemInKB = LLMemoryInfo::getHardwareMemSize();
|
||||
}
|
||||
// <FS:Beq> align MemInfo across platforms
|
||||
// sAvailPhysicalMemInKB = U32Bytes(vmstat.free_count * page_size);
|
||||
// sMaxPhysicalMemInKB = LLMemoryInfo::getHardwareMemSize();
|
||||
avail_phys = U32Bytes(vmstat.free_count * page_size);
|
||||
sMaxHeapSizeInKB = LLMemoryInfo::getHardwareMemSize();
|
||||
// </FS:Beq>
|
||||
}
|
||||
else
|
||||
{
|
||||
LL_WARNS() << "task_info failed" << LL_ENDL;
|
||||
}
|
||||
|
||||
// <FS:Beq> align MemInfo across platforms
|
||||
#elif defined(LL_LINUX)
|
||||
// Use sysinfo() to get the total physical memory.
|
||||
struct sysinfo info;
|
||||
sysinfo(&info);
|
||||
sMaxHeapSizeInKB = U32Kilobytes::convert(info.totalram); // Total RAM in system
|
||||
avail_phys = U32Kilobytes::convert(info.freeram); // Total Free RAM in system
|
||||
sAllocatedMemInKB = U64Bytes(LLMemory::getCurrentRSS()); // represents the RAM allocated by this process only (inline with the windows implementation)
|
||||
// </FS:Beq>
|
||||
#else
|
||||
//not valid for other systems for now.
|
||||
LL_WARNS() << "LLMemory::updateMemoryInfo() not implemented for this platform." << LL_ENDL;
|
||||
sAllocatedMemInKB = U64Bytes(LLMemory::getCurrentRSS());
|
||||
sMaxPhysicalMemInKB = U64Bytes(U32_MAX);
|
||||
sAvailPhysicalMemInKB = U64Bytes(U32_MAX);
|
||||
#endif
|
||||
// <FS:Beq> align MemInfo across platforms
|
||||
sample(sAllocatedMem, sAllocatedMemInKB);
|
||||
// sMaxPhysicalMem - max this process can use = the lesser of (what we already have + what's available) or MaxHeap
|
||||
sMaxPhysicalMemInKB = llmin(avail_phys + sAllocatedMemInKB, sMaxHeapSizeInKB);
|
||||
|
||||
if(sMaxPhysicalMemInKB > sAllocatedMemInKB)
|
||||
{
|
||||
sAvailPhysicalMemInKB = sMaxPhysicalMemInKB - sAllocatedMemInKB ;
|
||||
}
|
||||
else
|
||||
{
|
||||
sAvailPhysicalMemInKB = U32Kilobytes(0);
|
||||
}
|
||||
// </FS:Beq>
|
||||
return ;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue