Commit graph

196 commits

Author SHA1 Message Date
Jim Blackler
34c3cb84a0 Add start time to LmkKillOccurred
This is to measure an application's behavior with respect to being LMKed
(the longer an app lives before being LMKed, the better).

Bug: 119854389
Test: Manual
Change-Id: I4ef6433391c8758626334731d2b5de038e4468ae
2018-11-28 09:26:38 +00:00
Suren Baghdasaryan
fc9e83fc79 Merge "lmkd: Cleanup unused code for killing processes in bulk" am: d04b38b0e5 am: 46d6d26c6c
am: 76cc42248e

Change-Id: Id1faa246044963fac4c5d1b7a016d8eebd830751
2018-10-29 13:51:31 -07:00
Suren Baghdasaryan
53695f3ca4 Merge "lmkd: retune rate at which processes are killed" am: d5eaeffcf3 am: 4d8a9caf30
am: ea13ea4669

Change-Id: I2a1cfb849d8600dcbb3a6b180f48078a710825b4
2018-10-29 13:50:39 -07:00
Suren Baghdasaryan
76cc42248e Merge "lmkd: Cleanup unused code for killing processes in bulk" am: d04b38b0e5
am: 46d6d26c6c

Change-Id: I7ce93b79b64d43eae08a4b316e4cbb655e3d4e06
2018-10-29 13:44:53 -07:00
Suren Baghdasaryan
ea13ea4669 Merge "lmkd: retune rate at which processes are killed" am: d5eaeffcf3
am: 4d8a9caf30

Change-Id: Iba588d2de887372874bacb1f0a6dc829c0c021c7
2018-10-29 13:44:01 -07:00
Suren Baghdasaryan
f81b5f44d8 lmkd: Cleanup unused code for killing processes in bulk
find_and_kill_processes() does not kill multiple processes at a time
anymore. Remove support for bulk process killing.

Change-Id: Id09132a9cebe44589a1a3ebcbff800a16fa56557
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-10-29 16:20:50 +00:00
Tim Murray
e7853f637c lmkd: retune rate at which processes are killed
Kill a single process at a time and try to wait up to 100ms for
that process to reclaim memory before triggering another kill.

Test: boots, works
bug: 116877958
Change-Id: I6775d0534b3e3728c04389d3eae1a00e3cbf9f27
2018-10-29 16:20:29 +00:00
Suren Baghdasaryan
73900920a2 Merge "lmkd: Add command to get number of kills" am: a1c684be4f am: e518e0a1b8
am: 50312e155b

Change-Id: Id63ec92116193c7a485dc6243fad8ac9c5e6679d
2018-10-24 20:33:11 -07:00
Suren Baghdasaryan
50312e155b Merge "lmkd: Add command to get number of kills" am: a1c684be4f
am: e518e0a1b8

Change-Id: Ibe242de81e5e7cf027763a67dafde70621a7e152
2018-10-24 19:52:18 -07:00
Suren Baghdasaryan
d4a29903c0 lmkd: Add command to get number of kills
Intrduce LMK_GETKILLCNT command for ActivityManager to get the number of
kills from lmkd.

Bug: 117126077
Test: used lmkd_unit_test to verify correct reporting
Change-Id: I09c720a7176b4df95efc544177cd2694f8d791be
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-10-24 17:18:32 +00:00
Srinivas Paladugu
6db669c598 Merge "lmkd: increase the soft limit for keyboard" am: 618be4c225
am: a213c8931c

Change-Id: Ie7abdb7dcd106b31ff3b59998cf4d3636ae25411
2018-10-16 13:38:12 -07:00
Srinivas Paladugu
3eb20bc954 lmkd: increase the soft limit for keyboard
lmkd sets the soft limit parameters for Go devices.
The limit for apps in the perceptible group is set to 16M.
However this limit is not sufficient for the keyboard app to
prevent pages from being re-claimed quickly. The mem usage of
the keyboard app is around 55M most cases with some occasional
spikes to 70-80M. Increasing the limit to 64M improves the warm
startup latency for keyboard. It is still lower than the limits
set for foreground and visible apps.

