Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2834)

Unified Diff: base/sys_info_mac.mm

Issue 2558043007: Fix free memory calculation. (Closed)
Patch Set: Fix integer overflow in unittest. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/sys_info_linux.cc ('k') | base/sys_info_openbsd.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/sys_info_mac.mm
diff --git a/base/sys_info_mac.mm b/base/sys_info_mac.mm
index aab1103d4c401d14efc6bf7eecb30c208b9a5d98..1141bd557768bab8eb387dd62668831edd40bd92 100644
--- a/base/sys_info_mac.mm
+++ b/base/sys_info_mac.mm
@@ -19,6 +19,7 @@
#include "base/mac/scoped_mach_port.h"
#import "base/mac/sdk_forward_declarations.h"
#include "base/macros.h"
+#include "base/process/process_metrics.h"
#include "base/strings/stringprintf.h"
namespace base {
@@ -83,20 +84,12 @@ int64_t SysInfo::AmountOfPhysicalMemory() {
// static
int64_t SysInfo::AmountOfAvailablePhysicalMemory() {
- base::mac::ScopedMachSendRight host(mach_host_self());
- vm_statistics_data_t vm_info;
- mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
-
- if (host_statistics(host.get(),
- HOST_VM_INFO,
- reinterpret_cast<host_info_t>(&vm_info),
- &count) != KERN_SUCCESS) {
- NOTREACHED();
+ SystemMemoryInfoKB info;
+ if (!GetSystemMemoryInfo(&info))
return 0;
- }
-
- return static_cast<int64_t>(vm_info.free_count - vm_info.speculative_count) *
- PAGE_SIZE;
+ // We should add inactive file-backed memory also but there is no such
+ // information from Mac OS unfortunately.
+ return static_cast<int64_t>(info.free + info.speculative) * 1024;
}
// static
« no previous file with comments | « base/sys_info_linux.cc ('k') | base/sys_info_openbsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698