Commit Graph

1653 Commits

Author SHA1 Message Date
Suren Baghdasaryan 618e3f621c Merge "lmkd: Suppress error when accessing soft_limit_in_bytes for system_server" am: d4463fd9d7
am: ec2bc88aa1

Change-Id: I10f524189c88dded9cce608cd2bec18cf03497f4
2018-03-21 19:35:22 +00:00
Suren Baghdasaryan 9c5eaeb68f Merge "lmkd: Change error to warning when accessing oom_score_adj file" am: a77411f425
am: 3d3e875767

Change-Id: I59e03c59b9ee8a6a8e4dd8bf7ea4a26eb9bc4ecc
2018-03-21 19:34:51 +00:00
Suren Baghdasaryan 1588bfbc2a lmkd: Fix the message printed during a kill to avoid confusion
Current kills message prints min_score_adj marked as "oom_adj" which
is confusing. This change marks it as "min_oom_adj" to be more clear.

Change-Id: If52f0fb25fe3208c928c5d6adce77c04b9f15a0e
2018-03-21 17:12:42 +00:00
Suren Baghdasaryan bb7747bec2 lmkd: Suppress error when accessing soft_limit_in_bytes for system_server
system_server needs to register with lmkd, however it has no memory
cgroup under /dev/memcg/apps. This change detects if the process being
registered is system_server and suppresses the error message when
/dev/memcg/apps/uid_%d/pid_%d/memory.soft_limit_in_bytes file can't
be accessed.

Bug: 73483785
Test: verified logcat output
Change-Id: I03df7831f41f512ac8d3ebc46330546d08a3cbc6
2018-03-21 10:11:23 -07:00
Suren Baghdasaryan f584fff7aa lmkd: Change error to warning when accessing oom_score_adj file
Occasionally processes are killed or crash while lmkd is trying to access
their oom_score_adj file. This is not necessarily an erroneous condition
and therefore should not be reported as an error. Demoting error to a
warning with a detailed message.

Bug: 72039129
Test: verified logcat output
Change-Id: I97444ba5198c02cb7f7ba03c3af12e4aad9d233e
2018-03-20 17:14:38 -07:00
Suren Baghdasaryan 49d2f34411 Merge changes Ida58d13d,Ia9441cc5,Id840983d,I73611593 am: 0d1d773d54 am: 3a5f6f2422 -s ours
am: 2e9cb51fe2

Change-Id: I416f8786e94a59560255e9665d18921587f155d2
2018-03-14 21:48:02 +00:00
Suren Baghdasaryan b050fc62f9 Merge changes Ida58d13d,Ia9441cc5,Id840983d,I73611593 am: 0d1d773d54
am: 3a5f6f2422  -s ours

Change-Id: I76f0fa446cf53476b4778d88285eb6db13ae0e25
2018-03-14 21:12:22 +00:00
Suren Baghdasaryan 58dfc89613 lmkd: Fix lmkd-test to work with relative paths
This change allows lmkd-test to work correctly when it's started
using absolute as well as relative path.

Change-Id: Ida58d13d66a224119a363f59cc59289f0167d3c9
2018-03-13 12:34:18 -07:00
Rajeev Kumar 6694491b9f Fix compilation issue when LMKD_LOG_STATS is defined.
Note: The breakage was caused by http://ag/3621623

Test: mmma system/core/lmkd/
Change-Id: I17033aeedb3183d4777dacb89ec84430ff061b3c
Bug: 74443701
2018-03-09 15:58:42 -08:00
Suren Baghdasaryan 40b694d5df lmkd: Implement lmkd-test
(cherry pick from commit 5f5b30e58ba8964f78231ebf96e4ec80e7a31ecd)

lmkd-test executes alloc-stress native application and monitors kernel
logs for OOM kills.

Bug: 63631020

Change-Id: Ia9441cc5f8e283131f0bc839cb808a911bcdb168
Merged-In: Ia9441cc5f8e283131f0bc839cb808a911bcdb168
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-03-09 11:19:24 -08:00
Suren Baghdasaryan a743800b47 lmkd: Introduce liblmkd_utils for communicating with lmkd process
(cherry pick from commit 0f1005180513e880bf7c90a3f2c2bf1a36aa1406)

