readahead: convert readahead_expand() to use a folio

Replace the uses of page with a folio.  Also add a missing test for
workingset in the leading edge expansion.

Link: https://lkml.kernel.org/r/20230116193941.2148487-4-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
Matthew Wilcox (Oracle) 2023-01-16 19:39:41 +00:00 коммит произвёл Andrew Morton
Родитель eff3b364b4
Коммит 11a9804207
1 изменённых файлов: 22 добавлений и 17 удалений

Просмотреть файл

@ -801,21 +801,25 @@ void readahead_expand(struct readahead_control *ractl,
/* Expand the leading edge downwards */ /* Expand the leading edge downwards */
while (ractl->_index > new_index) { while (ractl->_index > new_index) {
unsigned long index = ractl->_index - 1; unsigned long index = ractl->_index - 1;
struct page *page = xa_load(&mapping->i_pages, index); struct folio *folio = xa_load(&mapping->i_pages, index);
if (page && !xa_is_value(page)) if (folio && !xa_is_value(folio))
return; /* Page apparently present */ return; /* Folio apparently present */
page = __page_cache_alloc(gfp_mask); folio = filemap_alloc_folio(gfp_mask, 0);
if (!page) if (!folio)
return; return;
if (add_to_page_cache_lru(page, mapping, index, gfp_mask) < 0) { if (filemap_add_folio(mapping, folio, index, gfp_mask) < 0) {
put_page(page); folio_put(folio);
return; return;
} }
if (unlikely(folio_test_workingset(folio)) &&
!ractl->_workingset) {
ractl->_workingset = true;
psi_memstall_enter(&ractl->_pflags);
}
ractl->_nr_pages++; ractl->_nr_pages++;
ractl->_index = page->index; ractl->_index = folio->index;
} }
new_len += new_start - readahead_pos(ractl); new_len += new_start - readahead_pos(ractl);
@ -824,19 +828,20 @@ void readahead_expand(struct readahead_control *ractl,
/* Expand the trailing edge upwards */ /* Expand the trailing edge upwards */
while (ractl->_nr_pages < new_nr_pages) { while (ractl->_nr_pages < new_nr_pages) {
unsigned long index = ractl->_index + ractl->_nr_pages; unsigned long index = ractl->_index + ractl->_nr_pages;
struct page *page = xa_load(&mapping->i_pages, index); struct folio *folio = xa_load(&mapping->i_pages, index);
if (page && !xa_is_value(page)) if (folio && !xa_is_value(folio))
return; /* Page apparently present */ return; /* Folio apparently present */
page = __page_cache_alloc(gfp_mask); folio = filemap_alloc_folio(gfp_mask, 0);
if (!page) if (!folio)
return; return;
if (add_to_page_cache_lru(page, mapping, index, gfp_mask) < 0) { if (filemap_add_folio(mapping, folio, index, gfp_mask) < 0) {
put_page(page); folio_put(folio);
return; return;
} }
if (unlikely(PageWorkingset(page)) && !ractl->_workingset) { if (unlikely(folio_test_workingset(folio)) &&
!ractl->_workingset) {
ractl->_workingset = true; ractl->_workingset = true;
psi_memstall_enter(&ractl->_pflags); psi_memstall_enter(&ractl->_pflags);
} }