| @@ -281,11 +281,11 @@ EXPORT_SYMBOL(delete_from_page_cache); · 280 unmodified lines |
| 281 | * @pvec: pagevec with pages to delete | 281 | * @pvec: pagevec with pages to delete |
| 282 | * | 282 | * |
| 283 | * The function walks over mapping->i_pages and removes pages passed in @pvec | 283 | * The function walks over mapping->i_pages and removes pages passed in @pvec |
| 284 | * from the mapping. The function expects @pvec to be sorted by page index. | 284 | * from the mapping. The function expects @pvec to be sorted by page index |
| | 285 | * and is optimised for it to be dense. |
| 285 | * It tolerates holes in @pvec (mapping entries at those indices are not | 286 | * It tolerates holes in @pvec (mapping entries at those indices are not |
| 286 | * modified). The function expects only THP head pages to be present in the | 287 | * modified). The function expects only THP head pages to be present in the |
| 287 | * @pvec and takes care to delete all corresponding tail pages from the | 288 | * @pvec. |
| 288 | * mapping as well. | | |
| 289 | * | 289 | * |
| 290 | * The function expects the i_pages lock to be held. | 290 | * The function expects the i_pages lock to be held. |
| 291 | */ | 291 | */ |
| @@ -294,40 +294,43 @@ static void page_cache_delete_batch(struct address_space *mapping, · 2 unmodified lines |
| 294 | { | 294 | { |
| 295 | XA_STATE(xas, &mapping->i_pages, pvec->pages[0]->index); | 295 | XA_STATE(xas, &mapping->i_pages, pvec->pages[0]->index); |
| 296 | int total_pages = 0; | 296 | int total_pages = 0; |
| 297 | int i = 0, tail_pages = 0; | 297 | int i = 0; |
| 298 | struct page *page; | 298 | struct page *page; |
| 299 | | 299 | |
| 300 | mapping_set_update(&xas, mapping); | 300 | mapping_set_update(&xas, mapping); |
| 301 | xas_for_each(&xas, page, ULONG_MAX) { | 301 | xas_for_each(&xas, page, ULONG_MAX) { |
| 302 | if (i >= pagevec_count(pvec) && !tail_pages) | 302 | if (i >= pagevec_count(pvec)) |
| 303 | break; | 303 | break; |
| | 304 | |
| | 305 | /* A swap/dax/shadow entry got inserted? Skip it. */ |
| 304 | if (xa_is_value(page)) | 306 | if (xa_is_value(page)) |
| 305 | continue; | 307 | continue; |
| 306 | if (!tail_pages) { | 308 | /* |
| 307 | /* | 309 | * A page got inserted in our range? Skip it. We have our |
| 308 | * Some page got inserted in our range? Skip it. We | 310 | * pages locked so they are protected from being removed. |
| 309 | * have our pages locked so they are protected from | 311 | * If we see a page whose index is higher than ours, it |
| 310 | * being removed. | 312 | * means our page has been removed, which shouldn't be |
| 311 | */ | 313 | * possible because we're holding the PageLock. |
| 312 | if (page != pvec->pages[i]) { | 314 | */ |
| 313 | VM_BUG_ON_PAGE(page->index > | 315 | if (page != pvec->pages[i]) { |
| 314 | pvec->pages[i]->index, page); | 316 | VM_BUG_ON_PAGE(page->index > pvec->pages[i]->index, |
| 315 | continue; | 317 | page); |
| 316 | } | 318 | continue; |
| 317 | WARN_ON_ONCE(!PageLocked(page)); | 319 | } |
| 318 | if (PageTransHuge(page) && !PageHuge(page)) | 320 | |
| 319 | tail_pages = HPAGE_PMD_NR - 1; | 321 | WARN_ON_ONCE(!PageLocked(page)); |
| | 322 | |
| | 323 | if (page->index == xas.xa_index) |
| 320 | page->mapping = NULL; | 324 | page->mapping = NULL; |
| 321 | /* | 325 | /* Leave page->index set: truncation lookup relies on it */ |
| 322 | * Leave page->index set: truncation lookup relies | 326 | |
| 323 | * upon it | 327 | /* |
| 324 | */ | 328 | * Move to the next page in the vector if this is a regular |
| | 329 | * page or the index is of the last sub-page of this compound |
| | 330 | * page. |
| | 331 | */ |
| | 332 | if (page->index + compound_nr(page) - 1 == xas.xa_index) |
| 325 | i++; | 333 | i++; |
| 326 | } else { | | |
| 327 | VM_BUG_ON_PAGE(page->index + HPAGE_PMD_NR - tail_pages | | |
| 328 | != pvec->pages[i]->index, page); | | |
| 329 | tail_pages--; | | |
| 330 | } | | |
| 331 | xas_store(&xas, NULL); | 334 | xas_store(&xas, NULL); |
| 332 | total_pages++; | 335 | total_pages++; |
| 333 | } | 336 | } |
| @@ -1520,7 +1523,7 @@ EXPORT_SYMBOL(page_cache_prev_miss); · 1186 unmodified lines |
| 1520 | struct page *find_get_entry(struct address_space *mapping, pgoff_t offset) | 1523 | struct page *find_get_entry(struct address_space *mapping, pgoff_t offset) |
| 1521 | { | 1524 | { |
| 1522 | XA_STATE(xas, &mapping->i_pages, offset); | 1525 | XA_STATE(xas, &mapping->i_pages, offset); |
| 1523 | struct page *head, *page; | 1526 | struct page *page; |
| 1524 | | 1527 | |
| 1525 | rcu_read_lock(); | 1528 | rcu_read_lock(); |
| 1526 | repeat: | 1529 | repeat: |
| @@ -1535,25 +1538,19 @@ repeat: · 8 unmodified lines |
| 1535 | if (!page || xa_is_value(page)) | 1538 | if (!page || xa_is_value(page)) |
| 1536 | goto out; | 1539 | goto out; |
| 1537 | | 1540 | |
| 1538 | head = compound_head(page); | 1541 | if (!page_cache_get_speculative(page)) |
| 1539 | if (!page_cache_get_speculative(head)) | | |
| 1540 | goto repeat; | | |
| 1541 | | | |
| 1542 | /* The page was split under us? */ | | |
| 1543 | if (compound_head(page) != head) { | | |
| 1544 | put_page(head); | | |
| 1545 | goto repeat; | 1542 | goto repeat; |
| 1546 | } | | |
| 1547 | | 1543 | |
| 1548 | /* | 1544 | /* |
| 1549 | * Has the page moved? | 1545 | * Has the page moved or been split? |
| 1550 | * This is part of the lockless pagecache protocol. See | 1546 | * This is part of the lockless pagecache protocol. See |
| 1551 | * include/linux/pagemap.h for details. | 1547 | * include/linux/pagemap.h for details. |
| 1552 | */ | 1548 | */ |
| 1553 | if (unlikely(page != xas_reload(&xas))) { | 1549 | if (unlikely(page != xas_reload(&xas))) { |
| 1554 | put_page(head); | 1550 | put_page(page); |
| 1555 | goto repeat; | 1551 | goto repeat; |
| 1556 | } | 1552 | } |
| | 1553 | page = find_subpage(page, offset); |
| 1557 | out: | 1554 | out: |
| 1558 | rcu_read_unlock(); | 1555 | rcu_read_unlock(); |
| 1559 | | 1556 | |
| @@ -1735,7 +1732,6 @@ unsigned find_get_entries(struct address_space *mapping, · 175 unmodified lines |
| 1735 | | 1732 | |
| 1736 | rcu_read_lock(); | 1733 | rcu_read_lock(); |
| 1737 | xas_for_each(&xas, page, ULONG_MAX) { | 1734 | xas_for_each(&xas, page, ULONG_MAX) { |
| 1738 | struct page *head; | | |
| 1739 | if (xas_retry(&xas, page)) | 1735 | if (xas_retry(&xas, page)) |
| 1740 | continue; | 1736 | continue; |
| 1741 | /* | 1737 | /* |
| @@ -1746,17 +1742,13 @@ unsigned find_get_entries(struct address_space *mapping, · 4 unmodified lines |
| 1746 | if (xa_is_value(page)) | 1742 | if (xa_is_value(page)) |
| 1747 | goto export; | 1743 | goto export; |
| 1748 | | 1744 | |
| 1749 | head = compound_head(page); | 1745 | if (!page_cache_get_speculative(page)) |
| 1750 | if (!page_cache_get_speculative(head)) | | |
| 1751 | goto retry; | 1746 | goto retry; |
| 1752 | | 1747 | |
| 1753 | /* The page was split under us? */ | 1748 | /* Has the page moved or been split? */ |
| 1754 | if (compound_head(page) != head) | | |
| 1755 | goto put_page; | | |
| 1756 | | | |
| 1757 | /* Has the page moved? */ | | |
| 1758 | if (unlikely(page != xas_reload(&xas))) | 1749 | if (unlikely(page != xas_reload(&xas))) |
| 1759 | goto put_page; | 1750 | goto put_page; |
| | 1751 | page = find_subpage(page, xas.xa_index); |
| 1760 | | 1752 | |
| 1761 | export: | 1753 | export: |
| 1762 | indices[ret] = xas.xa_index; | 1754 | indices[ret] = xas.xa_index; |
| @@ -1765,7 +1757,7 @@ export: · 2 unmodified lines |
| 1765 | break; | 1757 | break; |
| 1766 | continue; | 1758 | continue; |
| 1767 | put_page: | 1759 | put_page: |
| 1768 | put_page(head); | 1760 | put_page(page); |
| 1769 | retry: | 1761 | retry: |
| 1770 | xas_reset(&xas); | 1762 | xas_reset(&xas); |
| 1771 | } | 1763 | } |
| @@ -1807,33 +1799,27 @@ unsigned find_get_pages_range(struct address_space *mapping, pgoff_t *start, · 35 unmodified lines |
| 1807 | | 1799 | |
| 1808 | rcu_read_lock(); | 1800 | rcu_read_lock(); |
| 1809 | xas_for_each(&xas, page, end) { | 1801 | xas_for_each(&xas, page, end) { |
| 1810 | struct page *head; | | |
| 1811 | if (xas_retry(&xas, page)) | 1802 | if (xas_retry(&xas, page)) |
| 1812 | continue; | 1803 | continue; |
| 1813 | /* Skip over shadow, swap and DAX entries */ | 1804 | /* Skip over shadow, swap and DAX entries */ |
| 1814 | if (xa_is_value(page)) | 1805 | if (xa_is_value(page)) |
| 1815 | continue; | 1806 | continue; |
| 1816 | | 1807 | |
| 1817 | head = compound_head(page); | 1808 | if (!page_cache_get_speculative(page)) |
| 1818 | if (!page_cache_get_speculative(head)) | | |
| 1819 | goto retry; | 1809 | goto retry; |
| 1820 | | 1810 | |
| 1821 | /* The page was split under us? */ | 1811 | /* Has the page moved or been split? */ |
| 1822 | if (compound_head(page) != head) | | |
| 1823 | goto put_page; | | |
| 1824 | | | |
| 1825 | /* Has the page moved? */ | | |
| 1826 | if (unlikely(page != xas_reload(&xas))) | 1812 | if (unlikely(page != xas_reload(&xas))) |
| 1827 | goto put_page; | 1813 | goto put_page; |
| 1828 | | 1814 | |
| 1829 | pages[ret] = page; | 1815 | pages[ret] = find_subpage(page, xas.xa_index); |
| 1830 | if (++ret == nr_pages) { | 1816 | if (++ret == nr_pages) { |
| 1831 | *start = xas.xa_index + 1; | 1817 | *start = xas.xa_index + 1; |
| 1832 | goto out; | 1818 | goto out; |
| 1833 | } | 1819 | } |
| 1834 | continue; | 1820 | continue; |
| 1835 | put_page: | 1821 | put_page: |
| 1836 | put_page(head); | 1822 | put_page(page); |
| 1837 | retry: | 1823 | retry: |
| 1838 | xas_reset(&xas); | 1824 | xas_reset(&xas); |
| 1839 | } | 1825 | } |
| @@ -1878,7 +1864,6 @@ unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t index, · 38 unmodified lines |
| 1878 | | 1864 | |
| 1879 | rcu_read_lock(); | 1865 | rcu_read_lock(); |
| 1880 | for (page = xas_load(&xas); page; page = xas_next(&xas)) { | 1866 | for (page = xas_load(&xas); page; page = xas_next(&xas)) { |
| 1881 | struct page *head; | | |
| 1882 | if (xas_retry(&xas, page)) | 1867 | if (xas_retry(&xas, page)) |
| 1883 | continue; | 1868 | continue; |
| 1884 | /* | 1869 | /* |
| @@ -1888,24 +1873,19 @@ unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t index, · 3 unmodified lines |
| 1888 | if (xa_is_value(page)) | 1873 | if (xa_is_value(page)) |
| 1889 | break; | 1874 | break; |
| 1890 | | 1875 | |
| 1891 | head = compound_head(page); | 1876 | if (!page_cache_get_speculative(page)) |
| 1892 | if (!page_cache_get_speculative(head)) | | |
| 1893 | goto retry; | 1877 | goto retry; |
| 1894 | | 1878 | |
| 1895 | /* The page was split under us? */ | 1879 | /* Has the page moved or been split? */ |
| 1896 | if (compound_head(page) != head) | | |
| 1897 | goto put_page; | | |
| 1898 | | | |
| 1899 | /* Has the page moved? */ | | |
| 1900 | if (unlikely(page != xas_reload(&xas))) | 1880 | if (unlikely(page != xas_reload(&xas))) |
| 1901 | goto put_page; | 1881 | goto put_page; |
| 1902 | | 1882 | |
| 1903 | pages[ret] = page; | 1883 | pages[ret] = find_subpage(page, xas.xa_index); |
| 1904 | if (++ret == nr_pages) | 1884 | if (++ret == nr_pages) |
| 1905 | break; | 1885 | break; |
| 1906 | continue; | 1886 | continue; |
| 1907 | put_page: | 1887 | put_page: |
| 1908 | put_page(head); | 1888 | put_page(page); |
| 1909 | retry: | 1889 | retry: |
| 1910 | xas_reset(&xas); | 1890 | xas_reset(&xas); |
| 1911 | } | 1891 | } |
| @@ -1941,7 +1921,6 @@ unsigned find_get_pages_range_tag(struct address_space *mapping, pgoff_t *index, · 29 unmodified lines |
| 1941 | | 1921 | |
| 1942 | rcu_read_lock(); | 1922 | rcu_read_lock(); |
| 1943 | xas_for_each_marked(&xas, page, end, tag) { | 1923 | xas_for_each_marked(&xas, page, end, tag) { |
| 1944 | struct page *head; | | |
| 1945 | if (xas_retry(&xas, page)) | 1924 | if (xas_retry(&xas, page)) |
| 1946 | continue; | 1925 | continue; |
| 1947 | /* | 1926 | /* |
| @@ -1952,26 +1931,21 @@ unsigned find_get_pages_range_tag(struct address_space *mapping, pgoff_t *index, · 4 unmodified lines |
| 1952 | if (xa_is_value(page)) | 1931 | if (xa_is_value(page)) |
| 1953 | continue; | 1932 | continue; |
| 1954 | | 1933 | |
| 1955 | head = compound_head(page); | 1934 | if (!page_cache_get_speculative(page)) |
| 1956 | if (!page_cache_get_speculative(head)) | | |
| 1957 | goto retry; | 1935 | goto retry; |
| 1958 | | 1936 | |
| 1959 | /* The page was split under us? */ | 1937 | /* Has the page moved or been split? */ |
| 1960 | if (compound_head(page) != head) | | |
| 1961 | goto put_page; | | |
| 1962 | | | |
| 1963 | /* Has the page moved? */ | | |
| 1964 | if (unlikely(page != xas_reload(&xas))) | 1938 | if (unlikely(page != xas_reload(&xas))) |
| 1965 | goto put_page; | 1939 | goto put_page; |
| 1966 | | 1940 | |
| 1967 | pages[ret] = page; | 1941 | pages[ret] = find_subpage(page, xas.xa_index); |
| 1968 | if (++ret == nr_pages) { | 1942 | if (++ret == nr_pages) { |
| 1969 | *index = xas.xa_index + 1; | 1943 | *index = xas.xa_index + 1; |
| 1970 | goto out; | 1944 | goto out; |
| 1971 | } | 1945 | } |
| 1972 | continue; | 1946 | continue; |
| 1973 | put_page: | 1947 | put_page: |
| 1974 | put_page(head); | 1948 | put_page(page); |
| 1975 | retry: | 1949 | retry: |
| 1976 | xas_reset(&xas); | 1950 | xas_reset(&xas); |
| 1977 | } | 1951 | } |
| @@ -2652,7 +2626,7 @@ void filemap_map_pages(struct vm_fault *vmf, · 674 unmodified lines |
| 2652 | pgoff_t last_pgoff = start_pgoff; | 2626 | pgoff_t last_pgoff = start_pgoff; |
| 2653 | unsigned long max_idx; | 2627 | unsigned long max_idx; |
| 2654 | XA_STATE(xas, &mapping->i_pages, start_pgoff); | 2628 | XA_STATE(xas, &mapping->i_pages, start_pgoff); |
| 2655 | struct page *head, *page; | 2629 | struct page *page; |
| 2656 | | 2630 | |
| 2657 | rcu_read_lock(); | 2631 | rcu_read_lock(); |
| 2658 | xas_for_each(&xas, page, end_pgoff) { | 2632 | xas_for_each(&xas, page, end_pgoff) { |
| @@ -2661,24 +2635,19 @@ void filemap_map_pages(struct vm_fault *vmf, · 2 unmodified lines |
| 2661 | if (xa_is_value(page)) | 2635 | if (xa_is_value(page)) |
| 2662 | goto next; | 2636 | goto next; |
| 2663 | | 2637 | |
| 2664 | head = compound_head(page); | | |
| 2665 | | | |
| 2666 | /* | 2638 | /* |
| 2667 | * Check for a locked page first, as a speculative | 2639 | * Check for a locked page first, as a speculative |
| 2668 | * reference may adversely influence page migration. | 2640 | * reference may adversely influence page migration. |
| 2669 | */ | 2641 | */ |
| 2670 | if (PageLocked(head)) | 2642 | if (PageLocked(page)) |
| 2671 | goto next; | 2643 | goto next; |
| 2672 | if (!page_cache_get_speculative(head)) | 2644 | if (!page_cache_get_speculative(page)) |
| 2673 | goto next; | 2645 | goto next; |
| 2674 | | 2646 | |
| 2675 | /* The page was split under us? */ | 2647 | /* Has the page moved or been split? */ |
| 2676 | if (compound_head(page) != head) | | |
| 2677 | goto skip; | | |
| 2678 | | | |
| 2679 | /* Has the page moved? */ | | |
| 2680 | if (unlikely(page != xas_reload(&xas))) | 2648 | if (unlikely(page != xas_reload(&xas))) |
| 2681 | goto skip; | 2649 | goto skip; |
| | 2650 | page = find_subpage(page, xas.xa_index); |
| 2682 | | 2651 | |
| 2683 | if (!PageUptodate(page) || | 2652 | if (!PageUptodate(page) || |
| 2684 | PageReadahead(page) || | 2653 | PageReadahead(page) || |