Commit Graph

981 Commits

Author SHA1 Message Date
Suren Baghdasaryan 36b2c497e3 lmkd: Fix usage of ro.lmk.kill_heaviest_task property
lmkd should use ro.lmk.kill_heaviest_task property to select between
algorithms for victim selection. Set ro.lmk.kill_heaviest_task default
value to false in order to keep it compatible with previous versions
of lmkd (killing the heaviest task is a new mechanism).

Change-Id: I78d2dc79d9c54e636c26665605518d9c87b535b3
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-04-13 23:24:24 +00:00
Suren Baghdasaryan d1d59f871f lmkd: Rename is_go_device variable to better reflect its function
Rename is_go_device variable to low_ram_device to better reflect
its meaning and relation to ro.config.low_ram variable.

Change-Id: I6e2eaebe79cf2e6edf861f7c602e52a5b573ad0a
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-04-13 23:24:09 +00:00
Suren Baghdasaryan 14b4465450 lmkd: Add lmkd README file
Add README file providing lmkd overview and description for its
properties.

Change-Id: I30236dd4ccaa2b48c31dfb80b63f0b82b49b5744
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-04-13 21:36:44 +00:00
Mark Salyzyn 5cb238b41d resolve merge conflicts of f062a2cd9eef32ac9458faee7d056c06f2f4168b to pi-dev-plus-aosp
am: be5235619f

Change-Id: I5ac401c518af4240bb56d867fd10771b3ea1d0a2
2018-04-06 08:20:25 -07:00
Mark Salyzyn 9e918598df resolve merge conflicts of f062a2cd9eef32ac9458faee7d056c06f2f4168b to pi-dev-plus-aosp
Test: I solemnly swear I tested this conflict resolution.
Change-Id: I5eb1bc16bf25b27172b6d2ea355768df2f6d8ff7
2018-04-06 07:56:54 -07:00
Mark Salyzyn b9bd86aeaf Merge "lmkd: test: access /sys/module/lowmemorykiller/ as u:r:shell:s0" am: b69cb7071d am: 4f7d8851a5
am: aa0b84afca

Change-Id: I2b9848ada0bdff52179bebdda05b2695e8293994
2018-04-05 20:02:40 -07:00
Mark Salyzyn ef4b4be3a5 Merge "lmkd: test: access /sys/module/lowmemorykiller/ as u:r:shell:s0" am: b69cb7071d
am: 4f7d8851a5

Change-Id: I1ef7aab68bfb5a11891ef4777f6dc46774120a21
2018-04-05 19:45:16 -07:00
Mark Salyzyn 5cc80b3d98 lmkd: only mlockall() if enabled
Move process initialization, mlockall() and sched_setscheduler() to
only occur if initialization succeeds and is enabled.  This
conserves mlock'd memory and a FIFO processing slot if (deprecated)
kernel lowmemorykiller is active.

Cleanup: Android coding standard compliance.

Test: lmkd_unit_test
Bug: 33808187
Bug: 72838192
Change-Id: I51af0235c8eca4ef958ef2d83a8071ff58b49d78
2018-04-03 14:41:26 +00:00
Mark Salyzyn 930f877944 lmkd: test: access /sys/module/lowmemorykiller/ as u:r:shell:s0
lmkd_unit_test gets an selinux violation when run unprivileged:

lmkd_unit_test: type=1400 audit(0.0:???): avc: denied { search } for
    name="lowmemorykiller" dev="sysfs" ino=??? scontext=u:r:shell:s0
    tcontext=u:object_r:sysfs_lowmemorykiller:s0 tclass=dir
    permissive=0

resulting in log noise.  Check for INKERNEL_MINFREE_PATH existence
after known to be escalated as root user to suppress noise.

Test: lmkd_unit_test as unprivileged user, there should be no audits.
Change-Id: Ia5c7824e7070c98ee6eea20ca53097e4e56d61b6
2018-04-03 14:41:11 +00:00
android-build-team Robot ba824be447 Snap for 4683893 from 136f765fb32bbc8dc8b22645a6fbbf83475d1ec6 to pi-release
Change-Id: Ibe1b07efe8d032d44d2c828bae218c56d4e8078a
2018-03-28 07:25:18 +00:00
Greg Kaiser ef07ddcdd4 [automerger skipped] Merge "lmkd: Protect against buffer overflow" into pi-dev am: 136f765fb3 -s ours
am: f97f242c30  -s ours

Change-Id: I94f783d2f87f7590ee845c70ca27e437f0449cc3
2018-03-28 04:31:01 +00:00
Greg Kaiser 248b2c5611 [automerger skipped] Merge "lmkd: Protect against buffer overflow" into pi-dev
am: 136f765fb3  -s ours

