Commit graph

19 commits

Author SHA1 Message Date
Christopher Ferris
23f2a0b166 Add method to get usage stats for a single map.
The new scudo allocator creates a huge map in 64 bit address space. Some
tests would get the usage stats of all maps, but only really cared about
a small set of maps. In this case, provide a method to only get the usage
stats for the maps you care about.

Test: Unit tests pass.
Change-Id: Ie845e47a8c789a57bf689c9f0e5878a921640e30
2019-10-10 15:10:27 -07:00
Christopher Ferris
504d2cce64 Optimize code that only uses PageMap call.
Some code only wants to use PageMap to determine whether pages are
mapped in to memory. Modify the code to optimize this path.

Changes:
- Add a function that doesn't read all of usage stats data for every
  map. This operation is extremely expensive, and some code doesn't
  care about it.
- Optimize the PageMap call to do a single read instead of a single
  read per page.
- Add unit tests for these changes.

Bug: 136245508

Test: Ran new unit tests.
Test: Ran procrank and verified data looks good.
Test: Ran DexDiag art tests.
Change-Id: I37d03f2584551d26cb20be3abacdb958111d4eca
2019-07-12 16:28:09 -07:00
Christopher Ferris
d943301990 Fix error printing code.
Test: Induced error and verified the errors print properly in logcat.
Change-Id: Ie0e6e71671a8a3e26b4632f93bb2af089a20e2e0
2019-06-28 18:11:12 -07:00
Christopher Ferris
7f8915c76e Cache only a small portion of page map data.
The scudo memory allocator will allocate a large virtual memory address
that causes procrank to allocate a huge amount of data. Modify so it
caches the data a bit at a time.

Remove some allocations that are not necessary since the data is only used
in the first loop.

Fix a few pread64 checks against the actual bytes read, rather than the
read is < 0.

Fix sort by rss in procrank.

Bug: 135694447

Test: Ran unit tests (only one unit test actually runs the modified code).
Test: Ran the old version of procrank using a static libmeminfo and verified
Test: that the same data is found as the new version.

Change-Id: I8adc169b5607ec994ff13a9e161a479350d84c4d
2019-06-25 21:14:36 -07:00
Sandeep Patil
f31c70989b procinfo: Read inode number from /proc/<pid>/maps
Adjust all callbacks to include the inode number as well.

Fixes: 123532375
Test: libprocinfo_test
Test: libdmabufinfo_test
Test: libmeminfo_test

Change-Id: I71fd75d90d5ee44585011c5ae654a1dd7e185458
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-02-11 01:38:08 +00:00
Sandeep Patil
061b71339c meminfo: Add support to track working set with idle page tracking.
Also adds a tool to make use of this if it exists call 'wsstop'

Bug: 111694435
Test: wsstop -d 3 -n 100 1

Change-Id: I50415f0bdc09c09b5b414cf0e4fff8f2907c5823
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-01-23 22:53:46 -08:00
Sandeep Patil
cbc8f123d8 meminfo: Add API to read pagemap for a vma within a process.
.. and make sure we have some helper methods exposed to the clients
to do some basic checks for the pagemap values. For example, to check
if the page is present or swapped.

Bug: 111694435
Test: libmeminfo_test 1 --gtest_filter=ValidateProcMemInfo.TestPageMap
Test: libmeminfo_test 1

Change-Id: Ic6ae91f4214b42346f3d0b54164a43ac79d5ade1
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-01-21 17:24:54 -08:00
Sandeep Patil
3fcb44b908 procmeminfo: use getline() instead of fgets() everywhere
Bug: 111694435
Test: libmeminfo_test 1 --gtest_filter=TestProcMemInfo.*

Change-Id: Idfc797aa65f45e0152765605c14622e2110dfdc1
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-01-14 18:11:53 -08:00
Sandeep Patil
dfd34be42b meminfo: Add IsSmapsRollupSupported Api
Consolidate the checking of /proc/<pid>/smaps_rollup support
in libmeminfo and do it in a thread safe way.

Use the API in ProcMemInfo as well to eliminate the extra
parameters passed to SmapsOrRollup* methods.

Bug: 111694435
Test: libmeminfo_test 1 --gtest_filter=TestProcMemInfo.IsSmapsSupportedTest
Test: Tested with and without the smaps_rollup support in kernel.

Change-Id: I992057f06b54569025fa0cdade9618da2675d1de
Merged-In: I992057f06b54569025fa0cdade9618da2675d1de
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-01-14 09:43:32 -08:00
Sandeep Patil
8871e7e90f meminfo: Add SmapsOrRollupPss
Adds SmapsOrRollup parsing methods to only read Pss of the
process fomr /proc/<pid>/{smaps, smaps_rollup}.

Bug: 111694435
Test: libmeminfo_test 1 --gtest_filter=TestProcMemInfo.*

Change-Id: I31b982ae5ff2bb5b165ea33f6c57755ee34cbbc7
Merged-In: I31b982ae5ff2bb5b165ea33f6c57755ee34cbbc7
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-01-14 09:43:12 -08:00
Sandeep Patil
56c414e872 meminfo: Remove unnecessary working set stats
The Vma and ProcMemInfo objects do not need separate stats
objects for storing working set. The Vma either has working set
or memory usage information and never both.

Bug: 111694435
Test: libmeminfo_test 1

Change-Id: I2df05f7e750bbba4325474633e705d6d68dd2ccb
Merged-In: I2df05f7e750bbba4325474633e705d6d68dd2ccb
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-01-14 09:42:50 -08:00
Sandeep Patil
002f02ea49 meminfo: Fix ProcMemInfo ForEachVmaFromFile
Caused by passing invalid parameters to getline(3) and the test
failure went unnoticed.