A number of tools and tests require communication with lmkd.
In order to avoid code duplication liblmkd_utils implements
functions commonly used when interacting with lmkd process.
Isolate communication protocol details into lmkd.h

Bug: 63631020

Change-Id: Id840983d55b7db60013d52dee0c3187943811822
Merged-In: Id840983d55b7db60013d52dee0c3187943811822
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-03-09 11:18:53 -08:00
Suren Baghdasaryan c53a16b4c6 lmkd: Add support for multiple lmkd client connections
(cherry pick from commit 3cfb2c8b1018babf0007d8eb6263e25360409a33)

lmkd testing requires communication with lmkd daemon to register new
native processes. New implementation allows more than one communication
channel to lmkd. Current max number of communication channels is set to
two - one for ActivityManager and another one for a test process.

Bug: 63631020

Change-Id: I736115938a3c5ad9253bce29a17cd5349af190eb
Merged-In: I736115938a3c5ad9253bce29a17cd5349af190eb
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-03-09 11:18:44 -08:00
android-build-team Robot 40a124e050 Snap for 4632767 from 8aaf581b4de8d3dcadb449df5b8b4b6d1e5ae1c9 to pi-release
Change-Id: I940b81bada31593cd431a04695adb20e741e3bf4
2018-03-04 08:21:08 +00:00
Suren Baghdasaryan 294b1dd97f Merge changes I394a7920,Ia847118c,Ic8396eee,I79a85c33,Id015e6a7, ... am: 1d5b102671 am: 27bae4cf7c
am: 2cdfb3f23a  -s ours

Change-Id: I5d41303f07c25c06cf89d78b181f7c6d97902756
2018-03-03 00:50:09 +00:00
Suren Baghdasaryan 4d27393414 lmkd: Select in-kernel vs userspace lmk based on kernel driver presence
(cherry pick from commit 979591b627601f457955bcf1f6b5f6de6493777b)

Currently selection criteria for in-kernel vs userspace lmk is kernel
driver presence and device not being a Go device. This change removes
Go device check leaving kernel driver presence to be the only selection
criteria.

Bug: 71502948

Change-Id: I394a7920433a8d090e207ea86296356413a63fe7
Merged-In: I394a7920433a8d090e207ea86296356413a63fe7
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-03-02 01:16:05 +00:00
Suren Baghdasaryan de9e693171 lmkd: Implement kill timeout
(cherry pick from commit caa2dc56fd52d8d773aa8b902fc605b453111976)

New ro.lmk.kill_timeout_ms property defines timeout in ms after a
successful kill cycle for more kills to be considered. This is
necessary because memory pressure after a kill does not go down
instantly and system needs time to reflect new memory state. This
timeout prevents extra kills in the period immediately after a
kill cycle. By default it is set to 0 which disables this feature.

Bug: 63631020
Test: alloc-stress

Change-Id: Ia847118c8c4a659a7fc38cd5cd0042acb514ae28
Merged-In: Ia847118c8c4a659a7fc38cd5cd0042acb514ae28
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-03-02 01:15:01 +00:00
Suren Baghdasaryan 3bcbb99183 lmkd: Allow killing multiple processes to downgrade memory pressure
(cherry pick from commit 65f54a2665c5d8ebddcb18108ea54ed36df13609)

Record free memory at low vmpressure levels and whenever pressure
increases beyond low free up enough memory to downgrade memory pressure
to low. This is done by freeing enough memory to get to the max free
memory levels seen during low vmpressure.
The kill logic for Go devices is not changed as these devices are designed
to operate under high memory pressure.

Bug: 63631020
Test: alloc-stress

Change-Id: Ic8396eee08013b1c709072a13525601d5c8bf1f1
Merged-In: Ic8396eee08013b1c709072a13525601d5c8bf1f1
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-03-02 01:14:13 +00:00
Suren Baghdasaryan f70073f52e lmkd: Detect the highest level of vmpressure when event is detected
(cherry pick from commit e82e15c242d32272fe3493b0d358329e6e3d9fa7)

lmkd checks for vmpressure events using epoll_wait() with eventfds of
all registered events. It's possible that multiple events of different
priorities happen before epoll_wait() returns. For these cases we
use conservative approach by assuming that the system is under the
highest registered vmpressure levels. This speeds up lmkd response time
to high memory pressure by not responding to possibly stale low pressure
levels when vmpressure rises quickly.

