Commit graph

140 commits

Author SHA1 Message Date
Treehugger Robot
c48943165d Merge "lmkd: Do not downgrade/ignore events when swap is full" 2018-08-14 21:31:56 +00: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
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
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
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
Yang Lu
5564f4ee08 Only log the lmkd state change when the killing really happened.
BUG: b/78603347

Test: statsd test

Change-Id: I0345a47e1cd1c79a67103e401a2eb0a7fbe0631b
2018-05-15 16:54:45 +00:00
Dan Willemsen
971f23bf66 Revert "Only log the lmkd state change when the killing really happened."
am: 0051684905

Change-Id: I3fc6842348d7ede95dd5fcdca06271d90c4facb4
2018-05-14 20:31:29 -07:00
Dan Willemsen
0051684905 Revert "Only log the lmkd state change when the killing really happened."
This reverts commit 5e60f88cab.

Reason for revert: broke some builds

Bug: 78603347
Change-Id: I46bf6face35f5399d7d43146b360c0703eedfb1a
2018-05-15 03:26:05 +00:00
Yangster-mac
6d709b77c6 Only log the lmkd state change when the killing really happened.
am: 5e60f88cab

Change-Id: I95e347eeb0d69493a15ed11d32ca91d532eb043e
2018-05-14 19:22:33 -07:00
Yangster-mac
5e60f88cab Only log the lmkd state change when the killing really happened.
Test: statsd test
BUG: b/78603347
Change-Id: Ie08b0c3260f2f96b48e9e12c2c88208a3613042d
2018-05-14 22:25:29 +00:00
Suren Baghdasaryan
740d940074 lmkd: Enable more logs during a kill
am: da88b24c97

Change-Id: Ieb4ed09ac5224843ee8f7fb44494eb291054223d
2018-05-11 14:15:09 -07:00
Suren Baghdasaryan
da88b24c97 lmkd: Enable more logs during a kill
Logs that provide information about memory conditions during a process
kill event contain useful information and do not affect device
performance because these events are rare. Enabling them even when
ro.config.debug flag is not set will help in understanding low memory
conditions.

Bug: 79572814

Change-Id: Iae6e9bb612b9a7904ca491de3f1ddc727f24c7e0
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-05-11 21:03:14 +00:00
Yao Chen
89c1ea6deb Fix the stats log in lmkd
am: 389aee1117

Change-Id: I533b09089280681a9c41a3597c62ec621a870839
2018-05-04 13:40:47 -07:00
Yao Chen
389aee1117 Fix the stats log in lmkd
1. let logs be written to statsd directly like all other stats logs.
   + stats log should not write to logd anymore(b/78239479)
2. fixed the log format
   + need to embed the elapsed real time in the log
3. fixed the log context reuse problem
   +reset the log context buffer and internal state before reuse

Bug: 78603347
Bug: 78239479

Test: tested with alloc_stress, and saw logs written to statsd

performance measurement (memory & cpu):
https://paste.googleplex.com/5508158646648832

Change-Id: I345f0eace8ba1687ff480fb88e9abba1d8533f76
2018-05-03 16:04:27 -07:00
Mark Salyzyn
7977e3d24d Merge "lmkd: limit capability set to minimum" am: 01ce44b734
am: c2d4d08be2

Change-Id: Ic97ab3c4312d260c2aa8c7a30e203564cd72f61a
2018-04-17 15:34:06 -07:00
Suren Baghdasaryan
df6f9e30ed lmkd: Introduce support for legacy kill algorithm that uses minfree levels
am: ffdc4ddb25

Change-Id: Ic18a67fe5cbdf541f1b6c439e2b7f0488d4d1dcf
2018-04-16 20:45:49 -07:00
Suren Baghdasaryan
81999c34b4 lmkd: Switch to using /proc/meminfo to have access to file cache size
am: 9926e57ee8

Change-Id: Ie3f2773b2dc970ddea5b67632921eedfe87afd4d
2018-04-16 20:44:46 -07:00
Suren Baghdasaryan
a15a9c423d lmkd: Add zoneinfo and meminfo parsing routines
am: 8b9deaf618

