Skip to contentSkip to conversation

mm-vmscan-fix-do_try_to_free_pages-livelock.patch removed from -mm tree

merged [email protected] 1 participant 1 message Sep 12, 2013

Subsystems (7)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

Subject: [merged] mm-vmscan-fix-do_try_to_free_pages-livelock.patch removed from -mm tree
To: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]
From: [email protected]
Date: Thu, 12 Sep 2013 12:45:01 -0700

The patch titled
Subject: mm: vmscan: fix do_try_to_free_pages() livelock
has been removed from the -mm tree. Its filename was
mm-vmscan-fix-do_try_to_free_pages-livelock.patch

This patch was dropped because it was merged into mainline or a subsystem tree

------------------------------------------------------
From: Lisa Du <[email protected]>
Subject: mm: vmscan: fix do_try_to_free_pages() livelock

This patch is based on KOSAKI's work and I add a little more description, please refer https://lkml.org/lkml/2012/6/14/74.

Currently, I found system can enter a state that there are lots of free pages in a zone but only order-0 and order-1 pages which means the zone is heavily fragmented, then high order allocation could make direct reclaim path's long stall(ex, 60 seconds) especially in no swap and no compaciton enviroment. This problem happened on v3.4, but it seems issue still lives in current tree, the reason is do_try_to_free_pages enter live lock:

kswapd will go to sleep if the zones have been fully scanned and are still not balanced. As kswapd thinks there's little point trying all over again to avoid infinite loop. Instead it changes order from high-order to 0-order because kswapd think order-0 is the most important. Look at 73ce02e9 in detail. If watermarks are ok, kswapd will go back to sleep and may leave zone->all_unreclaimable =3D 0. It assume high-order users can still perform direct reclaim if they wish.

Direct reclaim continue to reclaim for a high order which is not a COSTLY_ORDER without oom-killer until kswapd turn on zone->all_unreclaimble= . This is because to avoid too early oom-kill. So it means direct_reclaim depends on kswapd to break this loop.

In worst case, direct-reclaim may continue to page reclaim forever when kswapd sleeps forever until someone like watchdog detect and finally kill the process. As described in:
http://thread.gmane.org/gmane.linux.kernel.mm/103737

We can't turn on zone->all_unreclaimable from direct reclaim path because direct reclaim path don't take any lock and this way is racy. Thus this patch removes zone->all_unreclaimable field completely and recalculates zone reclaimable state every time.

Note: we can't take the idea that direct-reclaim see zone->pages_scanned directly and kswapd continue to use zone->all_unreclaimable. Because, it is racy. commit 929bea7c71 (vmscan: all_unreclaimable() use zone->all_unreclaimable as a name) describes the detail.

[[email protected]: uninline zone_reclaimable_pages() and zone_reclaimable()]
Cc Aaditya Kumar <[email protected]>
Cc Ying Han <[email protected]>
Cc Nick Piggin <[email protected]>
Cc Mel Gorman <[email protected]>
Cc KAMEZAWA Hiroyuki <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc Bob Liu <[email protected]>
Cc Neil Zhang <[email protected]>
Cc Russell King - ARM Linux <[email protected]>

---

 include/linux/mm_inline.h |    1 
 include/linux/mmzone.h    |    1 
 include/linux/vmstat.h    |    1 
 mm/internal.h             |    2 +
 mm/migrate.c              |    2 -
 mm/page-writeback.c       |    3 +
 mm/page_alloc.c           |    5 +-
 mm/vmscan.c               |   66 ++++++++++++++++--------------------
 mm/vmstat.c               |    5 ++
 9 files changed, 44 insertions(+), 42 deletions(-)
include/linux/mm_inline.h renamed from include/linux/mm_inline.h~mm-vmscan-fix-do_try_to_free_pages-livelock +1 -0
diff -puN include/linux/mm_inline.h~mm-vmscan-fix-do_try_to_free_pages-livelock include/linux/mm_inline.h
@@ -2,6 +2,7 @@
 #define LINUX_MM_INLINE_H
 
 #include <linux/huge_mm.h>
+#include <linux/swap.h>
 
 /**
  * page_is_file_cache - should the page be on a file LRU or anon LRU?
include/linux/mmzone.h renamed from include/linux/mmzone.h~mm-vmscan-fix-do_try_to_free_pages-livelock +0 -1
diff -puN include/linux/mmzone.h~mm-vmscan-fix-do_try_to_free_pages-livelock include/linux/mmzone.h
@@ -353,7 +353,6 @@ struct zone {
 	 * free areas of different sizes
 	 */
 	spinlock_t		lock;
-	int                     all_unreclaimable; /* All pages pinned */
 #if defined CONFIG_COMPACTION || defined CONFIG_CMA
 	/* Set to true when the PG_migrate_skip bits should be cleared */
 	bool			compact_blockskip_flush;
include/linux/vmstat.h renamed from include/linux/vmstat.h~mm-vmscan-fix-do_try_to_free_pages-livelock +0 -1
diff -puN include/linux/vmstat.h~mm-vmscan-fix-do_try_to_free_pages-livelock include/linux/vmstat.h
@@ -143,7 +143,6 @@ static inline unsigned long zone_page_st
 }
 
 extern unsigned long global_reclaimable_pages(void);
