I’m reading code about in kernel lowmemorykiller, lets know about some concepts related.

  • vmpressure: monitor Linux virtual memory management pressure
  • kernel page reclaim: background reclaim/indrect reclaim/kswapd and direct reclaim
  • kswapd: when free pages low at water page_low, it’s wakeup
  • direct relaim: when alloc memory and no free memory, the thread will reclaim direcly, need avoid because of delay
  • page thrashing: from net:too many page fault is called thrashing. CPU spend most of the time in page fault related activity than the useful work, it will degrade the system performance…, page fault need swaping in/out, too many swaping in/out is called page thrashing, u can vmstat 1 and look at swap device usage… The result is an unresponsive system and a very busy hard disk.when lmk is not killing, still has page thrashing, page thrashing will casue system performance degrade, so killing is better choice than thrashing.
  • swappiness: ctl the kernel aggressiveness in swapping-out pages, 0-100, 100 means swap out pages as many pages as possible
  • page fault: A major page fault is one that can only be satisfied by accessing the disk. A minor page fault can be satisfied by sharing pages that are already in memory.

About lmk, i think the confused parameter is minfree, how to set it? we know AMS will calculate the value by resolution and so on, but as i know qcom does not use it, it use his own tuned.

AMS code path:

framework/base/services/core/java/com/android/server/am/ProcessList.java:updateOomLevels

Lets see the history adjusted by google/qcom:

Author: Dianne Hackborn <hackbod@google.com>
Date: Thu Oct 2 17:21:27 2014 -0700

Maybe fix issue #17449495: Nakasi is pretty laggy/slow to do anything

Tweak the oom tuning to raise everything by 50%. This is the same
increase we did for Volantis; I am thinking that most of the issue
there was not it being 64 bit, but it being tighter on RAM. From
my testing, it looks like in user switching there was some paging
going on with Nakasi, and with this change things seem to be better.

We should probably revisit this for future work on RAM. It seems
likely that a 64 bit device will need more RAM, so probably the value
I am picking here is larger than we actually need for other devices.
I think this is the safest change at this point though -- it leaves
Volantis the same, where we already had tweaked it to address paging
issues, raises it on Nakasi (to the same value as Volantis) where we
seem to have paging issues, and on our other devices also raises it
but those are generally not under memory pressure so this shouldn't
really make a difference.


// mOomMinFreeLow
- 8M, 12M, 16M, 24M, 28M, 32M
+ 12M, 18M, 24M, 36M, 42M, 48M

// mOomMinFreeHigh
- 48M, 60M, 72M, 84M, 96M, 120M
+ 72M, 90M, 108M, 126M, 144M, 180M

using existing for 32bit

Author: Uday Kiran jandhyala <ukiran@codeaurora.org>
Date: Fri Nov 21 16:07:26 2014 +0530

ProcessList: Adjusting OOM Min Free values for L

Existing boundary (both low and high) values for
OOM min free, are fine tuned to suit lowmemorykiller
behavior on L builds

+ MinFreeLow32Bit
+ 8M, 12M, 16M, 24M, 28M, 32M

+ MinFreeHigh32Bit
+ 48M, 60M, 72M, 84M, 96M 120M

more aggressive for 32bit

Author: Trishool Narayanasetty <tnarayan@codeaurora.org>
Date: Thu Mar 19 20:56:10 2015 +0530

frameworks/base: Make minfree values aggressive for 32bit devices

This change makes lowmemorykiller minfree values aggresive for 32bit
devices. So that processes get killed earlier and system can reclaim
memory earlier without hitting direct reclaim/background reclaim path
frequently.

+ MinFreeLow32Bit
+ 12M, 18M, 24M, 36M, 42M, 48M

+ MinFreeHigh32Bit
+ 72M, 90M, 108, 126, 172.x 221.x

tune optimal 32bit

Author: Trishool Narayanasetty <tnarayan@codeaurora.org>
Date: Mon Apr 13 15:58:13 2015 +0530

frameworks/base: Make minfree values optimal for 32bit devices

This change makes lowmemorykiller minfree values optimal for 32bit
devices. Arrived at these values after evaluating UX and launch
latencies.

MinFreeHigh32Bit
- 72M, 90M, 108, 126, 172.x 221.x
+ 60M, 75M, 90M, 105M, 134.x 170.x

for 7.0 google no 32bits

Tweak the tuning of low RAM devices to consider 480x800 as
the base line resolution. That is our target these days.

- int minSize = 320*480; // 153600
+ int minSize = 480*800; // 38400

ok, i think you got the rabbit.

And lets see below description about minfree:

