The rmap walk must reach every possible mapping of the page, so if a page is heavily shared (no matter if it's KSM, anon, pagecache) there will be tons of entries to walk through. All optimizations with prio_tree, anon_vma chains, interval tree, helps to find the right virtual mapping faster, but if there are lots of virtual mappings, all mapping must still be walked through. The biggest cost is for the IPIs, but regardless of the IPIs, it's generally safer to keep these cond_resched() in all cases, as even if we massively reduce the number of IPIs, the number of entries to walk IPI-less may still be large and no entry can be possibly skipped in the page migration case. Acked-by: Hugh Dickins <hughd@xxxxxxxxxx> Signed-off-by: Andrea Arcangeli <aarcange@xxxxxxxxxx> --- mm/ksm.c | 2 ++ mm/rmap.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/mm/ksm.c b/mm/ksm.c index 7ee101e..e87dec7 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1914,9 +1914,11 @@ again: struct anon_vma_chain *vmac; struct vm_area_struct *vma; + cond_resched(); anon_vma_lock_read(anon_vma); anon_vma_interval_tree_foreach(vmac, &anon_vma->rb_root, 0, ULONG_MAX) { + cond_resched(); vma = vmac->vma; if (rmap_item->address < vma->vm_start || rmap_item->address >= vma->vm_end) diff --git a/mm/rmap.c b/mm/rmap.c index f5b5c1f..b949778 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1607,6 +1607,8 @@ static int rmap_walk_anon(struct page *page, struct rmap_walk_control *rwc) struct vm_area_struct *vma = avc->vma; unsigned long address = vma_address(page, vma); + cond_resched(); + if (rwc->invalid_vma && rwc->invalid_vma(vma, rwc->arg)) continue; @@ -1656,6 +1658,8 @@ static int rmap_walk_file(struct page *page, struct rmap_walk_control *rwc) vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff) { unsigned long address = vma_address(page, vma); + cond_resched(); + if (rwc->invalid_vma && rwc->invalid_vma(vma, rwc->arg)) continue; -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@xxxxxxxxx. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@xxxxxxxxx"> email@xxxxxxxxx </a>