Bug: 63631020
Test: alloc-stress

Change-Id: I79a85c3342e7e1b3a3be82945266b2cc60b437cf
Merged-In: I79a85c3342e7e1b3a3be82945266b2cc60b437cf
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-03-02 01:13:16 +00:00
Suren Baghdasaryan bb1087eb18 lmkd: Close cgroup.event_control file when done writing
(cherry pick from commit 1bd2fc4fb6310da4303c3a76a259ab7e67bf39b8)

After events are specified by writing into cgroup.event_control file
the file should be closed.

Change-Id: Id015e6a7bac2b74bbc8d8793c85f529ee00bdf55
Merged-In: Id015e6a7bac2b74bbc8d8793c85f529ee00bdf55
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-03-02 01:12:29 +00:00
Suren Baghdasaryan 0fa737d068 lmkd: Remove stale dependency on libprocessgroup
(cherry pick from commit b333f83481d3de7a29a7aa8d27456af89581c12b)

Remove stale dependencies and header file inclusions

Change-Id: Ic0e7adb5bd2a0832937a831b6918e52ace4ad46a
Merged-In: Ic0e7adb5bd2a0832937a831b6918e52ace4ad46a
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-03-02 01:11:34 +00:00
Suren Baghdasaryan a052dcd6a6 lmkd: Add ability to trace lmkd kills
(cherry pick from commit c71355991d4bafb4694f6252ac10e288a5fb9f75)

For tracing lmkd kills inside kernel it is useful to have traces
indicating when and which process lmkd is killing. By default the
tracing is disabled.

Bug: 63631020
Test: alloc-stress

Change-Id: I3ceb2bde0c292eec55855cb4535927f3b4c5d08b
Merged-In: I3ceb2bde0c292eec55855cb4535927f3b4c5d08b
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-03-02 01:10:42 +00:00
Suren Baghdasaryan 742897f28c lmkd: add logic to kill the heaviest of the eligible processes
(cherry pick from commit 662492ab1d21f138483a8f3943483924e8779d29)

Killing the most memory-demanding process from the set of eligible
processes yields better results on high-performance devices than
killing the first one we could find. This is in line with how in-kernel
lowmemorykiller driver chooses its victims.

Bug: 63631020
Test: alloc-stress

Change-Id: Ie1ef7f33f3e79698a9b4120c14490386d6129f9b
Merged-In: Ie1ef7f33f3e79698a9b4120c14490386d6129f9b
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-03-02 01:09:12 +00:00
Suren Baghdasaryan 2148af42b3 lmkd: change defaults to disable event upgrade/downgrade logic
(cherry pick from commit ad2fd9150bdbb9abdbc26c6a395f007b4cca7567)

vmpressure upgrade/downgrade logic based on swap utilization works well
for low memory devices because of a small swap size, however for high
performance devices this measure is not a good indication of the memory
pressure because of large swap resources. This change sets the default
levels to disable upgrade/downgrade logic by default and each device
can set these properties appropriately.

Bug: 63631020
Test: alloc-stress

Change-Id: Ifd4fbd4d6bb3e82f0f87b029df94934f1e7b1c9c
Merged-In: Ifd4fbd4d6bb3e82f0f87b029df94934f1e7b1c9c
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-03-02 01:07:42 +00:00
Suren Baghdasaryan f8eb9adf9b lmkd: add ability to monitor all vmpressure events
(cherry pick from commit 96bf3a600c5f2678665a7c028dacbbf3fcc8f7c7)

Ability to monitor all available vmpressure event levels is needed
to accommodate systems with different memory resources. Low memory
systems can rely on medium and critical level events because working
under memory pressure is usual mode of operation. High performance
systems with more memory need to react earlier using also low
vmpressure level events to free memory early and prevent low memory
condition affecting its performance.

Bug: 63631020
Test: alloc-stress