Now, these minfree values are not typical on most devices these days as manufacturers love to tweak these to their liking depending on how they feel it best suits their device.
But what you should take away from this brief explanation is that the more free memory you have, the less likely you’ll see critical processes being killed off.
The main difference between a device with 2GB of RAM versus a device with 3GB of RAM is that the device with 3GB of RAM should be able to cache more processes in the background without triggering the LMK driver to kill it off.

at last lets see some call stack about lmk on QCOM_N:

[  373.858334] CPU: 2 PID: 5687 Comm: CAM_startstats Tainted: G        W      3.18.31-perf-g5e6acc4-00672-g606f204-dirty #31
[ 373.858363] [<c010cd84>] (unwind_backtrace) from [<c01099f4>] (show_stack+0x10/0x14)
[ 373.858376] [<c01099f4>] (show_stack) from [<c0baf53c>] (dump_stack+0x78/0x98)
[ 373.858389] [<c0baf53c>] (dump_stack) from [<c082a824>] (lowmem_scan+0x408/0x7e0)
[ 373.858401] [<c082a824>] (lowmem_scan) from [<c01e0ba4>] (shrink_slab_node+0x204/0x3d0)
[ 373.858410] [<c01e0ba4>] (shrink_slab_node) from [<c01e12b8>] (shrink_slab+0x70/0xe4)
[ 373.858418] [<c01e12b8>] (shrink_slab) from [<c01e3ba8>] (try_to_free_pages+0x3c0/0x74c)
[ 373.858428] [<c01e3ba8>] (try_to_free_pages) from [<c01d9188>] (__alloc_pages_nodemask+0x578/0x92c)
[ 373.858440] [<c01d9188>] (__alloc_pages_nodemask) from [<c01f8f78>] (handle_mm_fault+0x29c/0x904)
[ 373.858451] [<c01f8f78>] (handle_mm_fault) from [<c0114590>] (do_page_fault+0x118/0x378)
[ 373.858460] [<c0114590>] (do_page_fault) from [<c010030c>] (do_DataAbort+0x34/0x164)
[ 373.858468] [<c010030c>] (do_DataAbort) from [<c010a6fc>] (__dabt_usr+0x3c/0x40)
[ 373.858474] Exception stack(0xec275fb0 to 0xec275ff8)
[ 373.858481] 5fa0: 48227212 9eb00e00 a5d2287d 48227212
[ 373.858489] 5fc0: 9eadc370 9e27f000 a2afce40 00000000 a5d79864 9eb00e00 a2afa780 a2ad8d80
[ 373.858497] 5fe0: a5d79b74 9eadc328 a5d5ed77 a5d2289e a0010030 ffffffff


374.035992] CPU: 2 PID: 120 Comm: kswapd0 Tainted: G W 3.18.31-perf-g5e6acc4-00672-g606f204-dirty #31
[ 374.036018] [<c010cd84>] (unwind_backtrace) from [<c01099f4>] (show_stack+0x10/0x14)
[ 374.036031] [<c01099f4>] (show_stack) from [<c0baf53c>] (dump_stack+0x78/0x98)
[ 374.036044] [<c0baf53c>] (dump_stack) from [<c082a824>] (lowmem_scan+0x408/0x7e0)
[ 374.036056] [<c082a824>] (lowmem_scan) from [<c01e0ba4>] (shrink_slab_node+0x204/0x3d0)
[ 374.036066] [<c01e0ba4>] (shrink_slab_node) from [<c01e12b8>] (shrink_slab+0x70/0xe4)
[ 374.036074] [<c01e12b8>] (shrink_slab) from [<c01e46f4>] (kswapd+0x7c0/0x9f8)
[ 374.036083] [<c01e46f4>] (kswapd) from [<c013b9b4>] (kthread+0xdc/0xf0)
[ 374.036094] [<c013b9b4>] (kthread) from [<c0105f80>] (ret_from_fork+0x14/0x34)