-extern unsigned long zone_reclaimable_pages(struct zone *zone);
 
 #ifdef CONFIG_NUMA
 /*
mm/internal.h renamed from mm/internal.h~mm-vmscan-fix-do_try_to_free_pages-livelock +2 -0
diff -puN mm/internal.h~mm-vmscan-fix-do_try_to_free_pages-livelock mm/internal.h
@@ -85,6 +85,8 @@ extern unsigned long highest_memmap_pfn;
  */
 extern int isolate_lru_page(struct page *page);
 extern void putback_lru_page(struct page *page);
+extern unsigned long zone_reclaimable_pages(struct zone *zone);
+extern bool zone_reclaimable(struct zone *zone);
 
 /*
  * in mm/rmap.c:
mm/migrate.c renamed from mm/migrate.c~mm-vmscan-fix-do_try_to_free_pages-livelock +1 -1
diff -puN mm/migrate.c~mm-vmscan-fix-do_try_to_free_pages-livelock mm/migrate.c
@@ -1471,7 +1471,7 @@ static bool migrate_balanced_pgdat(struc
 		if (!populated_zone(zone))
 			continue;
 
-		if (zone->all_unreclaimable)
+		if (!zone_reclaimable(zone))
 			continue;
 
 		/* Avoid waking kswapd by allocating pages_to_migrate pages. */
mm/page-writeback.c renamed from mm/page-writeback.c~mm-vmscan-fix-do_try_to_free_pages-livelock +3 -0
diff -puN mm/page-writeback.c~mm-vmscan-fix-do_try_to_free_pages-livelock mm/page-writeback.c
@@ -36,8 +36,11 @@
 #include <linux/pagevec.h>
 #include <linux/timer.h>
 #include <linux/sched/rt.h>
+#include <linux/mm_inline.h>
 #include <trace/events/writeback.h>
 
+#include "internal.h"
+
 /*
  * Sleep at most 200ms at a time in balance_dirty_pages().
  */
mm/page_alloc.c renamed from mm/page_alloc.c~mm-vmscan-fix-do_try_to_free_pages-livelock +2 -3
diff -puN mm/page_alloc.c~mm-vmscan-fix-do_try_to_free_pages-livelock mm/page_alloc.c
@@ -56,6 +56,7 @@
 #include <linux/ftrace_event.h>
 #include <linux/memcontrol.h>
 #include <linux/prefetch.h>
+#include <linux/mm_inline.h>
 #include <linux/migrate.h>
 #include <linux/page-debug-flags.h>
 #include <linux/hugetlb.h>
@@ -647,7 +648,6 @@ static void free_pcppages_bulk(struct zo
 	int to_free = count;
 
 	spin_lock(&zone->lock);
-	zone->all_unreclaimable = 0;
 	zone->pages_scanned = 0;
 
 	while (to_free) {
@@ -696,7 +696,6 @@ static void free_one_page(struct zone *z
 				int migratetype)
 {
 	spin_lock(&zone->lock);
-	zone->all_unreclaimable = 0;
 	zone->pages_scanned = 0;
 
 	__free_one_page(page, zone, order, migratetype);
@@ -3164,7 +3163,7 @@ void show_free_areas(unsigned int filter
 			K(zone_page_state(zone, NR_FREE_CMA_PAGES)),
 			K(zone_page_state(zone, NR_WRITEBACK_TEMP)),
 			zone->pages_scanned,
-			(zone->all_unreclaimable ? "yes" : "no")
+			(!zone_reclaimable(zone) ? "yes" : "no")
 			);
 		printk("lowmem_reserve[]:");
 		for (i = 0; i < MAX_NR_ZONES; i++)
mm/vmscan.c renamed from mm/vmscan.c~mm-vmscan-fix-do_try_to_free_pages-livelock +31 -35

149 lines not on this page · raw message

mm/vmstat.c renamed from mm/vmstat.c~mm-vmscan-fix-do_try_to_free_pages-livelock +4 -1
diff -puN mm/vmstat.c~mm-vmscan-fix-do_try_to_free_pages-livelock mm/vmstat.c
@@ -19,6 +19,9 @@
 #include <linux/math64.h>
 #include <linux/writeback.h>
 #include <linux/compaction.h>
+#include <linux/mm_inline.h>
+
+#include "internal.h"
 
 #ifdef CONFIG_VM_EVENT_COUNTERS
 DEFINE_PER_CPU(struct vm_event_state, vm_event_states) = {{0}};
@@ -1088,7 +1091,7 @@ static void zoneinfo_show_print(struct s
 		   "\n  all_unreclaimable: %u"
 		   "\n  start_pfn:         %lu"
 		   "\n  inactive_ratio:    %u",
-		   zone->all_unreclaimable,
+		   !zone_reclaimable(zone),
 		   zone->zone_start_pfn,
 		   zone->inactive_ratio);
 	seq_putc(m, '\n');

_

Patches currently in -mm which might be from [email protected] are

origin.patch