Test: Go device (1G)
Bug: 117517805
Merged-In: Id50e49327cfd76126e41ef6503971845f29196af
Change-Id: Id50e49327cfd76126e41ef6503971845f29196af
2018-10-16 18:58:01 +00:00
Suren Baghdasaryan
e3b6047e0d lmkd: Implement pid purge command to clear old pids when zygote restarts
lmkd keeps a list of pids registered by ActivityManager, however on rare
occasions when framework restarts and lmkd survives that list has to be
purged. Implement a command that can be used to clear the pid list.

Bug: 116801366
Test: locally by killing zygote process
Change-Id: I71d6012f86bb83a73edd5b687e05a0848e0569b1
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-10-15 16:22:17 +00:00
Suren Baghdasaryan
1e8187f25d lmkd: Implement pid purge command to clear old pids when zygote restarts am: c89be17730
am: e6fcbe0719

Change-Id: I560e7076a24f4122a7a0c73890234ba9d8c05389
2018-10-12 16:48:13 -07:00
Suren Baghdasaryan
e6fcbe0719 lmkd: Implement pid purge command to clear old pids when zygote restarts
am: c89be17730

Change-Id: I11ebb0c22eedeaebd1c8f55ad5bec17abb82ba82
2018-10-12 16:43:03 -07:00
Suren Baghdasaryan
c5ef70dc87 Merge "lmkd: Fix an invalid access to a pointer after it's freed" am: 1f149d8d2a am: 8950a02d10
am: 3503445f7f

Change-Id: Ia6fe0dcf6814e29be1faba15f1c0a5ae67a59a34
2018-10-12 14:52:33 -07:00
Suren Baghdasaryan
3503445f7f Merge "lmkd: Fix an invalid access to a pointer after it's freed" am: 1f149d8d2a
am: 8950a02d10

Change-Id: I87ec58231106933ef3cdcec50110c307bd2b3b83
2018-10-12 14:44:40 -07:00
Suren Baghdasaryan
0106327486 lmkd: Fix an invalid access to a pointer after it's freed
pid_remove() frees a structure representing registered process and the
pointer can't be used anymore. This change fixes an instance when pointer
was used after it was freed. pid_remove() is moved to the end of the
function and comments are added to prevent similar situation in the future.

Bug: 117625315

Change-Id: I6a922952a31232497b3f9caf87d5a21bd402db94
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-10-12 11:28:33 -07:00
Srinivas Paladugu
97cdd8776f lmkd: increase the soft limit for keyboard
lmkd sets the soft limit parameters for Go devices.
The limit for apps in the perceptible group is set to 16M.
However this limit is not sufficient for the keyboard app to
prevent pages from being re-claimed quickly. The mem usage of
the keyboard app is around 55M most cases with some occasional
spikes to 70-80M. Increasing the limit to 64M improves the warm
startup latency for keyboard. It is still lower than the limits
set for foreground and visible apps.

Test: Go device (1G)
Bug: 117517805
Change-Id: Id50e49327cfd76126e41ef6503971845f29196af
2018-10-11 13:53:40 -07:00
Rajeev Kumar
4dbc24d393 Read memory stats from /proc/pid/stat file.
(cherry pick from commit 0301683e49)
Bug: 117333340
Test: Manual testing using alloc-stress tool
Merged-In: Ie555933aafa6a6b7aa1dbf5518ebe804376e0afd
Change-Id: Ie555933aafa6a6b7aa1dbf5518ebe804376e0afd
2018-10-10 22:23:25 +00:00
Suren Baghdasaryan
c89be17730 lmkd: Implement pid purge command to clear old pids when zygote restarts
lmkd keeps a list of pids registered by ActivityManager, however on rare
occasions when framework restarts and lmkd survives that list has to be
purged. Implement a command that can be used to clear the pid list.

Bug: 116801366
Test: locally by killing zygote process
Change-Id: I71d6012f86bb83a73edd5b687e05a0848e0569b1
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-10-10 22:11:23 +00:00
Rajeev Kumar
0301683e49 Read memory stats from /proc/pid/stat file.
Bug: 117333340
Test: Manual testing using alloc-stress tool
Change-Id: Ie555933aafa6a6b7aa1dbf5518ebe804376e0afd
2018-10-10 12:42:12 -07:00
Suren Baghdasaryan
d6cbf3f41d lmkd: rate-limit and cleanup failed kill reports
Excessive number of failed kill reports when lmkd can't find an eligible
process to kill or frees not enough memory pollutes logs and bugreports.
Cleanup kill reports to remove duplicate information and rate limit failed
kill attempts at 1 report per sec. The number of suppressed failed kills
will be reported in the next lmkd report.

