lmkd: Add a margin for watermark when swap free is low

When swap is depleted file cache thrashing might result in allocations
quickly pushing memory below low watermark and kswapd quickly pushing
it back above high watermark. In this situation free memory stays above
high watermark most of the time and lmkd during its periodic wake-ups
has low chance of detecting low memory conditions. Add a 15% margin
for high watermark which would allow lmkd to kill if swap is low,some
memory was reclaimed since the last wakeup and free memory is just
above the high watermark limit.

Bug: 163134367
Test: heavy loading launch
Signed-off-by: Martin Liu <liumartin@google.com>
Change-Id: I5694736b04bafcd13c01f4b51e242e2ac4ff55a8
This commit is contained in:
Martin Liu 2020-08-14 03:11:22 +08:00
parent fa667edb56
commit 95551f816a
1 changed files with 5 additions and 3 deletions

View File

@ -2239,9 +2239,11 @@ struct zone_watermarks {
* Returns lowest breached watermark or WMARK_NONE.
*/
static enum zone_watermark get_lowest_watermark(union meminfo *mi,
struct zone_watermarks *watermarks)
struct zone_watermarks *watermarks,
long margin)
{
int64_t nr_free_pages = mi->field.nr_free_pages - mi->field.cma_free;
int64_t high_wmark = (watermarks->high_wmark * margin) / 100;
if (nr_free_pages < watermarks->min_wmark) {
return WMARK_MIN;
@ -2249,7 +2251,7 @@ static enum zone_watermark get_lowest_watermark(union meminfo *mi,
if (nr_free_pages < watermarks->low_wmark) {
return WMARK_LOW;
}
if (nr_free_pages < watermarks->high_wmark) {
if (nr_free_pages < high_wmark) {
return WMARK_HIGH;
}
return WMARK_NONE;
@ -2406,7 +2408,7 @@ static void mp_event_psi(int data, uint32_t events, struct polling_params *poll_
}
/* Find out which watermark is breached if any */
wmark = get_lowest_watermark(&mi, &watermarks);
wmark = get_lowest_watermark(&mi, &watermarks, swap_is_low ? 115 : 100);
/*
* TODO: move this logic into a separate function