Change-Id: I1132199473d335197cbc9677431d3e2937e123c6
2018-04-16 20:44:28 -07:00
Suren Baghdasaryan
ffdc4ddb25 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
Merged-In: I6b51972951026854a079fcda33d6786b7ed035e4
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
(cherry picked from commit d273b6630d)
2018-04-17 01:42:06 +00:00
Suren Baghdasaryan
9926e57ee8 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
Merged-In: I16106fc4f9254f17f776803e60502b7b6474e1b7
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
(cherry picked from commit 9ac54eb2f8)
2018-04-17 01:41:59 +00:00
Suren Baghdasaryan
8b9deaf618 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
Merged-In: Ie7d80bbb81fd0d2fc0629f6f678e6afc97fed1f6
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
(cherry picked from commit da0bc05b22)
2018-04-17 01:41:38 +00:00
Mark Salyzyn
64d97d8761 lmkd: limit capability set to minimum
Set F() capability set and 'drop' lmkd from AID_ROOT to AID_LMKD uid
and from AID_ROOT to AID_LMKD and AID_SYSTEM gid.

/dev/memcg/memory.pressure defaults to root.root mode 0000, set it up
as root.system mode 0040 to allow lmkd read access.

Instrument failure to set SCHED_FIFO.

Annotate access points that require elevated capabilities.

Test: check /proc/`pidof lmkd`/status for capability set
Test: lmkd_unit_test
Bug: 77650566
Change-Id: I986081a0434cf6e842b63a55726380205b30a3ea
2018-04-16 14:51:56 -07:00
Suren Baghdasaryan
b2d59ee367 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
Merged-In: I8e27f8b9526e82e3cc313a02fce215c2e4dd3d29
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
(cherry picked from commit d716fe3610)
2018-04-16 09:33:44 -07:00
Suren Baghdasaryan
9ff66ff0b3 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).

Bug: 77299493
Bug: 75322373
Change-Id: I78d2dc79d9c54e636c26665605518d9c87b535b3
Merged-In: I78d2dc79d9c54e636c26665605518d9c87b535b3
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
(cherry picked from commit 818b59b229)
2018-04-16 09:30:29 -07:00
Suren Baghdasaryan
39a22e751b 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.

Bug: 77299493
Bug: 75322373
Change-Id: I6e2eaebe79cf2e6edf861f7c602e52a5b573ad0a
Merged-In: I6e2eaebe79cf2e6edf861f7c602e52a5b573ad0a
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
(cherry picked from commit fe2be6cc44073b7ef09ca849004e5072bdf18857)
2018-04-16 09:27:32 -07:00
Suren Baghdasaryan
9dbd937b4c lmkd: Add lmkd README file
Add README file providing lmkd overview and description for its
properties.

Bug: 77299493
Bug: 75322373
Change-Id: I30236dd4ccaa2b48c31dfb80b63f0b82b49b5744
Merged-In: I30236dd4ccaa2b48c31dfb80b63f0b82b49b5744
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
(cherry picked from commit 7e5dea82a5)
2018-04-16 09:26:40 -07:00
Florian Mayer
7725a9d9aa Merge commit '6499e5ec' into pi-dev-plus-aosp 2018-04-16 14:55:03 +01:00
Suren Baghdasaryan
c09b53db7b 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
45c9e0b30c 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
ceffb41162 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
6499e5ec4a 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
6607770968 Merge changes I78d2dc79,I6e2eaebe am: bb266150fe
am: 4d41a1f882

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

Change-Id: I0153fae612008cc2fe75a1ae8f29c8c4fe90d4b8
2018-04-14 16:03:45 -07:00
Suren Baghdasaryan
818b59b229 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
ff61afb002 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
7e5dea82a5 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
be5235619f resolve merge conflicts of f062a2cd9e 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
aa0b84afca 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
721d7c7fa3 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
ce32539cf3 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
Greg Kaiser
d6d847142b 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
Rajeev Kumar
f09c593dd5 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