Bug: 113864581
Test: Verified using lmkd_unit_test
Change-Id: I67fa1fec97613f136c7582115edcbc56b1503c9c
Merged-In: I67fa1fec97613f136c7582115edcbc56b1503c9c
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-09-07 18:27:17 -07:00
Suren Baghdasaryan
457df5f602 Merge "lmkd: rate-limit and cleanup failed kill reports" am: 83193c6c78 am: b6d606d06a
am: 18d0260406

Change-Id: Ieb8d80612d9cb74afd6f1dc4207e560e07c8d848
2018-09-06 13:25:31 -07:00
Suren Baghdasaryan
b6d606d06a Merge "lmkd: rate-limit and cleanup failed kill reports"
am: 83193c6c78

Change-Id: I087c782727e8c83afe606e0c23b42aa2e048e11b
2018-09-06 12:33:33 -07:00
Suren Baghdasaryan
a11db3e4c5 Merge "lmkd: Introduce system property to get minfree and oom_adj levels" am: ca2d03ebdb am: 4ca5f5be67
am: 4121aea7ac

Change-Id: I31a515121b68b6f7f74a96aac9bf80c205cad989
2018-09-05 21:22:47 -07:00
Suren Baghdasaryan
3693441d9b lmkd: rate-limit and cleanup failed kill reports
Excessive number of failed kill reports when lmkd can't find an eligible
process to kill or frees not enough memory pollutes logs and bugreports.
Cleanup kill reports to remove duplicate information and rate limit failed
kill attempts at 1 report per sec. The number of suppressed failed kills
will be reported in the next lmkd report.

Bug: 113864581
Test: Verified using lmkd_unit_test
Change-Id: I67fa1fec97613f136c7582115edcbc56b1503c9c
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-09-06 01:59:49 +00:00
Suren Baghdasaryan
4ca5f5be67 Merge "lmkd: Introduce system property to get minfree and oom_adj levels"
am: ca2d03ebdb

Change-Id: I8cfbfb8ec49336820692d04af6efc8adae23820d
2018-09-05 17:08:24 -07:00
Suren Baghdasaryan
314a505710 lmkd: Introduce system property to get minfree and oom_adj levels
Introduce sys.lmk.minfree_levels system property to allow minfree level
reporting. The format for this property is:

<minfree 1>:<oom_adj 1>, <minfree 2>:<oom_adj 2>, ...

Max number of minfree levels is 6 and they are specified in the
increasing order. For example:

sys.lmk.minfree_levels=18432:0,23040:100,27648:200,32256:300,55296:900,80640:906

sys.lmk.minfree_levels updates are ratelimited to once per second in order
to prevent DoS attacks.

Bug: 111521182
Test: getprop sys.lmk.minfree_levels returns expected value
Change-Id: I80d75d6836650b12457d6a99ca88898535837a97
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-09-05 10:54:22 -07:00
Vic Yang
86008076f4 Merge "lmkd: Do not downgrade/ignore events when swap is full" am: c48943165d am: a79d8384f1
am: 92e2212af0

Change-Id: I9857648f0803ac7356fb6e4b1963f26998837655
2018-08-14 19:59:50 -07:00
Vic Yang
a79d8384f1 Merge "lmkd: Do not downgrade/ignore events when swap is full"
am: c48943165d

Change-Id: Id9497112443f9a11cbf2368dd10019359c4fc3ee
2018-08-14 16:10:18 -07:00
Treehugger Robot
c48943165d Merge "lmkd: Do not downgrade/ignore events when swap is full" 2018-08-14 21:31:56 +00:00
Suren Baghdasaryan
e8e944ee16 Merge "lmkd: Add meminfo logging after each kill for easy troubleshooting" am: 7bb1ae2d88 am: e645496ecd am: 4b7f5af6c2
am: bbbc0c5ede

