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

mm: Add folio_evictable()

This is the folio equivalent of page_evictable(). Unfortunately, it's
different from !folio_test_unevictable(), but I think it's used in places
where you have to be a VM expert and can reasonably be expected to know
the difference.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Vlastimil Babka <vbabka@suse.cz>

+19 -8
+19 -8
mm/internal.h
··· 72 72 pgoff_t end, struct pagevec *pvec, pgoff_t *indices); 73 73 74 74 /** 75 - * page_evictable - test whether a page is evictable 76 - * @page: the page to test 75 + * folio_evictable - Test whether a folio is evictable. 76 + * @folio: The folio to test. 77 77 * 78 - * Test whether page is evictable--i.e., should be placed on active/inactive 79 - * lists vs unevictable list. 78 + * Test whether @folio is evictable -- i.e., should be placed on 79 + * active/inactive lists vs unevictable list. 80 80 * 81 - * Reasons page might not be evictable: 82 - * (1) page's mapping marked unevictable 83 - * (2) page is part of an mlocked VMA 84 - * 81 + * Reasons folio might not be evictable: 82 + * 1. folio's mapping marked unevictable 83 + * 2. One of the pages in the folio is part of an mlocked VMA 85 84 */ 85 + static inline bool folio_evictable(struct folio *folio) 86 + { 87 + bool ret; 88 + 89 + /* Prevent address_space of inode and swap cache from being freed */ 90 + rcu_read_lock(); 91 + ret = !mapping_unevictable(folio_mapping(folio)) && 92 + !folio_test_mlocked(folio); 93 + rcu_read_unlock(); 94 + return ret; 95 + } 96 + 86 97 static inline bool page_evictable(struct page *page) 87 98 { 88 99 bool ret;