Change-Id: I0cef1bd4c97d32c005045ae47f0ce3464ed98899
Merged-In: I0cef1bd4c97d32c005045ae47f0ce3464ed98899
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-03-01 21:40:13 +00:00
android-build-team Robot 2966074bdc Snap for 4628106 from 29717e60b49221554999f868432c7d977495e9a1 to pi-release
Change-Id: I3f43633596befdfeda8dd35edfc03c1367ea2bc7
2018-03-01 08:27:04 +00:00
Mark Salyzyn 0b08d5067c lmkd: move sundry pieces to statslog.h
Pragma once is not part of the standard, and is actually a gnu
C++ addition. Android coding standard requires the #ifndef header
wrappers. Moved things that belong in statslog.h from the lmkd files.

SideEffects: None
Test: lmkd_unit_tests
Bug: 33808187
Bug: 72838192
Change-Id: I9686b1a0791ee2b723d05b91905eda0bb64a1156
2018-02-28 19:36:12 +00:00
android-build-team Robot 40e5de6dda Snap for 4620899 from 472010f5f61be5f09439b62f30f006150dd9c9b7 to pi-release
Change-Id: Ic6eda700476a1d35a7a2a3e0f5050b7abbfd69f6
2018-02-25 08:25:22 +00:00
Rajeev Kumar 10a75706de Fix variable name in log statement and initialize memory_stat before using it.
Bug: 72177881
Test: Tested manually
Change-Id: Icbf948dd0e40eaa6c660d55f5cd72182436da086
2018-02-22 10:57:18 -08:00
android-build-team Robot 98be30f03a Snap for 4613997 from c02c42fca8b227edf3306690e779673615bc49b1 to pi-release
Change-Id: Ie6ba1b4edb3f2cb0ead5cbc86b77528822d14e5c
2018-02-21 08:21:46 +00:00
Daniel Colascione 56b95d787f Enable lmkd kill tracing everywhere
Test: asdf
Exempt-From-Owner-Approval: vacation
Change-Id: If6af7df74d303466aac4a69cdfe558e9748f72b9
2018-02-12 12:09:04 -08:00
android-build-team Robot e30b013acd Snap for 4598635 from 93c1ca6224da0bf04df2c424332de87ccf8a1455 to pi-release
Change-Id: I37e06a09af7ccd6ff87a6311731c3261c8f2a30c
2018-02-11 08:20:59 +00:00
Rajeev Kumar 4aba915a62 Implement stats logging in LMKD.
It implements logging of following atoms:
  -- LMK_STATE_CHANGED
  -- LMK_KILL_OCCURRED

We would like to gather memory metrics of the process killed by LMKD
because by gathering this info we would be able to analyze and improve
system health by potentially reducing memory footprint of the process.

This feature would be available on production builds.

To know more about this see: http://go/android-p-memory-metrics

Bug: 65738734
Test: Tested manually
Change-Id: I064e0cdcb47c3b4c95d8b8d5654050c9812008d8
2018-02-09 13:07:40 -08:00
android-build-team Robot 65322dffab Snap for 4590521 from aa41172e81d291b2d5190682d8d71f9a1bb019bc to pi-release
Change-Id: I82f8b6976e682f7bab5fce5a77f4d60c19b7a59b
2018-02-07 13:33:43 +00:00
Mark Salyzyn f004c15c0a Merge "lmkd: use after free" am: 7c3c8c27e1 am: c95fb64f0f
am: 9e11bb0cdb

Change-Id: I2ee21f9d995b588a2a08eeaf9366dcfce4354e63
2018-02-07 03:51:59 +00:00
Mark Salyzyn 1d5fdf356d lmkd: use after free
Remove a use-after free reference of procp->pid, using the already
captured pid variable.

Test: lmkd_unit_tests
Bug: 33808187
Change-Id: I3f5f8dd9acab2e28c81465d6195b73ae47e0a3c4
2018-02-05 11:00:59 -08:00
android-build-team Robot 372013f2b7 Snap for 4585119 from bd1f9850bd362406eb3c22f6234daa6a5fec1d9b to pi-release
Change-Id: I8e6dd14edde7abc83b8d3a8f68a81c833c415f51
2018-02-05 08:23:44 +00:00
android-build-team Robot fca9fe7c0f Snap for 4579913 from e9153c72825933fd4e7f2113fb141295a46634ea to pi-release
Change-Id: I5bec263c1b535bebd559c3cb9f52a83708194814
2018-02-01 08:55:29 +00:00
Rajeev Kumar 653d616754 Cleanup zoneinfo parsing function.
Usage of this function was removed in http://ag/2402070

