1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/sys_info.h"
9 #include "base/file_util.h"
10 #include "base/logging.h"
11 #include "base/string_number_conversions.h"
15 int64
SysInfo::AmountOfPhysicalMemory() {
16 long pages
= sysconf(_SC_PHYS_PAGES
);
17 long page_size
= sysconf(_SC_PAGE_SIZE
);
18 if (pages
== -1 || page_size
== -1) {
23 return static_cast<int64
>(pages
) * page_size
;
27 size_t SysInfo::MaxSharedMemorySize() {
29 static bool limit_valid
= false;
32 file_util::ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents
);
33 DCHECK(!contents
.empty());
34 if (!contents
.empty() && contents
[contents
.length() - 1] == '\n') {
35 contents
.erase(contents
.length() - 1);
37 if (base::StringToInt64(contents
, &limit
)) {
39 DCHECK(static_cast<uint64
>(limit
) <= std::numeric_limits
<size_t>::max());
46 return static_cast<size_t>(limit
);