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
Remove a use-after free reference of procp->pid, using the already
captured pid variable.
Test: lmkd_unit_tests
Bug: 33808187
Change-Id: I3f5f8dd9acab2e28c81465d6195b73ae47e0a3c4
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>
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>
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
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>
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>
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
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
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>
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>
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>
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>
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>
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>
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
Get min adj score when needed, instead to propagate from caller funct.
Bug:65642829
Test: tested on gobo_512
Change-Id: I87f15c5c6206d471002828a24d0462b0abb0d196
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
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
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
- 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
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
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
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
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
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
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