[53815.902603] CPU: 0 PID: 7242 Comm: CAM_defrdWrk Tainted: G W 3.18.31-perf-g5e6acc4-00672-g606f204-dirty #31
[53815.902631] [<c010cd84>] (unwind_backtrace) from [<c01099f4>] (show_stack+0x10/0x14)
[53815.902644] [<c01099f4>] (show_stack) from [<c0baf53c>] (dump_stack+0x78/0x98)
[53815.902658] [<c0baf53c>] (dump_stack) from [<c082a824>] (lowmem_scan+0x408/0x7e0)
[53815.902669] [<c082a824>] (lowmem_scan) from [<c01e0ba4>] (shrink_slab_node+0x204/0x3d0)
[53815.902678] [<c01e0ba4>] (shrink_slab_node) from [<c01e12b8>] (shrink_slab+0x70/0xe4)
[53815.902686] [<c01e12b8>] (shrink_slab) from [<c01e3ba8>] (try_to_free_pages+0x3c0/0x74c)
[53815.902696] [<c01e3ba8>] (try_to_free_pages) from [<c01d9188>] (__alloc_pages_nodemask+0x578/0x92c)
[53815.902707] [<c01d9188>] (__alloc_pages_nodemask) from [<c0819648>] (ion_page_pool_alloc_pages+0x20/0x68)
[53815.902718] [<c0819648>] (ion_page_pool_alloc_pages) from [<c08196c8>] (ion_page_pool_alloc+0x38/0x94)
[53815.902728] [<c08196c8>] (ion_page_pool_alloc) from [<c081a4e4>] (ion_system_heap_allocate+0x158/0x564)
[53815.902739] [<c081a4e4>] (ion_system_heap_allocate) from [<c081750c>] (__ion_alloc+0x170/0x8dc)
[53815.902749] [<c081750c>] (__ion_alloc) from [<c0817f40>] (ion_ioctl+0x168/0x3c8)
[53815.902759] [<c0817f40>] (ion_ioctl) from [<c02265b0>] (do_vfs_ioctl+0x4cc/0x58c)
[53815.902768] [<c02265b0>] (do_vfs_ioctl) from [<c02266bc>] (SyS_ioctl+0x4c/0x74)
[53815.902778] [<c02266bc>] (SyS_ioctl) from [<c0105ee0>] (ret_fast_syscall+0x0/0x38)


[53815.860035] CPU: 0 PID: 6761 Comm: kworker/u8:4 Tainted: G W 3.18.31-perf-g5e6acc4-00672-g606f204-dirty #31
[53815.860053] Workqueue: events_unbound swap_fn
[53815.860071] [<c010cd84>] (unwind_backtrace) from [<c01099f4>] (show_stack+0x10/0x14)
[53815.860083] [<c01099f4>] (show_stack) from [<c0baf53c>] (dump_stack+0x78/0x98)
[53815.860096] [<c0baf53c>] (dump_stack) from [<c082a824>] (lowmem_scan+0x408/0x7e0)
[53815.860107] [<c082a824>] (lowmem_scan) from [<c01e0ba4>] (shrink_slab_node+0x204/0x3d0)
[53815.860116] [<c01e0ba4>] (shrink_slab_node) from [<c01e12b8>] (shrink_slab+0x70/0xe4)
[53815.860124] [<c01e12b8>] (shrink_slab) from [<c01e3ba8>] (try_to_free_pages+0x3c0/0x74c)
[53815.860134] [<c01e3ba8>] (try_to_free_pages) from [<c01d9188>] (__alloc_pages_nodemask+0x578/0x92c)
[53815.860144] [<c01d9188>] (__alloc_pages_nodemask) from [<c0212a5c>] (zs_malloc+0xc0/0x2e0)
[53815.860156] [<c0212a5c>] (zs_malloc) from [<c052b0d8>] (zram_bvec_rw+0x3e4/0x7fc)
[53815.860166] [<c052b0d8>] (zram_bvec_rw) from [<c052b644>] (zram_rw_page+0x154/0x168)
[53815.860177] [<c052b644>] (zram_rw_page) from [<c0244f20>] (bdev_write_page+0x6c/0x98)
[53815.860188] [<c0244f20>] (bdev_write_page) from [<c0206c38>] (__swap_writepage+0x1b4/0x27c)
[53815.860198] [<c0206c38>] (__swap_writepage) from [<c01e203c>] (shrink_page_list+0x57c/0x9b0)
[53815.860207] [<c01e203c>] (shrink_page_list) from [<c01e2658>] (reclaim_pages_from_list+0xa8/0x108)
[53815.860217] [<c01e2658>] (reclaim_pages_from_list) from [<c0263968>] (reclaim_pte_range+0x11c/0x184)
[53815.860228] [<c0263968>] (reclaim_pte_range) from [<c0203ce8>] (walk_page_range+0x1b8/0x248)
[53815.860238] [<c0203ce8>] (walk_page_range) from [<c026462c>] (reclaim_task_anon+0xb4/0x11c)
[53815.860248] [<c026462c>] (reclaim_task_anon) from [<c0214524>] (swap_fn+0x248/0x4ec)
[53815.860258] [<c0214524>] (swap_fn) from [<c0137434>] (process_one_work+0x254/0x464)
[53815.860267] [<c0137434>] (process_one_work) from [<c013816c>] (worker_thread+0x2b4/0x3f8)
[53815.860277] [<c013816c>] (worker_thread) from [<c013b9b4>] (kthread+0xdc/0xf0)
[53815.860287] [<c013b9b4>] (kthread) from [<c0105f80>] (ret_from_fork+0x14/0x34)

Over.