Get rid of if(PageLocked()) This introduces another race condition since another process may have locked the page. Simply relock the page after successfully calling migratepages() and then retry. Signed-off-by: Christoph Lameter Index: linux-2.6.17-rc2-mm1/mm/migrate.c =================================================================== --- linux-2.6.17-rc2-mm1.orig/mm/migrate.c 2006-04-27 22:55:46.731119932 -0700 +++ linux-2.6.17-rc2-mm1/mm/migrate.c 2006-04-27 23:39:11.853319378 -0700 @@ -476,17 +476,20 @@ /* Someone else already triggered a write */ return -EAGAIN; - if (mapping->a_ops->writepage(page, &wbc) < 0) + rc = mapping->a_ops->writepage(page, &wbc); + if (rc < 0) /* I/O Error writing */ return -EIO; + if (rc == AOP_WRITEPAGE_ACTIVATE) + return -EAGAIN; + + lock_page(page); /* - * Retry if writepage() removed the lock or the page - * is still dirty or undergoing writeback. + * The lock was dropped by writepage() and so something + * may have changed with the page. */ - if (!PageLocked(page) || - PageWriteback(page) || PageDirty(page)) - return -EAGAIN; + return -EAGAIN; } /* @@ -599,8 +602,7 @@ unlock_page(newpage); unlock_page: - if (PageLocked(page)) /* writepage() may unlock */ - unlock_page(page); + unlock_page(page); next: if (rc) {