Commit graph

150 commits

Author SHA1 Message Date
Suren Baghdasaryan
e82e15c242 lmkd: Detect the highest level of vmpressure when event is detected
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
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-01-17 17:05:42 -08:00
Suren Baghdasaryan
1bd2fc4fb6 lmkd: Close cgroup.event_control file when done writing
After events are specified by writing into cgroup.event_control file
the file should be closed.

Change-Id: Id015e6a7bac2b74bbc8d8793c85f529ee00bdf55
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-01-17 17:03:09 -08:00
Suren Baghdasaryan
b333f83481 lmkd: Remove stale dependency on libprocessgroup
Remove stale dependencies and header file inclusions

Change-Id: Ic0e7adb5bd2a0832937a831b6918e52ace4ad46a
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-01-17 17:02:27 -08:00
Suren Baghdasaryan
c71355991d lmkd: Add ability to trace lmkd kills
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
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-01-17 16:52:23 -08:00
Suren Baghdasaryan
662492ab1d lmkd: add logic to kill the heaviest of the eligible processes
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
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-01-16 15:42:33 -08:00
Suren Baghdasaryan
ad2fd9150b lmkd: change defaults to disable event upgrade/downgrade logic
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
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-01-16 15:42:25 -08:00
TreeHugger Robot
1b5f483604 Merge "lmkd: add ability to monitor all vmpressure events" 2018-01-05 00:10:40 +00:00
Suren Baghdasaryan
96bf3a600c lmkd: add ability to monitor all vmpressure events
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
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2018-01-04 10:28:13 -08:00
Daniel Colascione
4dd5d00ecc Pin lmkd for real
We pin lmkd in memory so that we don't take page faults (and thus
requisition memory) while we're in the process of responding to a
low-memory condition. mlockall(2) is the right primitive for this
pinning. Previously, we used the MCL_FUTURE flag to mlockall: used
this way, mlockall doesn't actually pin all pages in memory, since
MCL_FUTURE affects only the default flags for future mappings and
doesn't affect mapping already in existence at the time of the
mlockall call --- like the lmkd executable itself.

This patch adds the MCL_CURRENT flag, which also pins all pages
already mapped.

Test: code inspection
Change-Id: I4563959367a2f0a9cadc3ea41731b7f311326685
2018-01-03 12:32:14 -08:00
Elliott Hughes
d65c6ba955 Merge "Add lmkd/OWNERS." 2017-12-09 18:47:57 +00:00
Elliott Hughes
ad4e3e2f54 Add lmkd/OWNERS.
Bug: N/A
Test: N/A
Change-Id: Ic4970a95d799c16ffe06bc94a85adabc18d6cc0b
2017-12-08 16:12:58 -08:00
Robert Benea
19e26708c2 Simplify lmkd functionality
Get min adj score when needed, instead to propagate from caller funct.

Bug:65642829
Test: tested on gobo_512
Change-Id: I87f15c5c6206d471002828a24d0462b0abb0d196
2017-09-17 18:31:35 -07:00
Robert Benea
6e8e710675 Downgrade memory pressure events
If the system has enough memory the pressure events are ignored or
downgraded from critical to medium.

Bug: 65642829
Test: tested on gobo
Change-Id: I44e66d2e35508aceee5c1719313db217b80d582e
2017-09-14 13:47:40 -07:00
Robert Benea
164baebc01 Allow ANDROID_LOW_MEMORY_KILLER to coexist with lmkd
For Go devices fallback to memcg/memory pressure events for LMK.
Go devices will use memcg pressure events while inkernel module
is disabled.

Bug: 64852905
Test: tested on gobo
Change-Id: I267ab00be85e324331f6c91551ba013184de817e
2017-09-11 16:57:26 -07:00
Robert Benea
c47f2992b5 Detect critical preassure
When close to oom the system tend to become very thrashy
and keeps paging. This change looks at the current working sent and
checks it against swap.

Test: tested on gobo
Bug: 64721547

Change-Id: I93d42def93cbc03a01a54988fd5286ec9f124e36
2017-08-25 19:01:54 -07:00
Robert Benea
caeaa655c1 Improvements to lmkd
- Don't show misleading messages, add the correct description for
  the reason of process killing
