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