Change-Id: I07c6a260fe2cd65d294bd92f560d0fe339ebb7d4
2018-08-10 19:48:32 -07:00
Suren Baghdasaryan
e645496ecd Merge "lmkd: Add meminfo logging after each kill for easy troubleshooting"
am: 7bb1ae2d88

Change-Id: Ie54654d0dd35b9549b017a7e2d10b80536e4a3af
2018-08-10 18:57:09 -07:00
Suren Baghdasaryan
282ad1a8f9 lmkd: Add meminfo logging after each kill for easy troubleshooting
While troubleshooting memory pressure related issues it's hard to get a
good view of the memory state when lmkd kill happens. Logging relevant
information from /proc/meminfo file that was used to make a kill decision
is very helpful for further analysis. To do this efficiently we are using
Android Logger event library functions and log the data used for kill
decision after the kill signal was issued.

Test: Run lmkd_unit_test and logcat -b events -v descriptive
Change-Id: Id5de41b9d91a04dd5d3eb9b85d4e1babe9755628
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-08-10 14:21:31 -07:00
Vic Yang
360a113e9b lmkd: Do not downgrade/ignore events when swap is full
When the swap space is full, a pressure event is unlikely to resolve by
itself.  In this case, do not downgrade or ignore the events.

Bug: 112056451
Test: Fill up swap on a 1GB device and check critical vmpressure events
      are not downgraded.
Change-Id: If154dc364711bf7c86f32e24ddcd10be359386de
2018-08-08 10:00:06 -07:00
Suren Baghdasaryan
1d1c002c3d lmkd: Skip memory.stat usage when per-app memcgs are not used
Initial change to remove memory.stat usage when per-application memcgs
are disabled was partially merged into AOSP under the following id:
Ib6dd7586d3ef1c64cb04d16e2d2b21fa9c8e6a3a
This change adds the missing parts.

Bug: 110384555
Change-Id: I1265021b1ede0e68efbf80d6430a959eaf46a69a
Merged-In: Ib6dd7586d3ef1c64cb04d16e2d2b21fa9c8e6a3a
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-08-08 01:18:38 +00:00
Greg Kaiser
f0da9b0cc2 lmkd: Protect against buffer overflow
We're passing a 'line' whose backing buffer is PAGE_MAX in size
into memory_stat_parse_line().  We protect overflowing the smaller
LINE_MAX 'key' buffer via some C preprocessing macros to assure
we limit the size.

Test: Local build with LMKD_LOG_STATS set for this file.
Bug: 76220622
Change-Id: I9e50d4270f7099e37a9bfc7fb9b9b95cc7adb086
2018-08-07 15:42:19 -07:00
Suren Baghdasaryan
9461708ec9 Merge "lmkd: Disable memory.stat usage when per-application memcgs are not used"
am: 615745cead

Change-Id: I57f3142ed217d4f1b3edb526087076fc588354d7
2018-08-03 09:14:09 -07:00
Suren Baghdasaryan
ce13cb52fe lmkd: Disable memory.stat usage when per-application memcgs are not used
Per-application memory.stat files are not available when per-application
memcgs are not used (per_app_memcg=false). Disable its usage based on
ro.config.per_app_memcg property.

minchan:
* correct indentation of memory_stat_parse
* move per_app_memcg check into memory_stat_parse inside
* change low_ram_device to per_app_memcg

Bug: 110384555
Test: manual test to see lkmd log message with memory hogger
Merged-In: Ib6dd7586d3ef1c64cb04d16e2d2b21fa9c8e6a3a
Change-Id: Ib6dd7586d3ef1c64cb04d16e2d2b21fa9c8e6a3a
Signed-off-by: Minchan Kim <minchan@google.com>
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-08-03 16:06:54 +00:00
Chih-Hung Hsieh
da9f65cd9b Merge "Declare __fake_use_va_args as a variadic function." am: e352a75b90 am: 7585d2270e am: bc7f7e7311
am: 044942e5b8

Change-Id: I72571e509dcda07ce4f2e36639523e23f5752146
2018-07-25 16:56:27 -07:00
Chih-Hung Hsieh
7585d2270e Merge "Declare __fake_use_va_args as a variadic function."
am: e352a75b90

