Skip to content

Commit 16f8eb3

Browse files
mjkravetzakpm00
authored andcommitted
Revert "page cache: fix page_cache_next/prev_miss off by one"
This reverts commit 9425c59 The reverted commit fixed up routines primarily used by readahead code such that they could also be used by hugetlb. Unfortunately, this caused a performance regression as pointed out by the Closes: tag. The hugetlb code which uses page_cache_next_miss will be addressed in a subsequent patch. Link: https://lkml.kernel.org/r/20230621212403.174710-1-mike.kravetz@oracle.com Fixes: 9425c59 ("page cache: fix page_cache_next/prev_miss off by one") Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com> Reported-by: kernel test robot <oliver.sang@intel.com> Closes: https://lore.kernel.org/oe-lkp/202306211346.1e9ff03e-oliver.sang@intel.com Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com> Cc: Ackerley Tng <ackerleytng@google.com> Cc: Erdem Aktas <erdemaktas@google.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Matthew Wilcox <willy@infradead.org> Cc: Muchun Song <songmuchun@bytedance.com> Cc: Vishal Annapurve <vannapurve@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 1bc545b commit 16f8eb3

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

mm/filemap.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,9 +1728,7 @@ bool __folio_lock_or_retry(struct folio *folio, struct mm_struct *mm,
17281728
*
17291729
* Return: The index of the gap if found, otherwise an index outside the
17301730
* range specified (in which case 'return - index >= max_scan' will be true).
1731-
* In the rare case of index wrap-around, 0 will be returned. 0 will also
1732-
* be returned if index == 0 and there is a gap at the index. We can not
1733-
* wrap-around if passed index == 0.
1731+
* In the rare case of index wrap-around, 0 will be returned.
17341732
*/
17351733
pgoff_t page_cache_next_miss(struct address_space *mapping,
17361734
pgoff_t index, unsigned long max_scan)
@@ -1740,13 +1738,12 @@ pgoff_t page_cache_next_miss(struct address_space *mapping,
17401738
while (max_scan--) {
17411739
void *entry = xas_next(&xas);
17421740
if (!entry || xa_is_value(entry))
1743-
return xas.xa_index;
1744-
if (xas.xa_index == 0 && index != 0)
1745-
return xas.xa_index;
1741+
break;
1742+
if (xas.xa_index == 0)
1743+
break;
17461744
}
17471745

1748-
/* No gaps in range and no wrap-around, return index beyond range */
1749-
return xas.xa_index + 1;
1746+
return xas.xa_index;
17501747
}
17511748
EXPORT_SYMBOL(page_cache_next_miss);
17521749

@@ -1767,9 +1764,7 @@ EXPORT_SYMBOL(page_cache_next_miss);
17671764
*
17681765
* Return: The index of the gap if found, otherwise an index outside the
17691766
* range specified (in which case 'index - return >= max_scan' will be true).
1770-
* In the rare case of wrap-around, ULONG_MAX will be returned. ULONG_MAX
1771-
* will also be returned if index == ULONG_MAX and there is a gap at the
1772-
* index. We can not wrap-around if passed index == ULONG_MAX.
1767+
* In the rare case of wrap-around, ULONG_MAX will be returned.
17731768
*/
17741769
pgoff_t page_cache_prev_miss(struct address_space *mapping,
17751770
pgoff_t index, unsigned long max_scan)
@@ -1779,13 +1774,12 @@ pgoff_t page_cache_prev_miss(struct address_space *mapping,
17791774
while (max_scan--) {
17801775
void *entry = xas_prev(&xas);
17811776
if (!entry || xa_is_value(entry))
1782-
return xas.xa_index;
1783-
if (xas.xa_index == ULONG_MAX && index != ULONG_MAX)
1784-
return xas.xa_index;
1777+
break;
1778+
if (xas.xa_index == ULONG_MAX)
1779+
break;
17851780
}
17861781

1787-
/* No gaps in range and no wrap-around, return index beyond range */
1788-
return xas.xa_index - 1;
1782+
return xas.xa_index;
17891783
}
17901784
EXPORT_SYMBOL(page_cache_prev_miss);
17911785

0 commit comments

Comments
 (0)