From: Kairui Song This is similar to folio_next(). But to get the head of the previous folio, the compound info of the current folio isn't helpful. So here just retrieve the previous page frame's compound info instead. This creates a nice side effect that we don't require the current folio to be still valid as we don't need any info from it and @folio is never dereferenced, just pointer arithmetic. The caller has to ensure the previous folio is legal though, as there is no reliable way to tell from @folio whether one exists. Signed-off-by: Kairui Song --- include/linux/mm.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 77b5d450fe45..5b529bc6624f 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3076,6 +3076,29 @@ static inline struct folio *folio_next(struct folio *folio) return (struct folio *)folio_page(folio, folio_nr_pages(folio)); } +/** + * folio_prev - Move to the previous physical folio. + * @folio: The folio we're currently operating on. + * + * The inverse of folio_next(). Use it to move from one folio to the + * previous one in physically contiguous memory which may span more than + * one folio. Do not use it if the memory is only virtually contiguous. + * This is the folio equivalent to writing ``page--``. + * + * The caller has to ensure the previous folio is legal; there is no way + * to tell from @folio whether one exists. @folio itself is never + * dereferenced, only the page preceding it, so it may be a sentinel + * pointer instead of a folio. + * + * Context: We assume that the folios are refcounted and/or locked at a + * higher level and do not adjust the reference counts. + * Return: The previous struct folio. + */ +static inline struct folio *folio_prev(struct folio *folio) +{ + return page_folio(&folio->page - 1); +} + /** * folio_shift - The size of the memory described by this folio. * @folio: The folio. -- 2.56.1