Ticket #55278: patch-Source-WTF-wtf-ramsize.cpp.diff
File patch-Source-WTF-wtf-ramsize.cpp.diff, 2.6 KB (added by kencu (Ken), 7 years ago) |
---|
-
Source/WTF/wtf/RAMSize.cpp
diff --git Source/WTF/wtf/RAMSize.cpp Source/WTF/wtf/RAMSize.cpp index 5d34d3b..3dd516c 100644
29 29 #include "StdLibExtras.h" 30 30 #include <mutex> 31 31 32 #if OS(WINDOWS) 32 #if OS(DARWIN) 33 #import <dispatch/dispatch.h> 34 #import <mach/host_info.h> 35 #import <mach/mach.h> 36 #import <mach/mach_error.h> 37 #import <math.h> 38 #elif OS(UNIX) 39 #include <unistd.h> 40 #elif OS(WINDOWS) 33 41 #include <windows.h> 34 #elif defined(USE_SYSTEM_MALLOC) && USE_SYSTEM_MALLOC35 #if OS(UNIX)36 #include <sys/sysinfo.h>37 #endif // OS(UNIX)38 #else39 #include <bmalloc/bmalloc.h>40 42 #endif 41 43 42 44 namespace WTF { 43 45 44 #if OS(WINDOWS)45 46 static const size_t ramSizeGuess = 512 * MB; 46 #endif47 47 48 48 static size_t computeRAMSize() 49 49 { 50 #if OS(WINDOWS) 50 #if PLATFORM(IOS_SIMULATOR) 51 // Pretend we have 512MB of memory to make cache sizes behave like on device. 52 return ramSizeGuess; 53 #elif OS(DARWIN) 54 host_basic_info_data_t hostInfo; 55 56 mach_port_t host = mach_host_self(); 57 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; 58 kern_return_t r = host_info(host, HOST_BASIC_INFO, (host_info_t)&hostInfo, &count); 59 mach_port_deallocate(mach_task_self(), host); 60 if (r != KERN_SUCCESS) { 61 LOG_ERROR("%s : host_info(%d) : %s.\n", __FUNCTION__, r, mach_error_string(r)); 62 return ramSizeGuess; 63 } 64 65 if (hostInfo.max_mem > std::numeric_limits<size_t>::max()) 66 return std::numeric_limits<size_t>::max(); 67 68 size_t sizeAccordingToKernel = static_cast<size_t>(hostInfo.max_mem); 69 size_t multiple = 128 * MB; 70 71 // Round up the memory size to a multiple of 128MB because max_mem may not be exactly 512MB 72 // (for example) and we have code that depends on those boundaries. 73 return ((sizeAccordingToKernel + multiple - 1) / multiple) * multiple; 74 #elif OS(UNIX) 75 long pages = sysconf(_SC_PHYS_PAGES); 76 long pageSize = sysconf(_SC_PAGE_SIZE); 77 if (pages == -1 || pageSize == -1) 78 return ramSizeGuess; 79 return pages * pageSize; 80 #elif OS(WINDOWS) 51 81 MEMORYSTATUSEX status; 52 82 status.dwLength = sizeof(status); 53 83 bool result = GlobalMemoryStatusEx(&status); 54 84 if (!result) 55 85 return ramSizeGuess; 56 86 return status.ullTotalPhys; 57 #elif defined(USE_SYSTEM_MALLOC) && USE_SYSTEM_MALLOC58 #if OS(UNIX)59 struct sysinfo si;60 sysinfo(&si);61 return si.totalram * si.mem_unit;62 #else63 #error "Missing a platform specific way of determining the available RAM"64 #endif // OS(UNIX)65 #else66 return bmalloc::api::availableMemory();67 87 #endif 68 88 } 69 89 … … size_t ramSize() 77 97 return ramSize; 78 98 } 79 99 80 } // namespace WTF 100 } // namespace WTF 101 No newline at end of file