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

Side by Side Diff: base/process/process_metrics.h

Issue 2558043007: Fix free memory calculation. (Closed)
Patch Set: Fix review notes. Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/process/process_metrics_ios.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 // This file contains routines for gathering resource statistics for processes 5 // This file contains routines for gathering resource statistics for processes
6 // running on the system. 6 // running on the system.
7 7
8 #ifndef BASE_PROCESS_PROCESS_METRICS_H_ 8 #ifndef BASE_PROCESS_PROCESS_METRICS_H_
9 #define BASE_PROCESS_PROCESS_METRICS_H_ 9 #define BASE_PROCESS_PROCESS_METRICS_H_
10 10
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 #endif // defined(OS_POSIX) 257 #endif // defined(OS_POSIX)
258 258
259 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \ 259 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \
260 defined(OS_ANDROID) 260 defined(OS_ANDROID)
261 // Data about system-wide memory consumption. Values are in KB. Available on 261 // Data about system-wide memory consumption. Values are in KB. Available on
262 // Windows, Mac, Linux, Android and Chrome OS. 262 // Windows, Mac, Linux, Android and Chrome OS.
263 // 263 //
264 // Total/free memory are available on all platforms that implement 264 // Total/free memory are available on all platforms that implement
265 // GetSystemMemoryInfo(). Total/free swap memory are available on all platforms 265 // GetSystemMemoryInfo(). Total/free swap memory are available on all platforms
266 // except on Mac. Buffers/cached/active_anon/inactive_anon/active_file/ 266 // except on Mac. Buffers/cached/active_anon/inactive_anon/active_file/
267 // inactive_file/dirty/pswpin/pswpout/pgmajfault are available on 267 // inactive_file/dirty/reclaimable/pswpin/pswpout/pgmajfault are available on
268 // Linux/Android/Chrome OS. Shmem/slab/gem_objects/gem_size are Chrome OS only. 268 // Linux/Android/Chrome OS. Shmem/slab/gem_objects/gem_size are Chrome OS only.
269 // Speculative/file_backed/purgeable are Mac and iOS only.
269 struct BASE_EXPORT SystemMemoryInfoKB { 270 struct BASE_EXPORT SystemMemoryInfoKB {
270 SystemMemoryInfoKB(); 271 SystemMemoryInfoKB();
271 SystemMemoryInfoKB(const SystemMemoryInfoKB& other); 272 SystemMemoryInfoKB(const SystemMemoryInfoKB& other);
272 273
273 // Serializes the platform specific fields to value. 274 // Serializes the platform specific fields to value.
274 std::unique_ptr<Value> ToValue() const; 275 std::unique_ptr<Value> ToValue() const;
275 276
276 int total; 277 int total;
277 int free; 278 int free;
278 279
279 #if defined(OS_LINUX) 280 #if defined(OS_WIN)
281 // There are Free and Zero memory on Windows platform.
282 // See "Memory Management" and "Memory Performance Information"
283 // articles at MSDN.
284 int zero;
Primiano Tucci (use gerrit) 2017/02/20 14:13:27 Why this needs to be exposed at an API level? I un
Michael K. (Yandex Team) 2017/02/20 14:33:13 You're right: currently nobody uses it. ...Except
285
286 // "This is the amount of physical memory that can be immediately reused
287 // without having to write its contents to disk first. It is the sum of the
288 // size of the standby, free, and zero lists." (MSDN).
289 // Standby: not modified pages of physical ram (file-backed memory) that are
290 // not actively being used.
291 // Note: on Windows this field has a bit different meaning from the Linux one.
292 // On Linux "available" includes _all_ file-backed memory (active + inactive).
Primiano Tucci (use gerrit) 2017/02/20 14:13:27 note that you are saying "on linux" but this line
Michael K. (Yandex Team) 2017/02/20 14:33:14 Because I wanted to explain what "different" exact
293 int available;
294 #endif
295
296 #if defined(OS_LINUX) || defined(OS_ANDROID)
280 // This provides an estimate of available memory as described here: 297 // This provides an estimate of available memory as described here:
281 // https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id= 34e431b0ae398fc54ea69ff85ec700722c9da773 298 // https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id= 34e431b0ae398fc54ea69ff85ec700722c9da773
282 // NOTE: this is ONLY valid in kernels 3.14 and up. Its value will always 299 // NOTE: this is ONLY valid in kernels 3.14 and up. Its value will always
283 // be 0 in earlier kernel versions. 300 // be 0 in earlier kernel versions.
284 int available; 301 int available;
285 #endif 302 #endif
286 303
287 #if !defined(OS_MACOSX) 304 #if !defined(OS_MACOSX)
288 int swap_total; 305 int swap_total;
289 int swap_free; 306 int swap_free;
290 #endif 307 #endif
291 308
292 #if defined(OS_ANDROID) || defined(OS_LINUX) 309 #if defined(OS_ANDROID) || defined(OS_LINUX)
293 int buffers; 310 int buffers;
294 int cached; 311 int cached;
295 int active_anon; 312 int active_anon;
296 int inactive_anon; 313 int inactive_anon;
297 int active_file; 314 int active_file;
298 int inactive_file; 315 int inactive_file;
299 int dirty; 316 int dirty;
317 int reclaimable;
300 318
301 // vmstats data. 319 // vmstats data.
302 unsigned long pswpin; 320 unsigned long pswpin;
303 unsigned long pswpout; 321 unsigned long pswpout;
304 unsigned long pgmajfault; 322 unsigned long pgmajfault;
305 #endif // defined(OS_ANDROID) || defined(OS_LINUX) 323 #endif // defined(OS_ANDROID) || defined(OS_LINUX)
306 324
307 #if defined(OS_CHROMEOS) 325 #if defined(OS_CHROMEOS)
308 int shmem; 326 int shmem;
309 int slab; 327 int slab;
310 // Gem data will be -1 if not supported. 328 // Gem data will be -1 if not supported.
311 int gem_objects; 329 int gem_objects;
312 long long gem_size; 330 long long gem_size;
313 #endif // defined(OS_CHROMEOS) 331 #endif // defined(OS_CHROMEOS)
332
333 #if defined(OS_MACOSX) || defined(OS_IOS)
334 int speculative;
335 int file_backed;
336 int purgeable;
337 #endif
314 }; 338 };
315 339
316 // On Linux/Android/Chrome OS, system-wide memory consumption data is parsed 340 // On Linux/Android/Chrome OS, system-wide memory consumption data is parsed
317 // from /proc/meminfo and /proc/vmstat. On Windows/Mac, it is obtained using 341 // from /proc/meminfo and /proc/vmstat. On Windows/Mac, it is obtained using
318 // system API calls. 342 // system API calls.
319 // 343 //
320 // Fills in the provided |meminfo| structure. Returns true on success. 344 // Fills in the provided |meminfo| structure. Returns true on success.
321 // Exposed for memory debugging widget. 345 // Exposed for memory debugging widget.
322 BASE_EXPORT bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo); 346 BASE_EXPORT bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo);
323 347
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 SystemDiskInfo disk_info_; 454 SystemDiskInfo disk_info_;
431 #endif 455 #endif
432 #if defined(OS_CHROMEOS) 456 #if defined(OS_CHROMEOS)
433 SwapInfo swap_info_; 457 SwapInfo swap_info_;
434 #endif 458 #endif
435 }; 459 };
436 460
437 } // namespace base 461 } // namespace base
438 462
439 #endif // BASE_PROCESS_PROCESS_METRICS_H_ 463 #endif // BASE_PROCESS_PROCESS_METRICS_H_
OLDNEW
« no previous file with comments | « no previous file | base/process/process_metrics_ios.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698