提交 69b7189f 编写于 作者: V Vlastimil Babka 提交者: Linus Torvalds

mm, compaction: skip rechecks when lock was already held

Compaction scanners try to lock zone locks as late as possible by checking
many page or pageblock properties opportunistically without lock and
skipping them if not unsuitable.  For pages that pass the initial checks,
some properties have to be checked again safely under lock.  However, if
the lock was already held from a previous iteration in the initial checks,
the rechecks are unnecessary.

This patch therefore skips the rechecks when the lock was already held.
This is now possible to do, since we don't (potentially) drop and
reacquire the lock between the initial checks and the safe rechecks
anymore.
Signed-off-by: NVlastimil Babka <vbabka@suse.cz>
Reviewed-by: NZhang Yanfei <zhangyanfei@cn.fujitsu.com>
Reviewed-by: NNaoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Acked-by: NMinchan Kim <minchan@kernel.org>
Acked-by: NMel Gorman <mgorman@suse.de>
Cc: Michal Nazarewicz <mina86@mina86.com>
Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Rik van Riel <riel@redhat.com>
Acked-by: NDavid Rientjes <rientjes@google.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 8b44d279
...@@ -366,6 +366,14 @@ static unsigned long isolate_freepages_block(struct compact_control *cc, ...@@ -366,6 +366,14 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
if (!PageBuddy(page)) if (!PageBuddy(page))
goto isolate_fail; goto isolate_fail;
/*
* If we already hold the lock, we can skip some rechecking.
* Note that if we hold the lock now, checked_pageblock was
* already set in some previous iteration (or strict is true),
* so it is correct to skip the suitable migration target
* recheck as well.
*/
if (!locked) {
/* /*
* The zone lock must be held to isolate freepages. * The zone lock must be held to isolate freepages.
* Unfortunately this is a very coarse lock and can be * Unfortunately this is a very coarse lock and can be
...@@ -374,7 +382,6 @@ static unsigned long isolate_freepages_block(struct compact_control *cc, ...@@ -374,7 +382,6 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
* spin on the lock and we acquire the lock as late as * spin on the lock and we acquire the lock as late as
* possible. * possible.
*/ */
if (!locked)
locked = compact_trylock_irqsave(&cc->zone->lock, locked = compact_trylock_irqsave(&cc->zone->lock,
&flags, cc); &flags, cc);
if (!locked) if (!locked)
...@@ -383,6 +390,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc, ...@@ -383,6 +390,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
/* Recheck this is a buddy page under lock */ /* Recheck this is a buddy page under lock */
if (!PageBuddy(page)) if (!PageBuddy(page))
goto isolate_fail; goto isolate_fail;
}
/* Found a free page, break it into order-0 pages */ /* Found a free page, break it into order-0 pages */
isolated = split_free_page(page); isolated = split_free_page(page);
...@@ -644,8 +652,8 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, ...@@ -644,8 +652,8 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
page_count(page) > page_mapcount(page)) page_count(page) > page_mapcount(page))
continue; continue;
/* If the lock is not held, try to take it */ /* If we already hold the lock, we can skip some rechecking */
if (!locked) if (!locked) {
locked = compact_trylock_irqsave(&zone->lru_lock, locked = compact_trylock_irqsave(&zone->lru_lock,
&flags, cc); &flags, cc);
if (!locked) if (!locked)
...@@ -658,6 +666,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, ...@@ -658,6 +666,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
low_pfn += (1 << compound_order(page)) - 1; low_pfn += (1 << compound_order(page)) - 1;
continue; continue;
} }
}
lruvec = mem_cgroup_page_lruvec(page, zone); lruvec = mem_cgroup_page_lruvec(page, zone);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册