Re: [PATCH 2/6] mm: mlocking in try_to_unmap_one

KOSAKI Motohiro
2009-11-11T07:56:27Z

Hi Hugh

> @@ -1081,45 +1053,23 @@ static int try_to_unmap_file(struct page
> unsigned long max_nl_cursor = 0;
> unsigned long max_nl_size = 0;
> unsigned int mapcount;
> - unsigned int mlocked = 0;
> - int unlock = TTU_ACTION(flags) == TTU_MUNLOCK;
> -
> - if (MLOCK_PAGES && unlikely(unlock))
> - ret = SWAP_SUCCESS; /* default for try_to_munlock() */
>
> spin_lock(&mapping->i_mmap_lock);
> vma_prio_tree_foreach(vma, &iter, &mapping->i_mmap, pgoff, pgoff) {
> - if (MLOCK_PAGES && unlikely(unlock)) {
> - if (!((vma->vm_flags & VM_LOCKED) &&
> - page_mapped_in_vma(page, vma)))
> - continue; /* must visit all vmas */
> - ret = SWAP_MLOCK;
> - } else {
> - ret = try_to_unmap_one(page, vma, flags);
> - if (ret == SWAP_FAIL || !page_mapped(page))
> - goto out;
> - }
> - if (ret == SWAP_MLOCK) {
> - mlocked = try_to_mlock_page(page, vma);
> - if (mlocked)
> - break; /* stop if actually mlocked page */
> - }
> + ret = try_to_unmap_one(page, vma, flags);
> + if (ret != SWAP_AGAIN || !page_mapped(page))
> + goto out;
> }
>
> - if (mlocked)
> + if (list_empty(&mapping->i_mmap_nonlinear))
> goto out;
>
> - if (list_empty(&mapping->i_mmap_nonlinear))
> + /* We don't bother to try to find the munlocked page in nonlinears */
> + if (MLOCK_PAGES && TTU_ACTION(flags) == TTU_MUNLOCK)
> goto out;

I have dumb question.
Does this shortcut exiting code makes any behavior change?

>
> list_for_each_entry(vma, &mapping->i_mmap_nonlinear,
> shared.vm_set.list) {
> - if (MLOCK_PAGES && unlikely(unlock)) {
> - if (!(vma->vm_flags & VM_LOCKED))
> - continue; /* must visit all vmas */
> - ret = SWAP_MLOCK; /* leave mlocked == 0 */
> - goto out; /* no need to look further */
> - }
> if (!MLOCK_PAGES && !(flags & TTU_IGNORE_MLOCK) &&
> (vma->vm_flags & VM_LOCKED))
> continue;
> @@ -1161,10 +1111,9 @@ static int try_to_unmap_file(struct page
> cursor = (unsigned long) vma->vm_private_data;
> while ( cursor < max_nl_cursor &&
> cursor < vma->vm_end - vma->vm_start) {
> - ret = try_to_unmap_cluster(cursor, &mapcount,
> - vma, page);
> - if (ret == SWAP_MLOCK)
> - mlocked = 2; /* to return below */
> + if (try_to_unmap_cluster(cursor, &mapcount,
> + vma, page) == SWAP_MLOCK)
> + ret = SWAP_MLOCK;
> cursor += CLUSTER_SIZE;
> vma->vm_private_data = (void *) cursor;
> if ((int)mapcount <= 0)
> @@ -1185,10 +1134,6 @@ static int try_to_unmap_file(struct page
> vma->vm_private_data = NULL;
> out:
> spin_unlock(&mapping->i_mmap_lock);
> - if (mlocked)
> - ret = SWAP_MLOCK; /* actually mlocked the page */
> - else if (ret == SWAP_MLOCK)
> - ret = SWAP_AGAIN; /* saw VM_LOCKED vma */
> return ret;
> }
>