Change-Id: I4cfeb23cab215741944485baa47450115ed671e0
2018-07-25 16:44:45 -07:00
Chih-Hung Hsieh
62b0ef556d Declare __fake_use_va_args as a variadic function.
* New clang compiler requires variadic function to have
  at least one named parameter type.
* Use ##__VA_ARGS__ to work with empty __VA_ARGS__.
* Fix one ALOG_ASSERT parameter bug in lmkd/lmkd.c.

Bug: 111614304
Test: make with WITH_TIDY=1
Change-Id: I90f35aa88527a6897954f69a35b256a157a725c5
2018-07-25 14:36:35 -07:00
Suren Baghdasaryan
aba4d2b725 lmkd: Disable memory.stat usage when per-application memcgs are not used
Per-application memory.stat files are not available when per-application
memcgs are not used (per_app_memcg=false). Disable its usage based on
ro.config.per_app_memcg property.

minchan:
* correct indentation of memory_stat_parse
* move per_app_memcg check into memory_stat_parse inside
* change low_ram_device to per_app_memcg

Bug: 110384555
Test: manual test to see lkmd log message with memory hogger
Change-Id: Ib6dd7586d3ef1c64cb04d16e2d2b21fa9c8e6a3a
Signed-off-by: Minchan Kim <minchan@google.com>
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-06-21 10:36:55 +09:00
Suren Baghdasaryan
fe26dfb3bf lmkd: Do not set soft_limit_in_bytes on high-end devices
Setting memory.soft_limit_in_bytes on high-end devices with large memory
reserves affects performance of memory-hungry applications that have
large workingsets and keep thrashing because of the memory limits imposed.
Limit the usage of memory.soft_limit_in_bytes to low-memory devices only.
Add debug messages for future troubleshooting to capture cases when
vmpressure events are being ignored.

Bug: 78916015
Test: collect vmstat while running a heavy app
Change-Id: Ib4434b96d2be802ef89960b573486eae8d12f198
Merged-In: Ib4434b96d2be802ef89960b573486eae8d12f198
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-05-22 10:25:38 -07:00
Suren Baghdasaryan
3862dd3685 resolve merge conflicts of 20686f061e to pi-dev-plus-aosp
BUG: None
Test: I solemnly swear I tested this conflict resolution.
Change-Id: I02b5973366351604bf46df7ad4e2235b1dda014a
2018-05-21 19:48:47 -07:00
Suren Baghdasaryan
20686f061e lmkd: Do not set soft_limit_in_bytes on high-end devices
Setting memory.soft_limit_in_bytes on high-end devices with large memory
reserves affects performance of memory-hungry applications that have
large workingsets and keep thrashing because of the memory limits imposed.
Limit the usage of memory.soft_limit_in_bytes to low-memory devices only.
Add debug messages for future troubleshooting to capture cases when
vmpressure events are being ignored.

Bug: 78916015
Test: collect vmstat while running a heavy app
Change-Id: Ib4434b96d2be802ef89960b573486eae8d12f198
Merged-In: Ib4434b96d2be802ef89960b573486eae8d12f198
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-05-21 23:17:46 +00:00
Suren Baghdasaryan
16830241df lmkd: Do not set soft_limit_in_bytes on high-end devices
Setting memory.soft_limit_in_bytes on high-end devices with large memory
reserves affects performance of memory-hungry applications that have
large workingsets and keep thrashing because of the memory limits imposed.
Limit the usage of memory.soft_limit_in_bytes to low-memory devices only.
Add debug messages for future troubleshooting to capture cases when
vmpressure events are being ignored.

Bug: 78916015
Test: collect vmstat while running a heavy app
Change-Id: Ib4434b96d2be802ef89960b573486eae8d12f198
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-05-21 14:42:15 -07:00
Yang Lu
b348314abd Merge "Only log the lmkd state change when the killing really happened." into pi-dev am: 7905b1e162
am: 45695becc5

Change-Id: I63f288d064b896ae16908035f41fed3346154daa
2018-05-16 09:17:19 -07:00
Yang Lu
45695becc5 Merge "Only log the lmkd state change when the killing really happened." into pi-dev
am: 7905b1e162

Change-Id: I2abda8ab40e766c882bdd8746bdf21bc222e7c50
2018-05-16 09:12:41 -07:00