Skip to content

Commit

Permalink
Revert "page cache: fix page_cache_next/prev_miss off by one"
Browse files Browse the repository at this point in the history
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/[email protected]
Fixes: 9425c59 ("page cache: fix page_cache_next/prev_miss off by one")
Signed-off-by: Mike Kravetz <[email protected]>
Reported-by: kernel test robot <[email protected]>
Closes: https://lore.kernel.org/oe-lkp/[email protected]
Reviewed-by: Sidhartha Kumar <[email protected]>
Cc: Ackerley Tng <[email protected]>
Cc: Erdem Aktas <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Muchun Song <[email protected]>
Cc: Vishal Annapurve <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
mjkravetz authored and akpm00 committed Jun 23, 2023
1 parent 1bc545b commit 16f8eb3
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions mm/filemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1728,9 +1728,7 @@ bool __folio_lock_or_retry(struct folio *folio, struct mm_struct *mm,
*
* Return: The index of the gap if found, otherwise an index outside the
* range specified (in which case 'return - index >= max_scan' will be true).
* In the rare case of index wrap-around, 0 will be returned. 0 will also
* be returned if index == 0 and there is a gap at the index. We can not
* wrap-around if passed index == 0.
* In the rare case of index wrap-around, 0 will be returned.
*/
pgoff_t page_cache_next_miss(struct address_space *mapping,
pgoff_t index, unsigned long max_scan)
Expand All @@ -1740,13 +1738,12 @@ pgoff_t page_cache_next_miss(struct address_space *mapping,
while (max_scan--) {
void *entry = xas_next(&xas);
if (!entry || xa_is_value(entry))
return xas.xa_index;
if (xas.xa_index == 0 && index != 0)
return xas.xa_index;
break;
if (xas.xa_index == 0)
break;
}

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

Expand All @@ -1767,9 +1764,7 @@ EXPORT_SYMBOL(page_cache_next_miss);
*
* Return: The index of the gap if found, otherwise an index outside the
* range specified (in which case 'index - return >= max_scan' will be true).
* In the rare case of wrap-around, ULONG_MAX will be returned. ULONG_MAX
* will also be returned if index == ULONG_MAX and there is a gap at the
* index. We can not wrap-around if passed index == ULONG_MAX.
* In the rare case of wrap-around, ULONG_MAX will be returned.
*/
pgoff_t page_cache_prev_miss(struct address_space *mapping,
pgoff_t index, unsigned long max_scan)
Expand All @@ -1779,13 +1774,12 @@ pgoff_t page_cache_prev_miss(struct address_space *mapping,
while (max_scan--) {
void *entry = xas_prev(&xas);
if (!entry || xa_is_value(entry))
return xas.xa_index;
if (xas.xa_index == ULONG_MAX && index != ULONG_MAX)
return xas.xa_index;
break;
if (xas.xa_index == ULONG_MAX)
break;
}

/* No gaps in range and no wrap-around, return index beyond range */
return xas.xa_index - 1;
return xas.xa_index;
}
EXPORT_SYMBOL(page_cache_prev_miss);

Expand Down

0 comments on commit 16f8eb3

Please sign in to comment.