diff options
Diffstat (limited to 'indra/llcommon/llmemory.h')
| -rw-r--r-- | indra/llcommon/llmemory.h | 63 |
1 files changed, 35 insertions, 28 deletions
diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index c06ae93766..b02458d8d2 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -4,7 +4,7 @@ * * $LicenseInfo:firstyear=2002&license=viewerlgpl$ * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. + * Copyright (C) 2026, Linden Research, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -27,6 +27,7 @@ #define LLMEMORY_H #include "linden_common.h" +#include "llframetimer.h" #include "llunits.h" #include "stdtypes.h" #if !LL_WINDOWS @@ -48,6 +49,9 @@ class LLMutex ; #define LL_ALIGN_OF __align_of__ #endif +#if defined(LL_X86_64) || defined(LL_ARM64) +#define LL_DEFAULT_HEAP_ALIGN 16 +#else #if LL_WINDOWS #define LL_DEFAULT_HEAP_ALIGN 8 #elif LL_DARWIN @@ -55,7 +59,7 @@ class LLMutex ; #elif LL_LINUX || __FreeBSD__ #define LL_DEFAULT_HEAP_ALIGN 8 #endif - +#endif LL_COMMON_API void ll_assert_aligned_func(uintptr_t ptr,U32 alignment); @@ -89,22 +93,6 @@ template <typename T> T* LL_NEXT_ALIGNED_ADDRESS_64(T* address) (uintptr_t(address) + 0x3F) & ~0x3F); } -#if LL_LINUX || LL_DARWIN || __FreeBSD__ - -#define LL_ALIGN_PREFIX(x) -#define LL_ALIGN_POSTFIX(x) __attribute__((aligned(x))) - -#elif LL_WINDOWS - -#define LL_ALIGN_PREFIX(x) __declspec(align(x)) -#define LL_ALIGN_POSTFIX(x) - -#else -#error "LL_ALIGN_PREFIX and LL_ALIGN_POSTFIX undefined" -#endif - -#define LL_ALIGN_16(var) LL_ALIGN_PREFIX(16) var LL_ALIGN_POSTFIX(16) - #define LL_ALIGN_NEW \ public: \ void* operator new(size_t size) \ @@ -127,7 +115,6 @@ public: \ ll_aligned_free_16(ptr); \ } - //------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------ // for enable buffer overrun detection predefine LL_DEBUG_BUFFER_OVERRUN in current library @@ -143,6 +130,10 @@ public: \ LL_PROFILE_ZONE_SCOPED_CATEGORY_MEMORY; #if defined(LL_WINDOWS) void* ret = _aligned_malloc(size, align); + #elif defined(LL_LINUX) + void *ret; + if (0 != posix_memalign(&ret, align, size)) + return nullptr; #else char* aligned = NULL; void* mem = malloc( size + (align - 1) + sizeof(void*) ); @@ -165,6 +156,8 @@ public: \ LL_PROFILE_FREE(ptr); #if defined(LL_WINDOWS) _aligned_free(ptr); + #elif defined(LL_LINUX) + free(ptr); #else if (ptr) { @@ -179,10 +172,10 @@ public: \ inline void* ll_aligned_malloc_16(size_t size) // returned hunk MUST be freed with ll_aligned_free_16(). { LL_PROFILE_ZONE_SCOPED_CATEGORY_MEMORY; -#if defined(LL_WINDOWS) +#if LL_DEFAULT_HEAP_ALIGN == 16 + void* ret = malloc(size); // default osx and 64-bit malloc is 16 byte aligned. +#elif defined(LL_WINDOWS) void* ret = _aligned_malloc(size, 16); -#elif defined(LL_DARWIN) - void* ret = malloc(size); // default osx malloc is 16 byte aligned. #else void *ret; if (0 != posix_memalign(&ret, 16, size)) @@ -196,10 +189,10 @@ inline void ll_aligned_free_16(void *p) { LL_PROFILE_ZONE_SCOPED_CATEGORY_MEMORY; LL_PROFILE_FREE(p); -#if defined(LL_WINDOWS) +#if LL_DEFAULT_HEAP_ALIGN == 16 + free(p); +#elif defined(LL_WINDOWS) _aligned_free(p); -#elif defined(LL_DARWIN) - return free(p); #else free(p); // posix_memalign() is compatible with heap deallocator #endif @@ -209,10 +202,10 @@ inline void* ll_aligned_realloc_16(void* ptr, size_t size, size_t old_size) // r { LL_PROFILE_ZONE_SCOPED_CATEGORY_MEMORY; LL_PROFILE_FREE(ptr); -#if defined(LL_WINDOWS) +#if LL_DEFAULT_HEAP_ALIGN == 16 + void* ret = realloc(ptr,size); // default osx and 64bit malloc is 16 byte aligned. +#elif defined(LL_WINDOWS) void* ret = _aligned_realloc(ptr, size, 16); -#elif defined(LL_DARWIN) - void* ret = realloc(ptr,size); // default osx malloc is 16 byte aligned. #else //FIXME: memcpy is SLOW void* ret = ll_aligned_malloc_16(size); @@ -428,17 +421,31 @@ public: static void initMaxHeapSizeGB(F32Gigabytes max_heap_size); static void updateMemoryInfo() ; static void logMemoryInfo(bool update = false); + static F32 getSystemMemoryBudgetFactor(); +#if LL_WINDOWS + // Commit charge is a Windows-only concept, combines page file and ram + static U32Megabytes getAvailableCommitMemMB(); +#endif static U32Kilobytes getAvailableMemKB() ; static U32Kilobytes getMaxMemKB() ; static U32Kilobytes getAllocatedMemKB() ; private: + static void updateFreeSystemMemory(); + // LLMemoryInfo directly updates memory stats + friend class LLMemoryInfo; + + static U32Megabytes sAvailCommitMemInMB; static U32Kilobytes sAvailPhysicalMemInKB ; static U32Kilobytes sMaxPhysicalMemInKB ; static U32Kilobytes sAllocatedMemInKB; static U32Kilobytes sAllocatedPageSizeInKB ; static U32Kilobytes sMaxHeapSizeInKB; + + static LLFrameTimer sMemoryCheckTimer; + static F32 sSysMemoryFactor; + static U32 sFactorLastFrameCount; }; // LLRefCount moved to llrefcount.h |
