From 46983902958d1c2a748652fbbac7d265d7ff1bbb Mon Sep 17 00:00:00 2001 From: Shaohua Li Date: Fri, 21 Sep 2012 11:00:25 +1000 Subject: [PATCH] mm: compaction: check lock contention first before taking lock 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 Acked-by: Mel Gorman Acked-by: Minchan Kim Signed-off-by: Andrew Morton --- mm/compaction.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 0649cc1b3479..35c75744799c 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -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; -- 2.39.5