- Don't kill Launcher3 upgrade the score to perceptible (200)
- Limit the verbose logging

Test: tested on gobo
Bug: 64316273
Change-Id: Ic7c13853d939afe4f20cdaa5b488b6e1810f5ddf
2017-08-11 16:13:57 -07:00
Robert Benea
58891d59b7 Make lmkd memory pressure levels configurable.
By doing so different platforms can customize them accordingly.
For instance a low mem, 512MB device can do
ro.lmk.medium=400, while a device with more memory can keep
the default(800).

Test: tested on gobo.
Bug: 64316084
Change-Id: Ifc4f3853bc06f30488adb25883ccd9aaf683ba9b
2017-08-02 23:42:48 +00:00
Robert Benea
673e27677a Make lmkd use medium/critical mem pressure, and update soft limit based on adj score.
Test: GO device (512MB/1GB), both show improvements under heavy load.

Bug: 62626918

Change-Id: I98afc8b1171db5b57056bc05d1f1ae9c5eed8506
2017-06-14 13:28:44 -07:00
Steven Moreland
1457c9290d lmkd: Android.mk -> Android.bp
Test: links
Change-Id: I19aa62270488af02d64830ca90faf80b35423009
2017-04-28 15:20:18 -07:00
Mark Salyzyn
30f991f251 liblog: use log/log.h when utilizing ALOG macros
Test: compile
Bug: 30465923
Change-Id: Id6d76510819ebd88c3f5003d00d73a0dbe85e943
2017-01-11 09:31:15 -08:00
Mark Salyzyn
cfd5b080af system/core: preparation to pull back interfaces from android/log.h
Point to log/log.h where necessary, define LOG_TAG where necessary.
Accept that private/android_logger.h is suitable replacement for
log/logger.h and android/log.h.

Correct liblog/README

Effectively a cleanup and controlled select revert of
'system/core: drop or replace log/logger.h' and
'system/core: Replace log/log.h with android/log.h'.

Test: compile
Bug: 30465923
Change-Id: Ic2ad157bad6f5efe2c6af293a73bb753300b17a2
2016-10-20 08:11:39 -07:00
Mark Salyzyn
ff2dcd9af9 system/core Replace log/log.h with android/log.h
Should use android/log.h instead of log/log.h as a good example
to all others.  Adjust header order to comply with Android Coding
standards.

Test: Compile
Bug: 26552300
Bug: 31289077
Change-Id: I33a8fb4e754d2dc4754d335660c450e0a67190fc
2016-09-30 12:47:05 -07:00
Colin Cross
e8ffa449fd Move android_get_control_socket out of line
android_get_control_socket has a warning from the implicit cast from
long to int.  The warning was being hidden because cutils/sockets.h was
included with -isystem.  Move android_get_control_socket to sockets.cpp,
since we don't want header only dependencies anyways, and fix the
warning with a range check and a static_cast.

Bug: 31492149
Test: m -j <module that uses sockets.h and -Wall>
Change-Id: I1f394ab26d4ec8a7dd0e7907c10416d7f8647624
2016-09-23 11:26:08 -07:00
Elliott Hughes
8615d79d85 Merge "Most accept/accept4 calls in system/core don't actually want the remote address."
am: 299d64144b

Change-Id: I3fb9678dfed08f0b1d6e90e547ecae6cdcabc9a1
2016-08-23 23:03:20 +00:00
Elliott Hughes
3dcfa3fb1c Most accept/accept4 calls in system/core don't actually want the remote address.
So don't write the extra code for it or waste the kernel's time
copying it around.

