]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
mm: compaction: check lock contention first before taking lock
authorShaohua Li <shli@kernel.org>
Fri, 21 Sep 2012 01:00:25 +0000 (11:00 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Fri, 21 Sep 2012 05:58:56 +0000 (15:58 +1000)
isolate_migratepages_range will take zone->lru_lock first and check if the
lock is contented, if yes, it will release the lock.  This isn't
efficient.  If the lock is truly contented, a lock/unlock pair will
increase the lock contention.  We'd better check if the lock is contended
first.  compact_trylock_irqsave perfectly meets the requirement.

Signed-off-by: Shaohua Li <shli@fusionio.com>
Acked-by: Mel Gorman <mgorman@suse.de>
Acked-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/compaction.c

index 0649cc1b3479daf56bc1a3b995b7c5c5ef59dd9d..35c75744799c582427b1039aa9ad96b912e04e43 100644 (file)
@@ -349,8 +349,9 @@ isolate_migratepages_range(struct zone *zone, struct compact_control *cc,
 
        /* Time to isolate some pages for migration */
        cond_resched();
-       spin_lock_irqsave(&zone->lru_lock, flags);
-       locked = true;
+       locked = compact_trylock_irqsave(&zone->lru_lock, &flags, cc);
+       if (!locked)
+               return 0;
        for (; low_pfn < end_pfn; low_pfn++) {
                struct page *page;