OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/sys_info.h" | 5 #include "base/sys_info.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "base/threading/thread_restrictions.h" | 21 #include "base/threading/thread_restrictions.h" |
22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
23 | 23 |
24 #if defined(OS_ANDROID) | 24 #if defined(OS_ANDROID) |
25 #include <sys/vfs.h> | 25 #include <sys/vfs.h> |
26 #define statvfs statfs // Android uses a statvfs-like statfs struct and call. | 26 #define statvfs statfs // Android uses a statvfs-like statfs struct and call. |
27 #else | 27 #else |
28 #include <sys/statvfs.h> | 28 #include <sys/statvfs.h> |
29 #endif | 29 #endif |
30 | 30 |
31 #if defined(OS_LINUX) | |
32 #include <sys/vfs.h> | |
33 #include <linux/magic.h> | |
Lei Zhang
2016/08/02 19:35:41
alphabetical order
| |
34 #endif | |
35 | |
31 namespace { | 36 namespace { |
32 | 37 |
33 #if !defined(OS_OPENBSD) | 38 #if !defined(OS_OPENBSD) |
34 int NumberOfProcessors() { | 39 int NumberOfProcessors() { |
35 // sysconf returns the number of "logical" (not "physical") processors on both | 40 // sysconf returns the number of "logical" (not "physical") processors on both |
36 // Mac and Linux. So we get the number of max available "logical" processors. | 41 // Mac and Linux. So we get the number of max available "logical" processors. |
37 // | 42 // |
38 // Note that the number of "currently online" processors may be fewer than the | 43 // Note that the number of "currently online" processors may be fewer than the |
39 // returned value of NumberOfProcessors(). On some platforms, the kernel may | 44 // returned value of NumberOfProcessors(). On some platforms, the kernel may |
40 // make some processors offline intermittently, to save power when system | 45 // make some processors offline intermittently, to save power when system |
(...skipping 25 matching lines...) Expand all Loading... | |
66 NOTREACHED(); | 71 NOTREACHED(); |
67 return 0; | 72 return 0; |
68 } | 73 } |
69 return limit.rlim_cur == RLIM_INFINITY ? 0 : limit.rlim_cur; | 74 return limit.rlim_cur == RLIM_INFINITY ? 0 : limit.rlim_cur; |
70 } | 75 } |
71 | 76 |
72 base::LazyInstance< | 77 base::LazyInstance< |
73 base::internal::LazySysInfoValue<int64_t, AmountOfVirtualMemory>>::Leaky | 78 base::internal::LazySysInfoValue<int64_t, AmountOfVirtualMemory>>::Leaky |
74 g_lazy_virtual_memory = LAZY_INSTANCE_INITIALIZER; | 79 g_lazy_virtual_memory = LAZY_INSTANCE_INITIALIZER; |
75 | 80 |
81 #if defined(OS_LINUX) | |
82 bool IsStatsZeroIfUnlimited(const base::FilePath& path) { | |
83 struct statfs stats; | |
84 | |
85 if (HANDLE_EINTR(statfs(path.value().c_str(), &stats)) != 0) | |
86 return false; | |
87 | |
88 return stats.f_type == TMPFS_MAGIC || stats.f_type == HUGETLBFS_MAGIC || | |
89 stats.f_type == RAMFS_MAGIC; | |
90 } | |
91 #endif | |
92 | |
76 bool GetDiskSpaceInfo(const base::FilePath& path, | 93 bool GetDiskSpaceInfo(const base::FilePath& path, |
77 int64_t* available_bytes, | 94 int64_t* available_bytes, |
78 int64_t* total_bytes) { | 95 int64_t* total_bytes) { |
79 struct statvfs stats; | 96 struct statvfs stats; |
80 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0) | 97 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0) |
81 return false; | 98 return false; |
82 | 99 |
83 if (available_bytes) | 100 #if defined(OS_LINUX) |
84 *available_bytes = static_cast<int64_t>(stats.f_bavail) * stats.f_frsize; | 101 const bool zero_size_means_unlimited = |
85 if (total_bytes) | 102 stats.f_blocks == 0 && IsStatsZeroIfUnlimited(path); |
86 *total_bytes = static_cast<int64_t>(stats.f_blocks) * stats.f_frsize; | 103 #else |
104 const bool zero_size_means_unlimited = false; | |
105 #endif | |
106 | |
107 if (available_bytes) { | |
108 *available_bytes = | |
109 zero_size_means_unlimited | |
110 ? std::numeric_limits<int64_t>::max() | |
111 : static_cast<int64_t>(stats.f_bavail) * stats.f_frsize; | |
112 } | |
113 | |
114 if (total_bytes) { | |
115 *total_bytes = zero_size_means_unlimited | |
116 ? std::numeric_limits<int64_t>::max() | |
117 : static_cast<int64_t>(stats.f_blocks) * stats.f_frsize; | |
118 } | |
87 return true; | 119 return true; |
88 } | 120 } |
89 | 121 |
90 } // namespace | 122 } // namespace |
91 | 123 |
92 namespace base { | 124 namespace base { |
93 | 125 |
94 #if !defined(OS_OPENBSD) | 126 #if !defined(OS_OPENBSD) |
95 int SysInfo::NumberOfProcessors() { | 127 int SysInfo::NumberOfProcessors() { |
96 return g_lazy_number_of_processors.Get().value(); | 128 return g_lazy_number_of_processors.Get().value(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 } | 193 } |
162 return arch; | 194 return arch; |
163 } | 195 } |
164 | 196 |
165 // static | 197 // static |
166 size_t SysInfo::VMAllocationGranularity() { | 198 size_t SysInfo::VMAllocationGranularity() { |
167 return getpagesize(); | 199 return getpagesize(); |
168 } | 200 } |
169 | 201 |
170 } // namespace base | 202 } // namespace base |
OLD | NEW |