Bug: 62626918
Test: Manual
Change-Id: Ib6af945d1005062d4219deae078a415bb7369261
2018-01-31 18:13:46 -08:00
Suren Baghdasaryan 3f82af9977 lmkd: Implement lmkd-test
lmkd-test executes alloc-stress native application and monitors kernel
logs for OOM kills.

Bug: 63631020

Change-Id: Ia9441cc5f8e283131f0bc839cb808a911bcdb168
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-01-31 18:11:38 +00:00
Suren Baghdasaryan f7932e5b30 lmkd: Introduce liblmkd_utils for communicating with lmkd process
A number of tools and tests require communication with lmkd.
In order to avoid code duplication liblmkd_utils implements
functions commonly used when interacting with lmkd process.
Isolate communication protocol details into lmkd.h

Bug: 63631020

Change-Id: Id840983d55b7db60013d52dee0c3187943811822
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-01-31 18:10:49 +00:00
Suren Baghdasaryan ef8e701f40 lmkd: Add support for multiple lmkd client connections
lmkd testing requires communication with lmkd daemon to register new
native processes. New implementation allows more than one communication
channel to lmkd. Current max number of communication channels is set to
two - one for ActivityManager and another one for a test process.

Bug: 63631020

Change-Id: I736115938a3c5ad9253bce29a17cd5349af190eb
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-01-31 04:45:01 +00:00
android-build-team Robot d3a296112b Snap for 4574286 from b17ce35c0442c3b404e6cc49f17733779212e78d to pi-release
Change-Id: I7003dde6cd915292807540de161aeec36b0a57c1
2018-01-30 08:21:14 +00:00
Rajeev Kumar 962fee4761 Functions to log stats log from LMKD.
Bug: 72177881
Test: Manual
Change-Id: I0f618013e242fabae785b62eb39f9bfbcaac16da
2018-01-29 15:18:04 -08:00
android-build-team Robot 6016d24455 Snap for 4565898 from 207a211804a60cb46d7ee9785c5055968e609188 to pi-release
Change-Id: Id6472866aa17835af1d73e04ce4c448f4f475e00
2018-01-25 09:06:24 +00:00
Daniel Colascione dba30fb82c Merge "Add MCL_ONFAULT to mlockall" am: ccb9960beb am: 179c81f733
am: 1592d9b458

Change-Id: I55420b49d0902dc00b5741294c05a1320bf13325
2018-01-24 08:31:28 +00:00
Daniel Colascione abe25b1fca Add MCL_ONFAULT to mlockall
This way, we don't fault in the entirety of our DSOs immediately;
instead, used pages are "sticky" in memory. Works only on kernel 4.4
and up: downlevel, we ignore the mlockall failure.

Once we get statically-linked lmkd in better shape, we'll just switch
to that.

Change-Id: I07a75ee3bc1264a1db41635c2acf611fede99b91
2018-01-24 01:53:52 +00:00
gitbuildkicker 42bdbfe7b0 merge in pi-release history after reset to master 2018-01-22 22:28:38 -08:00
gitbuildkicker 213b45c7aa merge in pi-release history after reset to master 2018-01-22 16:32:14 -08:00
Suren Baghdasaryan e6613ea04e lmkd: Select in-kernel vs userspace lmk based on kernel driver presence
Currently selection criteria for in-kernel vs userspace lmk is kernel
driver presence and device not being a Go device. This change removes
Go device check leaving kernel driver presence to be the only selection
criteria.

Bug: 71502948

Change-Id: I394a7920433a8d090e207ea86296356413a63fe7
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-01-20 03:50:41 +00:00
Suren Baghdasaryan 30854e70d9 lmkd: Implement kill timeout
New ro.lmk.kill_timeout_ms property defines timeout in ms after a
successful kill cycle for more kills to be considered. This is
necessary because memory pressure after a kill does not go down
instantly and system needs time to reflect new memory state. This
timeout prevents extra kills in the period immediately after a
kill cycle. By default it is set to 0 which disables this feature.

Bug: 63631020
Test: alloc-stress

Change-Id: Ia847118c8c4a659a7fc38cd5cd0042acb514ae28
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-01-20 03:49:35 +00:00