Change-Id: I5f8cf0f5dad1e93cbe51d0fbfad785d6b8bc831d
2018-03-28 03:19:15 +00:00
TreeHugger Robot e5135b856a Merge "lmkd: Protect against buffer overflow" 2018-03-27 23:47:14 +00:00
Greg Kaiser cfca0a30fb 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
Merged-In: I9e50d4270f7099e37a9bfc7fb9b9b95cc7adb086
Change-Id: I9e50d4270f7099e37a9bfc7fb9b9b95cc7adb086
2018-03-27 21:59:31 +00:00
android-build-team Robot d49c7d1ad1 Snap for 4680594 from ca47ae35135d1b77ee89641f972eb60ab7522b5a to pi-release
Change-Id: Ia0ebf1e82b207d979c2300e7ca589d0928531199
2018-03-27 07:27:32 +00:00
Rajeev Kumar 09c53b2c3b [automerger skipped]Merge "Use usel_mkd_stats_log build variable while compiling lmkd with stats logging feature." into pi-dev am: 42c17c8ee5
am: f09c593dd5  -s ours

Change-Id: I99ccf9e683612752670c68173199df0faa98a37b
2018-03-26 23:46:01 +00:00
Rajeev Kumar 9b3719d5f0 Merge "Use usel_mkd_stats_log build variable while compiling lmkd with stats logging feature." into pi-dev
am: 42c17c8ee5

Change-Id: I4d5b2851bb465dfaf0c8c7b863611685aedaf03d
2018-03-26 23:34:24 +00:00
TreeHugger Robot 88bfbef576 Merge "Use usel_mkd_stats_log build variable while compiling lmkd with stats logging feature." into pi-dev 2018-03-26 23:14:23 +00:00
Rajeev Kumar 3c69f0a64d Fix compilation issue when LMKD_LOG_STATS is defined. am: 1c669f764d
am: 716fe89b88

Change-Id: I17664c7b1c66b3f14fd8d1291016c106c3505946
2018-03-26 21:51:59 +00:00
Rajeev Kumar 860ff464e2 Fix compilation issue when LMKD_LOG_STATS is defined.
am: 1c669f764d

Change-Id: I750b6a13b1a897b3dc77e1823a997afe0c40e4a3
2018-03-26 21:46:22 +00:00
Rajeev Kumar 02499a92f0 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
(cherry picked from commit fb25ddd9c9004de9a9ebb1175a6ceaf7aeec0673)
2018-03-26 18:15:25 +00:00
Greg Kaiser 1d721caddc 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-03-23 14:30:37 -07:00
Rajeev Kumar 9dd1497b95 Use usel_mkd_stats_log build variable while compiling lmkd with stats logging feature.
Bug: 74443701
Test: Tested manually
Merged-In: Ifa13cc7d1c3ff3ac71a16cf55be5a48ce808ef59
Change-Id: Ifa13cc7d1c3ff3ac71a16cf55be5a48ce808ef59
(cherry picked from commit 083be30783870ce4093d1d5f040f42f9f3c27510)
2018-03-23 20:33:57 +00:00
Rajeev Kumar 6afff4243c Use usel_mkd_stats_log build variable while compiling lmkd with stats logging feature.
Bug: 74443701
Test: Tested manually
Change-Id: Ifa13cc7d1c3ff3ac71a16cf55be5a48ce808ef59
2018-03-22 10:55:36 -07:00
Suren Baghdasaryan a11e49518b Merge "lmkd: Fix the message printed during a kill to avoid confusion" am: 5ea2c4baf1 am: ccb9744562
am: 0bff4732d4

Change-Id: I1c9de7850267c443b91c690baa32973ce56fc50c
2018-03-21 22:25:02 +00:00
Suren Baghdasaryan ec59ef25d3 Merge "lmkd: Suppress error when accessing soft_limit_in_bytes for system_server" am: d4463fd9d7 am: ec2bc88aa1
am: b939f0d45e

Change-Id: Idcf02ae42388bf2188a9782dcb1c36475e821699
2018-03-21 22:16:11 +00:00
Suren Baghdasaryan 9433ba123b Merge "lmkd: Change error to warning when accessing oom_score_adj file" am: a77411f425 am: 3d3e875767
am: d33812455d

Change-Id: I38e27bae540e947706b31b1eb98c51b51e1a2708
2018-03-21 21:44:23 +00:00
Suren Baghdasaryan 0fa401c7b6 Merge "lmkd: Fix the message printed during a kill to avoid confusion" am: 5ea2c4baf1
am: ccb9744562

Change-Id: I45960a335ad426fdd69a2a36268ddfc425f92de0
2018-03-21 19:35:53 +00:00
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