Skip to contentSkip to conversation

staging: android: lowmemorykiller: neglect swap cached pages in other_file

PATCH In review [email protected] 2 participants 2 messages Feb 26, 2014 – Aug 11, 2015 Staging

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 staging: android: lowmemorykiller: neglect swap cached pages in other_file

From: Vinayak Menon <[email protected]>

With ZRAM enabled it is observed that lowmemory killer doesn't trigger properly. swap cached pages are accounted in NR_FILE, and lowmemorykiller considers this as reclaimable and adds to other_file. But these pages can't be reclaimed unless lowmemorykiller triggers. So subtract swap pages from other_file.

---
 drivers/staging/android/lowmemorykiller.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/android/lowmemorykiller.c +2 -1
index 6f094b3..9e931b2 100644
@@ -88,7 +88,8 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)
 	int array_size = ARRAY_SIZE(lowmem_adj);
 	int other_free = global_page_state(NR_FREE_PAGES) - totalreserve_pages;
 	int other_file = global_page_state(NR_FILE_PAGES) -
-						global_page_state(NR_SHMEM);
+						global_page_state(NR_SHMEM) -
+						total_swapcache_pages();
 
 	if (lowmem_adj_size < array_size)
 		array_size = lowmem_adj_size;
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 6 lines · On 02/26/2014 11:06 AM, [email protected] wrote:

With ZRAM enabled it is observed that lowmemory killer doesn't trigger properly. swap cached pages are accounted in NR_FILE, and lowmemorykiller considers this as reclaimable and adds to other_file. But these pages can't be reclaimed unless lowmemorykiller triggers. So subtract swap pages from other_file.

...

drivers/staging/android/lowmemorykiller.c static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc) · line 92

Quoted 9 lines
drivers/staging/android/lowmemorykiller.c +2 -1
@@ -88,7 +88,8 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)
 	int array_size = ARRAY_SIZE(lowmem_adj);
 	int other_free = global_page_state(NR_FREE_PAGES) - totalreserve_pages;
 	int other_file = global_page_state(NR_FILE_PAGES) -
-						global_page_state(NR_SHMEM);
+						global_page_state(NR_SHMEM) -
+						total_swapcache_pages();

Sorry to dredge up an ancient thread. But, I'm not sure this is a good commit

The swap cache is there for pages which are still in RAM but are also in some stage of being written to disk. In this case, the "disk" in question is ZRAM.

So, pages in the swap cache are probably "present" simultaneously in the swap cache (the original copy) *and* in ZRAM (the compressed copy). Swap cache pages *do* become reclaimable once their write to the backing store is complete (just like any other dirty data).

I assume that this patch did *some* good, but perhaps it was via another mechanism that what was described in the commit message. Or, perhaps the fact that ZRAM consumes RAM has thrown the lowmemorykiller off somehow, and this helps to compensate for that effect.

Vinayak, how have you seen this patch help?