Change-Id: I93de64064c2d4fe58ba5b5322cfa69bf31a76dad
2016-08-23 12:50:00 -07:00
Chih-Hung Hsieh
daa13eaa92 resolve merge conflicts of 3252d11 to nyc-dev-plus-aosp
Change-Id: I2973439a194a3048d009159d75572a5366021f21
2016-05-19 16:02:22 -07:00
Chih-Hung Hsieh
2b82e918d8 Fix misc-macro-parentheses warnings in lmkd.
Bug: 28705665
Change-Id: I43388c0f9fdc8c2a0c0f4495f96bbc27e3de8a1d
2016-05-18 15:37:20 -07:00
Martijn Coenen
9010a2398e lmkd: subscribe to low mempressure events.
This will make sure we get invoked in time,
and combined with a kernel change to increase
the window size (and thus rate-limit the
notifications) based on the amount of memory
on the device, this should provide a nice
balance between receiving too many notifications
vs getting notified too late.

Change-Id: I2f5e92390b94e582aaa06d88763a232e39673496
2016-02-09 11:25:18 +01:00
Nick Kralevich
261952e570 Merge "more O_CLOEXEC" am: 920d637d25
am: 890cd99709

* commit '890cd997098795b7a58c1d56c49c23895da7b4f9':
  more O_CLOEXEC
2015-12-18 23:05:34 -08:00
Nick Kralevich
c68c8862f9 more O_CLOEXEC
Change-Id: I330aef8d6f1fc35d6649995ef312954b84dff555
2015-12-18 20:57:25 -08:00
Erik Kline
79a3210eda Merge "Switch from using sockaddr to sockaddr_storage." am: 46b0b1c694 am: 4c1b3840f0
am: cbc6f68e32

* commit 'cbc6f68e320bd30d0cd7fbe73847deacbd54e073':
  Switch from using sockaddr to sockaddr_storage.
2015-12-08 04:54:05 +00:00
Erik Kline
7e16cc15b5 Switch from using sockaddr to sockaddr_storage.
This is to ensure sufficient space is always available.

Change-Id: Ifa87b93ecdc90dcacbfb24446c872344da6703d3
2015-12-07 16:07:46 +09:00
Nick Kralevich
bdf20142b9 Merge "Enable hidepid=2 on /proc" am: 2d8f1d4c47 am: ea8452cc72
am: 7dafe5b818

* commit '7dafe5b818f7771cb00c4a0ea3ab1dbf74593185':
  Enable hidepid=2 on /proc
2015-11-09 20:41:19 +00:00
Nick Kralevich
c39ba5ae32 Enable hidepid=2 on /proc
Add the following mount options to the /proc filesystem:

  hidepid=2,gid=3009

This change blocks /proc access unless you're in group 3009
(aka AID_READPROC).

Please see
  https://github.com/torvalds/linux/blob/master/Documentation/filesystems/proc.txt
for documentation on the hidepid option.

hidepid=2 is preferred over hidepid=1 since it leaks less information
and doesn't generate SELinux ptrace denials when trying to access
/proc without being in the proper group.

Add AID_READPROC to processes which need to access /proc entries for
other UIDs.

Bug: 23310674
Change-Id: I22bb55ff7b80ff722945e224845215196f09dafa
2015-11-09 09:08:46 -08:00
Chong Zhang
0a4acdfca0 lmkd: allow client to use oom score in [-1000, 1000]
bug: 21411311

Change-Id: I20ddd1b30881712d03b5f85f270e1b56661fdfd1
2015-10-19 09:37:32 -07:00
Tom Cherry
984bd8323d resolved conflicts for 5caca3dd to mnc-dr-dev-plus-aosp
Change-Id: I773e514a8232b77cdd566dc36c9efc4e15f206f0
2015-09-21 14:25:34 -07:00
Tom Cherry
20391b1de5 bundle init.rc contents with its service
Bug: 23186545
Change-Id: I52616b8ab1165fdef716f9b8f958665f2308c12e
2015-08-21 10:14:43 -07:00
Andreas Gampe
c165b01a8b Lmkd: Fix unused variables
For build-system CFLAGS clean-up, fix unused variables.

Change-Id: I841192e92585814b8691d544cc48433b2ca1b3d3
2014-11-24 20:32:42 -08:00
Colin Cross
f8857cc24a lmkd: kill a process if zoneinfo can't be read
Opening /proc/zoneinfo may return -ENOMEM under memory pressure,
assume something needs to be killed if that happens.