Bug: 111694435
Test: libmeminfo_test 1 --gtest_filter=TestProcMemInfo.ForEachVmaFromFileTest
Change-Id: Ideb39604c58f89237b05d2f7c8edb67c5ae65768
Merged-In: Ideb39604c58f89237b05d2f7c8edb67c5ae65768
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-01-14 09:42:17 -08:00
Sandeep Patil
82a48b160a meminfo: Add Smaps(), showmap and friends.
Needed by showmap and also android_s_Debug to classify each allocation
into multiple heaps.

The APIs added are:
ForEachVmaFromFile - Global API to parse a file expected to be in the
same format as /proc/<pid>/smaps and make a callback for each VMA found.
ProcMemInfo::ForEachVma - Same as 'ForEachVmaFromFile' but for a
ProcMemInfo object corresponding to a process(pid).
ProcMemInfo::Smaps - Wrapper to ProcMemInfo::ForEachVma, except the
function collects 'struct Vma' in a member vector and returns the
reference for the same.

Added showmap2 using the APIs and the corresponding tests the same time.

Bug: 111694435
Test: showmap_test.sh
Test: libmeminfo_test 1

Change-Id: I3065809cf94ecf3da88529809701035c47a8ce34
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-01-08 17:08:10 -08:00
Sandeep Patil
fa2d8d5541 libmeminfo: Add SmapsRollup
This adds the tests and SmapsRollup() parsing function in
ProcMemInfo. Adds tests to check the return value as well as
the correctness.

Bug: 111694435
Test: libmeminfo_test 1 --gtest_filter=TestProcMemInfo.*
Test: libmeminfo_benchmark --benchmark_filter=BM_SmapsRollup_
Result:
----------------------------------------------------------
Benchmark                   Time           CPU Iterations
----------------------------------------------------------
BM_SmapsRollup_old       4751 ns       4730 ns     149458
BM_SmapsRollup_new       4858 ns       4837 ns     144636
----------------------------------------------------------

Change-Id: Ia051fe53a7622e3091502ff7166efafae35e7935
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-01-07 09:43:37 -08:00
Sandeep Patil
c6497eb1dc libmeminfo: defer maps reading only when required for procmeminfo
This restores the original behavior. The main reason it should be this
way is to make the class generic for all things memory under
/proc/<pid>/. For example, with the current behavior, a program that
only needs to read /proc/<pid>/smaps_rollup will end up wasting time and
memory by parsing /proc/<pid>/maps when the object is being constructed.
Same goes for a program that only wants to reset the working set.

The 'ProcMemInfo' object still retains the property that it can only be
used once to read maps and the object must be destroyed + recreated to
update the stats.

Bug: 114325007
Bug: 111694435
Test: libmeminfo_test 1
Test:
 # adb push /google/data/ro/users/ss/sspatil/test-memutils.sh /data/local/tmp/
 # adb push procmem2 /data/local/tmp && adb push procrank2 /data/local/tmp
 # adb root && adb shell
 $ cd /data/local/tmp/
 $ chmod +x test-memutils.sh
 $ ./test-memutils.sh 2>&1 | tee test.log

Change-Id: I856d3b78a0088cff02cbd010b29ffbe0e35f5ee2
Signed-off-by: Sandeep Patil <sspatil@google.com>
2018-12-05 09:31:10 -08:00
Sandeep Patil
f129199350 libmeminfo: Add support to reset workingset without procmeminfo objects
Bug: 114325007
Bug: 111694435
Test: libmeminfo_test 1

Change-Id: I816809cda13983e47294a956347a27085397cbcf
Signed-off-by: Sandeep Patil <sspatil@google.com>
2018-12-05 09:13:20 -08:00
Sandeep Patil
549feab631 libmeminfo: Add support to fiter accounting based on page flags
Bug: 114325007
Bug: 111694435
Test: libmeminfo_test 1 --gtest_filter=ValidateProcMemInfoFlags.*

Change-Id: Ifa7006de78dd909b5b4db282a8c9931ebf97a68a
Signed-off-by: Sandeep Patil <sspatil@google.com>
2018-12-04 15:59:42 -08:00
Sandeep Patil
2259fdf7df libmeminfo: Add support for counting swap pages
Adds procmeminfo API to get the vector of swap_offsets
if SWAP is enabled on the device.

Bug: 114325007
Bug: 111694435
Test: libmeminfo_test 1
Change-Id: If0b52d042749a5bcb2c87aa2cb1595190d4769b1
Signed-off-by: Sandeep Patil <sspatil@google.com>
2018-12-04 14:02:28 -08:00
Sandeep Patil
54d8721374 libmeminfo: Add libmeminfo to gather global and per-process memory stats
The library is expected to be a unified place for all components to read
both global and per-process memory accounting form kernel including
getting the working set. This change adds the PageInfo, MemInfo and
ProcMemInfo classes and verifies the implementation against libpagemap
for correctness.

Adds a procmem2 tool show the usage.

TODO: Plumbing in os_debug, add vmastats, zoneinfo etc parsing.

Test: libmeminfo_test 1
Test: procmem2 1
Test: procmem2 -h -W 1
Test: procmem2 -h -w 1
Test: libmeminfo_benchmark
Bug: 111694435
Bug: 114325007

Change-Id: I280440b1dc26a498170686d10fcf63f953a0dcbd
Signed-off-by: Sandeep Patil <sspatil@google.com>
2018-11-05 10:42:46 -08:00