Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm: add folio_flush_mapping()

This is the folio equivalent of page_mapping_file(), but rename it to make
it clear that it's very different from page_file_mapping().
Theoretically, there's nothing flush-only about it, but there are no other
users today, and I doubt there will be; it's almost always more useful to
know the swapfile's mapping or the swapcache's mapping.

Link: https://lkml.kernel.org/r/20230802151406.3735276-5-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Acked-by: Mike Rapoport (IBM) <rppt@kernel.org>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Matthew Wilcox (Oracle) and committed by
Andrew Morton
bc60abfb 3a255267

+21 -5
+21 -5
include/linux/pagemap.h
··· 389 389 return folio->mapping; 390 390 } 391 391 392 + /** 393 + * folio_flush_mapping - Find the file mapping this folio belongs to. 394 + * @folio: The folio. 395 + * 396 + * For folios which are in the page cache, return the mapping that this 397 + * page belongs to. Anonymous folios return NULL, even if they're in 398 + * the swap cache. Other kinds of folio also return NULL. 399 + * 400 + * This is ONLY used by architecture cache flushing code. If you aren't 401 + * writing cache flushing code, you want either folio_mapping() or 402 + * folio_file_mapping(). 403 + */ 404 + static inline struct address_space *folio_flush_mapping(struct folio *folio) 405 + { 406 + if (unlikely(folio_test_swapcache(folio))) 407 + return NULL; 408 + 409 + return folio_mapping(folio); 410 + } 411 + 392 412 static inline struct address_space *page_file_mapping(struct page *page) 393 413 { 394 414 return folio_file_mapping(page_folio(page)); ··· 419 399 */ 420 400 static inline struct address_space *page_mapping_file(struct page *page) 421 401 { 422 - struct folio *folio = page_folio(page); 423 - 424 - if (unlikely(folio_test_swapcache(folio))) 425 - return NULL; 426 - return folio_mapping(folio); 402 + return folio_flush_mapping(page_folio(page)); 427 403 } 428 404 429 405 /**