Bug: 16236289
Change-Id: I25aab09f4c3f2b9e176eaaeca94fd6bd790dad4e
2014-07-14 17:41:17 -07:00
Colin Cross
16b0946da1 lmkd: kill multiple tasks
The task selected to die may be small, add its approximate size
to other_free and other_file and keep killing until all thresholds
are met.

Bug: 16236289
Change-Id: Iceeca4c63fec98cae2bf53e258f7707cea408b07
2014-07-14 17:41:17 -07:00
Colin Cross
ce85d955a3 lmkd: use open instead of fopen
fopen and fgets require allocations, switch to open/read with
stack allocated buffers.

Bug: 16236289
Change-Id: I10586883fe78caf59d309eff7f7989b3e45beb7d
2014-07-14 17:41:17 -07:00
Colin Cross
1a0d9be53e lmkd: make lmkd SCHED_FIFO
If kswapd runs more than lmkd it may throw away all page cache pages
before lmkd gets a chance to kill a process.  Make lmkd SCHED_FIFO
so it can react quickly to kernel low memory notifications.

Bug: 16236289
Change-Id: I46767b4ec81ef8638d0c9e47d168a68b62e3cac5
2014-07-14 17:41:17 -07:00
Colin Cross
b28ff91313 lmkd: mlock all memory
Use mlockall(MCL_FUTURE) to lock all lmkd pages in memory.  This
avoids lmkd thrashing when the system is low on memory.

As a side effect, it will also keep the .text sections of liblog, libm,
libc, and libprocessgroup in memory at all times.

Bug: 16236289
Change-Id: Idd70557efa4b1e14bc86f14220672a30f6c956e3
2014-07-14 16:39:56 -07:00
Colin Cross
9d9e62cf37 lmkd: remove libcutils from LOCAL_SHARED_LIBRARIES
While lmkd does technically use libcutils' socket.h, it only
uses a static inline.  Remove libcutils from LOCAL_SHARED_LIBRARIES
so it doesn't end up mlock'd in memory in the next patch.

Bug: 16236289
Change-Id: I744d69bfff06cb904836f64e1d5f6e530604bff4
2014-07-14 16:39:56 -07:00
Colin Cross
fef9522d9b lmkd: use libprocessgroup to kill forked processes
After sending sigkill to the main process, also call into
libprocessgroup to kill any processes that were forked.

Bug: 15313911
Change-Id: I05577c6f5b70800ce0a01f480c8870c2c601afda
2014-07-09 17:24:39 -07:00
Colin Cross
fbb78c6fee lmkd: pass uid from ActivityManager to lmkd
lmkd will use the uid to find processgroups and kill forked processes.

Bug: 15313911
Change-Id: I3f7bb003ccf15650cae6ebc2c042ddeb4cc796fc
2014-07-09 11:30:52 -07:00
Nick Kralevich
7d7f5e58db Make lmkd dynamically linked
Statically linked binaries cannot take advantage of ASLR,
making them less secure.

In addition, statically linked binaries consume more ram,
because shared libraries cannot be reused.

  executable size before: 87728
  executable size after:  13656

Change-Id: I9d02d865f9beeaaaadcd5009f64ac015931d4b11
2014-05-07 23:59:11 +00:00
Mark Salyzyn
e6ed68bdf3 lmkd: turn on -Werror
- Deal with some -Wunused issues

Change-Id: Id037c44a0ca2d00ae10a939fb001bc24a3e9410c
2014-05-07 12:27:29 -07:00
Todd Poynor
16b6099476 low memory killer: switch to kernel oom_score_adj interface
Use oom_score_adj for setting OOM score adjustment values instead
of the older, deprecated oom_adj interface.

Change-Id: I5ba7801d4b8971be092b31ae0fd8af8c3001d613
2013-09-23 18:32:02 +00:00
Todd Poynor
3948f80f2a Add lmkd low memory killer daemon
Move kernel low memory killer logic to new daemon lmkd.  ActivityManager
communicates with this daemon over a named socket.

Change-Id: Ie957da7e9b1f7150e23c689fdadf23ff260b47be
2013-08-30 15:32:09 -07:00