[Moto G 2015 Original Android Development] IronTechmonkey:
Low Memory Killer

So there is this kernel function called Low Memory Killer (LMK) which is a mechanism by which apps are killed based on categories, and changing certain LMK parameters seems to improve performance on my XT1540. Here are the notes from the jira ticket https://jira.lineageos.org/browse/BUGBASH-480

I initially noticed this when playing with squid2's kernel and Kernel Adiutor in April 20 build, but all testing and logging is directly from a clean flash of LOS Osprey April 27, OpenGapps Pico April 27, LOS SU, with the only installed apps being; Titanium Backup, Matlog, and Kernel Adiutor (but no KA settings changes made unless specified).

The default Low Memory Killer (LMK) values (see *1 in LMK Settings Comparison below) are much higher than other possible scenarios, and performance is noticeably better when they are lowered. Are they too high for this 1GB device?

They are much higher even than the most aggressive profile offered by Kernel Adiutor on Osprey (*2 in LMK Settings Comparison below).

The Kernel Adiutor "medium" profile on Osprey (*3), and the default LOS 14.1 settings on Peregrine XT1045 1GB (*4), and the Kernel Adiutor medium profile on Peregrine (*5) all have much lower values and are in the same range as each other... and they all seem to yield a much better experience in re apps being killed (at least in my usage case).

I was not sure what to log but: the attached logs (in jira ticket) seem to show more app killing when using the Osprey default LMK settings (*1) than when using Kernel Adiutor “Medium” profile (*3). Each test was after a reboot and letting media scans complete. The logs span: Opening camera, taking a picture, switching to panorama mode and taking a panoramic picture, scrolling to gallery to view pics.

Attached log OspreyLMKdefault2017-04-27-13-31-00.txt, default Osprey LMK settings (*1), contains 54 instances of “killing”.

Attached log OspreyLMKmedium2017-04-27-13-44-26.txt, Kernel Adiutor’s “Medium” profile (*3), contains 32 instance of “killing”

--------------------

With apps installed the effects are much more noticeable (and I'm still testing and logging).

Using default Osprey LMK settings (*1): Merely opening the camera causes some apps/services to be killed some in ways disruptive to their use (status bar icon missing or app did not restart), and there is sometimes a very laggy response returning to home screen app switching. Other apps or combinations of apps may also induce this. Taking a panorama as described in the clean test above induces this almost every time.

Using Kernel Adiutor’s “Medium” profile (*3): The instances of intrusive app killing have been rare. Even taking a panorama picture rarely causes my apps to be killed. Aforementioned lags are also less common, and performance when switching apps and or returning to home screen seems better. I've done the same panorama camera test as above several times without killing those same apps. This is a big difference in user experience.

The separate "Adaptive Low Memory Killer" setting does not seem to have much of an impact. If it did, that impact seems negligible compared to the difference in perceived performance between the default and the medium LMK settings.

Even though the "medium" setting (*3) that I'm testing might not be the best for all cases, on 1GB devices lowering them at least somewhat from where they are might yield better performance if it is not detrimental to something else.

------------------

LMK Settings Comparison:

*1 Osprey , default settings:

Foreground Applications, 72

Visible Applications, 90

Secondary Server, 108

Hidden Applications, 126

Content Providers, 144

Empty Applications, 180

*2 Osprey; Kernel Adiutor "Very Aggressive” profile:

Foreground Applications, 26

Visible Applications, 35

Secondary Server, 44

Hidden Applications, 98

Content Providers, 134

Empty Applications, 143

*3 Osprey; Kernel Adiutor "Medium” profile:

Foreground Applications	26

Visible Applications, 35

Secondary Server, 44

Hidden Applications, 53

Content Providers, 62

Empty Applications, 80

*4 Peregrine; default settings:

Foreground Applications, 32

Visible Applications, 40

Secondary Server, 48

Hidden Applications, 56

Content Providers, 64

Empty Applications, 80

*5 Peregrine; Kernel Adiutor "Medium” profile:

Foreground Applications, 26

Visible Applications, 34

Secondary Server, 43

Hidden Applications, 52

Content Providers, 60

Empty Applications, 78