Commit Graph

444 Commits

Author SHA1 Message Date
Florian Mayer 00484817cc Merge commit '6499e5ec' 2018-04-16 11:21:27 +01:00
Suren Baghdasaryan 786e8537fa lmkd: Introduce support for legacy kill algorithm that uses minfree levels
Add ability to switch to the algorithm used by lowmemorykiller driver
for determining when to kill. It uses minfree levels to decide at which
levels of free memory and file cache to kill a process. oom_adj_score
is also determined by comparing current memory resources against minfree
levels.
ro.lmk.use_minfree_levels property is introduces for switching into this
mode. By default it is disabled.

Bug: 77299493
Bug: 75322373
Merged-In: I6b51972951026854a079fcda33d6786b7ed035e4
Change-Id: I6b51972951026854a079fcda33d6786b7ed035e4
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-04-15 16:02:36 +00:00
Suren Baghdasaryan 3bac7a1daf lmkd: Switch to using /proc/meminfo to have access to file cache size
Current mechanism of getting system memory state by using sysinfo()
is not enough because it does not provide information about file cache
size which is needed to correctly assess memory state. Switch to using
data from /proc/meminfo that includes information provided by sysinfo()
and file cache size in addition to that.


Bug: 77299493
Bug: 75322373
Merged-In: I16106fc4f9254f17f776803e60502b7b6474e1b7
Change-Id: I16106fc4f9254f17f776803e60502b7b6474e1b7
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-04-15 10:03:05 +00:00
Suren Baghdasaryan 65f04901ec lmkd: Introduce support for legacy kill algorithm that uses minfree levels
Add ability to switch to the algorithm used by lowmemorykiller driver
for determining when to kill. It uses minfree levels to decide at which
levels of free memory and file cache to kill a process. oom_adj_score
is also determined by comparing current memory resources against minfree
levels.
ro.lmk.use_minfree_levels property is introduces for switching into this
mode. By default it is disabled.

Bug: 77299493
Bug: 75322373
Change-Id: I6b51972951026854a079fcda33d6786b7ed035e4
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-04-15 02:29:57 -07:00
Suren Baghdasaryan 836c9168f0 lmkd: Switch to using /proc/meminfo to have access to file cache size
Current mechanism of getting system memory state by using sysinfo()
is not enough because it does not provide information about file cache
size which is needed to correctly assess memory state. Switch to using
data from /proc/meminfo that includes information provided by sysinfo()
and file cache size in addition to that.

Bug: 77299493
Bug: 75322373
Change-Id: I16106fc4f9254f17f776803e60502b7b6474e1b7
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-04-15 02:13:44 -07:00
Suren Baghdasaryan 7e0d65b65c lmkd: Add zoneinfo and meminfo parsing routines
/proc/zoneinfo and /proc/meminfo contain information necessary for lmkd
to assess system memory state. Add routines to parse these files.


Bug: 77299493
Bug: 75322373
Merged-In: Ie7d80bbb81fd0d2fc0629f6f678e6afc97fed1f6
Change-Id: Ie7d80bbb81fd0d2fc0629f6f678e6afc97fed1f6
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-04-15 07:55:27 +00:00
Suren Baghdasaryan 8796674f2e lmkd: Optimize frequent file reads by keeping file descriptors open
To check system memory state lmkd is using same files every time vmpressure
event is received. Instead of opening and closing these files every time
we store the file descriptor and use pread() to reread the file from
the beginning.


Bug: 77299493
Bug: 75322373
Merged-In: I8e27f8b9526e82e3cc313a02fce215c2e4dd3d29
Change-Id: I8e27f8b9526e82e3cc313a02fce215c2e4dd3d29
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-04-15 07:54:03 +00:00
Suren Baghdasaryan 207ed18611 lmkd: Add zoneinfo and meminfo parsing routines
/proc/zoneinfo and /proc/meminfo contain information necessary for lmkd
to assess system memory state. Add routines to parse these files.

Bug: 77299493
Bug: 75322373
Change-Id: Ie7d80bbb81fd0d2fc0629f6f678e6afc97fed1f6
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-04-14 23:50:14 -07:00
Suren Baghdasaryan 34c6cf2f40 lmkd: Optimize frequent file reads by keeping file descriptors open
To check system memory state lmkd is using same files every time vmpressure
event is received. Instead of opening and closing these files every time
we store the file descriptor and use pread() to reread the file from
the beginning.

Bug: 77299493
Bug: 75322373
Change-Id: I8e27f8b9526e82e3cc313a02fce215c2e4dd3d29
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-04-14 23:50:00 -07:00
Suren Baghdasaryan fc2123fdcf Merge changes I78d2dc79,I6e2eaebe am: bb266150fe am: 4d41a1f882
am: 6607770968

Change-Id: I22db50c6e56549582dd8c8dfcda9794d3989a17c
2018-04-14 17:21:53 -07:00
Suren Baghdasaryan f7e6fd02a1 Merge "lmkd: Add lmkd README file" am: b518418fbb am: 29aca8b0be
am: 94b5686aca

Change-Id: I41ed8e67023a24deb2049b05818d234253bd5ac3
2018-04-14 16:44:00 -07:00
Suren Baghdasaryan 47b64460c0 Merge changes I78d2dc79,I6e2eaebe am: bb266150fe
am: 4d41a1f882

Change-Id: If65529061b6bd49c06b0eae37dd9e196fa805ab7
2018-04-14 16:25:15 -07:00
Suren Baghdasaryan c989cb1e2f Merge "lmkd: Add lmkd README file" am: b518418fbb
am: 29aca8b0be

Change-Id: I0153fae612008cc2fe75a1ae8f29c8c4fe90d4b8
2018-04-14 16:03:45 -07:00
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