From ad061b4322afd211f60403dd780c5f95da71f42e Mon Sep 17 00:00:00 2001 From: Beq Date: Sun, 23 Jun 2024 14:20:23 +0100 Subject: [PATCH] WiP to realign the physical ram detection across platforms --- indra/llcommon/llmemory.cpp | 62 +++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/indra/llcommon/llmemory.cpp b/indra/llcommon/llmemory.cpp index cf5ead718d..eab87df300 100644 --- a/indra/llcommon/llmemory.cpp +++ b/indra/llcommon/llmemory.cpp @@ -39,6 +39,7 @@ #elif LL_LINUX # include # include +# inlcude #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; // 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); + // 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); - } - + // #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(); - } + // 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(); + // + } else { LL_WARNS() << "task_info failed" << LL_ENDL; } - + // 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) + // #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 + // 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); + } + // return ; }