File tree 2 files changed +46
-0
lines changed
2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,31 @@ bool IsRunningInXen()
125
125
return true ;
126
126
}
127
127
128
+ Result<uint64_t > GetPhysicallyInstalledSystemMemoryApi ()
129
+ {
130
+ using FnGetPhysicallyInstalledSystemMemory = BOOL (__stdcall*)(PULONGLONG);
131
+
132
+ static FnGetPhysicallyInstalledSystemMemory fn = nullptr ;
133
+ if (fn == nullptr )
134
+ {
135
+ fn = reinterpret_cast <FnGetPhysicallyInstalledSystemMemory>(
136
+ ::GetProcAddress (GetModuleHandleA(" kernel32.dll" ), "GetPhysicallyInstalledSystemMemory"));
137
+ if (!fn)
138
+ {
139
+ return LastWin32Error ();
140
+ }
141
+ }
142
+
143
+ uint64_t installed = 0 ;
144
+ BOOL ret = fn (&installed);
145
+ if (!ret)
146
+ {
147
+ return LastWin32Error ();
148
+ }
149
+
150
+ return installed;
151
+ }
152
+
128
153
} // namespace
129
154
130
155
namespace Orc {
@@ -724,6 +749,26 @@ Result<uint64_t> SystemDetails::GetPhysicalMemoryAdjustedSize()
724
749
return roundedToGB;
725
750
}
726
751
752
+ // Attempt to get the real installed memory size (GlobalMemoryStatusEx exclude some bytes)
753
+ Result<uint64_t > SystemDetails::GetPhysicalMemoryInstalledSize ()
754
+ {
755
+ auto memory = ::GetPhysicallyInstalledSystemMemoryApi ();
756
+ if (memory)
757
+ {
758
+ return *memory * 1024 ;
759
+ }
760
+
761
+ Log::Debug (" Failed GetPhysicallyInstalledSystemMemory [{}]" , memory);
762
+
763
+ memory = SystemDetails::GetPhysicalMemoryAdjustedSize ();
764
+ if (memory)
765
+ {
766
+ return *memory;
767
+ }
768
+
769
+ return memory.error ();
770
+ }
771
+
727
772
HRESULT SystemDetails::GetPageSize (DWORD& dwPageSize)
728
773
{
729
774
HRESULT hr = E_FAIL;
Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ class SystemDetails
77
77
78
78
static Result<MEMORYSTATUSEX> GetPhysicalMemory ();
79
79
static Result<uint64_t > GetPhysicalMemoryAdjustedSize ();
80
+ static Result<uint64_t > GetPhysicalMemoryInstalledSize ();
80
81
81
82
static HRESULT GetPageSize (DWORD& dwPageSize);
82
83
static HRESULT GetLargePageSize (DWORD& dwPageSize);
You can’t perform that action at this time.
0 commit comments