cifs: fix uninitialised var in smb2_compound_op()
[linux-2.6-microblaze.git] / mm / migrate.c
index eb594b0..c228afb 100644 (file)
@@ -993,17 +993,15 @@ out:
        return rc;
 }
 
-static int __unmap_and_move(struct page *page, struct page *newpage,
+static int __unmap_and_move(struct folio *src, struct folio *dst,
                                int force, enum migrate_mode mode)
 {
-       struct folio *folio = page_folio(page);
-       struct folio *dst = page_folio(newpage);
        int rc = -EAGAIN;
        bool page_was_mapped = false;
        struct anon_vma *anon_vma = NULL;
-       bool is_lru = !__PageMovable(page);
+       bool is_lru = !__PageMovable(&src->page);
 
-       if (!trylock_page(page)) {
+       if (!folio_trylock(src)) {
                if (!force || mode == MIGRATE_ASYNC)
                        goto out;
 
@@ -1023,10 +1021,10 @@ static int __unmap_and_move(struct page *page, struct page *newpage,
                if (current->flags & PF_MEMALLOC)
                        goto out;
 
-               lock_page(page);
+               folio_lock(src);
        }
 
-       if (PageWriteback(page)) {
+       if (folio_test_writeback(src)) {
                /*
                 * Only in the case of a full synchronous migration is it
                 * necessary to wait for PageWriteback. In the async case,
@@ -1043,39 +1041,39 @@ static int __unmap_and_move(struct page *page, struct page *newpage,
                }
                if (!force)
                        goto out_unlock;
-               wait_on_page_writeback(page);
+               folio_wait_writeback(src);
        }
 
        /*
-        * By try_to_migrate(), page->mapcount goes down to 0 here. In this case,
-        * we cannot notice that anon_vma is freed while we migrates a page.
+        * By try_to_migrate(), src->mapcount goes down to 0 here. In this case,
+        * we cannot notice that anon_vma is freed while we migrate a page.
         * This get_anon_vma() delays freeing anon_vma pointer until the end
         * of migration. File cache pages are no problem because of page_lock()
         * File Caches may use write_page() or lock_page() in migration, then,
         * just care Anon page here.
         *
-        * Only page_get_anon_vma() understands the subtleties of
+        * Only folio_get_anon_vma() understands the subtleties of
         * getting a hold on an anon_vma from outside one of its mms.
         * But if we cannot get anon_vma, then we won't need it anyway,
         * because that implies that the anon page is no longer mapped
         * (and cannot be remapped so long as we hold the page lock).
         */
-       if (PageAnon(page) && !PageKsm(page))
-               anon_vma = page_get_anon_vma(page);
+       if (folio_test_anon(src) && !folio_test_ksm(src))
+               anon_vma = folio_get_anon_vma(src);
 
        /*
         * Block others from accessing the new page when we get around to
         * establishing additional references. We are usually the only one
-        * holding a reference to newpage at this point. We used to have a BUG
-        * here if trylock_page(newpage) fails, but would like to allow for
-        * cases where there might be a race with the previous use of newpage.
+        * holding a reference to dst at this point. We used to have a BUG
+        * here if folio_trylock(dst) fails, but would like to allow for
+        * cases where there might be a race with the previous use of dst.
         * This is much like races on refcount of oldpage: just don't BUG().
         */
-       if (unlikely(!trylock_page(newpage)))
+       if (unlikely(!folio_trylock(dst)))
                goto out_unlock;
 
        if (unlikely(!is_lru)) {
-               rc = move_to_new_folio(dst, folio, mode);
+               rc = move_to_new_folio(dst, src, mode);
                goto out_unlock_both;
        }
 
@@ -1083,7 +1081,7 @@ static int __unmap_and_move(struct page *page, struct page *newpage,
         * Corner case handling:
         * 1. When a new swap-cache page is read into, it is added to the LRU
         * and treated as swapcache but it has no rmap yet.
-        * Calling try_to_unmap() against a page->mapping==NULL page will
+        * Calling try_to_unmap() against a src->mapping==NULL page will
         * trigger a BUG.  So handle it here.
         * 2. An orphaned page (see truncate_cleanup_page) might have
         * fs-private metadata. The page can be picked up due to memory
@@ -1091,57 +1089,56 @@ static int __unmap_and_move(struct page *page, struct page *newpage,
         * invisible to the vm, so the page can not be migrated.  So try to
         * free the metadata, so the page can be freed.
         */
-       if (!page->mapping) {
-               VM_BUG_ON_PAGE(PageAnon(page), page);
-               if (page_has_private(page)) {
-                       try_to_free_buffers(folio);
+       if (!src->mapping) {
+               if (folio_test_private(src)) {
+                       try_to_free_buffers(src);
                        goto out_unlock_both;
                }
-       } else if (page_mapped(page)) {
+       } else if (folio_mapped(src)) {
                /* Establish migration ptes */
-               VM_BUG_ON_PAGE(PageAnon(page) && !PageKsm(page) && !anon_vma,
-                               page);
-               try_to_migrate(folio, 0);
+               VM_BUG_ON_FOLIO(folio_test_anon(src) &&
+                              !folio_test_ksm(src) && !anon_vma, src);
+               try_to_migrate(src, 0);
                page_was_mapped = true;
        }
 
-       if (!page_mapped(page))
-               rc = move_to_new_folio(dst, folio, mode);
+       if (!folio_mapped(src))
+               rc = move_to_new_folio(dst, src, mode);
 
        /*
-        * When successful, push newpage to LRU immediately: so that if it
+        * When successful, push dst to LRU immediately: so that if it
         * turns out to be an mlocked page, remove_migration_ptes() will
-        * automatically build up the correct newpage->mlock_count for it.
+        * automatically build up the correct dst->mlock_count for it.
         *
         * We would like to do something similar for the old page, when
         * unsuccessful, and other cases when a page has been temporarily
         * isolated from the unevictable LRU: but this case is the easiest.
         */
        if (rc == MIGRATEPAGE_SUCCESS) {
-               lru_cache_add(newpage);
+               folio_add_lru(dst);
                if (page_was_mapped)
                        lru_add_drain();
        }
 
        if (page_was_mapped)
-               remove_migration_ptes(folio,
-                       rc == MIGRATEPAGE_SUCCESS ? dst : folio, false);
+               remove_migration_ptes(src,
+                       rc == MIGRATEPAGE_SUCCESS ? dst : src, false);
 
 out_unlock_both:
-       unlock_page(newpage);
+       folio_unlock(dst);
 out_unlock:
        /* Drop an anon_vma reference if we took one */
        if (anon_vma)
                put_anon_vma(anon_vma);
-       unlock_page(page);
+       folio_unlock(src);
 out:
        /*
-        * If migration is successful, decrease refcount of the newpage,
+        * If migration is successful, decrease refcount of dst,
         * which will not free the page because new page owner increased
         * refcounter.
         */
        if (rc == MIGRATEPAGE_SUCCESS)
-               put_page(newpage);
+               folio_put(dst);
 
        return rc;
 }
@@ -1157,6 +1154,7 @@ static int unmap_and_move(new_page_t get_new_page,
                                   enum migrate_reason reason,
                                   struct list_head *ret)
 {
+       struct folio *dst, *src = page_folio(page);
        int rc = MIGRATEPAGE_SUCCESS;
        struct page *newpage = NULL;
 
@@ -1174,9 +1172,10 @@ static int unmap_and_move(new_page_t get_new_page,
        newpage = get_new_page(page, private);
        if (!newpage)
                return -ENOMEM;
+       dst = page_folio(newpage);
 
        newpage->private = 0;
-       rc = __unmap_and_move(page, newpage, force, mode);
+       rc = __unmap_and_move(src, dst, force, mode);
        if (rc == MIGRATEPAGE_SUCCESS)
                set_page_owner_migrate_reason(newpage, reason);
 
@@ -1264,7 +1263,7 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,
        if (!hugepage_migration_supported(page_hstate(hpage)))
                return -ENOSYS;
 
-       if (page_count(hpage) == 1) {
+       if (folio_ref_count(src) == 1) {
                /* page was freed from under us. So we are done. */
                putback_active_hugepage(hpage);
                return MIGRATEPAGE_SUCCESS;
@@ -1275,7 +1274,7 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,
                return -ENOMEM;
        dst = page_folio(new_hpage);
 
-       if (!trylock_page(hpage)) {
+       if (!folio_trylock(src)) {
                if (!force)
                        goto out;
                switch (mode) {
@@ -1285,29 +1284,29 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,
                default:
                        goto out;
                }
-               lock_page(hpage);
+               folio_lock(src);
        }
 
        /*
         * Check for pages which are in the process of being freed.  Without
-        * page_mapping() set, hugetlbfs specific move page routine will not
+        * folio_mapping() set, hugetlbfs specific move page routine will not
         * be called and we could leak usage counts for subpools.
         */
-       if (hugetlb_page_subpool(hpage) && !page_mapping(hpage)) {
+       if (hugetlb_page_subpool(hpage) && !folio_mapping(src)) {
                rc = -EBUSY;
                goto out_unlock;
        }
 
-       if (PageAnon(hpage))
-               anon_vma = page_get_anon_vma(hpage);
+       if (folio_test_anon(src))
+               anon_vma = folio_get_anon_vma(src);
 
-       if (unlikely(!trylock_page(new_hpage)))
+       if (unlikely(!folio_trylock(dst)))
                goto put_anon;
 
-       if (page_mapped(hpage)) {
+       if (folio_mapped(src)) {
                enum ttu_flags ttu = 0;
 
-               if (!PageAnon(hpage)) {
+               if (!folio_test_anon(src)) {
                        /*
                         * In shared mappings, try_to_unmap could potentially
                         * call huge_pmd_unshare.  Because of this, take
@@ -1328,7 +1327,7 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,
                        i_mmap_unlock_write(mapping);
        }
 
-       if (!page_mapped(hpage))
+       if (!folio_mapped(src))
                rc = move_to_new_folio(dst, src, mode);
 
        if (page_was_mapped)
@@ -1336,7 +1335,7 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,
                        rc == MIGRATEPAGE_SUCCESS ? dst : src, false);
 
 unlock_put_anon:
-       unlock_page(new_hpage);
+       folio_unlock(dst);
 
 put_anon:
        if (anon_vma)
@@ -1348,12 +1347,12 @@ put_anon:
        }
 
 out_unlock:
-       unlock_page(hpage);
+       folio_unlock(src);
 out:
        if (rc == MIGRATEPAGE_SUCCESS)
                putback_active_hugepage(hpage);
        else if (rc != -EAGAIN)
-               list_move_tail(&hpage->lru, ret);
+               list_move_tail(&src->lru, ret);
 
        /*
         * If migration was not successful and there's a freeing callback, use