WebKit roll 98705:98715
[chromium-blink-merge.git] / base / sys_info_linux.cc
blob03fdac28e58c9326eec145774544d0a2bd585575
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"
7 #include <limits>
9 #include "base/file_util.h"
10 #include "base/logging.h"
11 #include "base/string_number_conversions.h"
13 namespace base {
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) {
19 NOTREACHED();
20 return 0;
23 return static_cast<int64>(pages) * page_size;
26 // static
27 size_t SysInfo::MaxSharedMemorySize() {
28 static int64 limit;
29 static bool limit_valid = false;
30 if (!limit_valid) {
31 std::string contents;
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)) {
38 DCHECK(limit >= 0);
39 DCHECK(static_cast<uint64>(limit) <= std::numeric_limits<size_t>::max());
40 limit_valid = true;
41 } else {
42 NOTREACHED();
43 return 0;
46 return static_cast<size_t>(limit);
49 } // namespace base