mem-hotplug: call isolate_lru_page with elevated refcount
Subsystems (5)
PATCH 1/3 mem-hotplug: call isolate_lru_page with elevated refcount
isolate_lru_page() must be called only with stable reference to page. So, let's grab normal page reference.
--- mm/memory_hotplug.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
mm/memory_hotplug.c +3 -1
@@ -705,7 +705,7 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)if (!pfn_valid (pfn))continue ; page =pfn_to_page (pfn); -if (!page_count (page)) +if (!get_page_unless_zero (page))continue ;/* * We can skip free pages. And we can only deal with pages on
@@ -713,6 +713,7 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)*/ ret =isolate_lru_page (page);if (!ret) {/* Success */ +put_page (page);list_add_tail (&page->lru, &source); move_pages--; inc_zone_page_state(page, NR_ISOLATED_ANON +
@@ -724,6 +725,7 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) pfn);dump_page (page);#endif +put_page (page);/* Because we don't have big zone->lock. we should check this again here. */ if (page_count (page)) {
PATCH 2/3 mem-hwpoison: fix page refcount around isolate_lru_page()
Drop first page reference only after calling isolate_lru_page() to keep page stable reference while isolating.
--- mm/memory-failure.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
mm/memory-failure.c +6 -5
@@ -1440,16 +1440,12 @@ int soft_offline_page(struct page *page, int flags)*/ ret =invalidate_inode_page (page);unlock_page (page); -/* -* Drop count because page migration doesn't like raised -* counts. The page could get re-allocated, but if it becomes -* LRU the isolation will just fail. * RED-PEN would be better to keep it isolated here, but we * would need to fix isolation locking first. */ -put_page (page);if (ret ==1 ) { +put_page (page); ret =0 ;pr_info ("soft_offline: %#lx: invalidated\n" , pfn); goto done;
@@ -1461,6 +1457,11 @@ int soft_offline_page(struct page *page, int flags)* handles a large number of cases for us. */ ret =isolate_lru_page (page); +/* +* Drop page reference which is came from get_any_page() +* successful isolate_lru_page() already took another one. +*/ +put_page (page);if (!ret) {LIST_HEAD (pagelist);
PATCH 3/3 mm: strictly require elevated page refcount in isolate_lru_page()
In reply to Konstantin Khlebnikovisolate_lru_page() must be called only with stable reference to the page, this is what is written in the comment above it, this is reasonable.
current isolate_lru_page() users and its page extra reference sources:
mm/huge_memory.c__collapse_huge_page_isolate() - reference from pte
mm/memcontrol.cmem_cgroup_move_parent() - get_page_unless_zero()mem_cgroup_move_charge_pte_range() - reference from pte
mm/memory-failure.csoft_offline_page() - fixed, reference from get_any_page()delete_from_lru_cache() - reference from caller or get_page_unless_zero() [seems like there bug, because __memory_failure() can call page_action() for
hpages tail, but it is ok for isolate_lru_page(), tail getted and not in lru]
mm/memory_hotplug.cdo_migrate_range() - fixed, get_page_unless_zero()
mm/mempolicy.cmigrate_page_add() - reference from pte
mm/migrate.cdo_move_page_to_node_array() - reference from follow_page()
mlock.c - various external references
mm/vmscan.cputback_lru_page() - reference from isolate_lru_page()
It seems that all isolate_lru_page() users are ready now for this restriction. So, let's replace redundant get_page_unless_zero() with get_page() and add page initial reference count check with VM_BUG_ON()
--- mm/vmscan.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
mm/vmscan.c +4 -1
@@ -1201,13 +1201,16 @@ int isolate_lru_page(struct page *page) {int ret = -EBUSY ; +VM_BUG_ON (!page_count (page)); +if (PageLRU (page)) {struct zone *zone =page_zone (page);spin_lock_irq (&zone->lru_lock); -if (PageLRU (page) &&get_page_unless_zero (page)) { +if (PageLRU (page)) {int lru =page_lru (page); ret =0 ; +get_page (page);ClearPageLRU (page);del_page_from_lru_list (zone, page, lru);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>