From bdab80c39d4da1d4d5c47706d85e8de7e3d2da10 Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Tue, 20 Jun 2023 08:49:31 +0200 Subject: [PATCH 04/18] mm/readahead: rework loop in page_cache_ra_unbounded() Rework the loop in page_cache_ra_unbounded() to advance with the number of pages in a folio instead of just one page at a time. Signed-off-by: Hannes Reinecke --- mm/readahead.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 47afbca1d122..1700603685d0 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -209,7 +209,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, struct address_space *mapping = ractl->mapping; unsigned long index = readahead_index(ractl); gfp_t gfp_mask = readahead_gfp_mask(mapping); - unsigned long i; + unsigned long i = 0; /* * Partway through the readahead operation, we will have added @@ -227,7 +227,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, /* * Preallocate as many pages as we will need. */ - for (i = 0; i < nr_to_read; i++) { + do { struct folio *folio = xa_load(&mapping->i_pages, index + i); if (folio && !xa_is_value(folio)) { @@ -240,8 +240,8 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, * not worth getting one just for that. */ read_pages(ractl); - ractl->_index++; - i = ractl->_index + ractl->_nr_pages - index - 1; + ractl->_index += folio_nr_pages(folio); + i = ractl->_index + ractl->_nr_pages - index; continue; } @@ -252,15 +252,16 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, gfp_mask) < 0) { folio_put(folio); read_pages(ractl); - ractl->_index++; - i = ractl->_index + ractl->_nr_pages - index - 1; + ractl->_index += folio_nr_pages(folio); + i = ractl->_index + ractl->_nr_pages - index; continue; } if (i == nr_to_read - lookahead_size) folio_set_readahead(folio); ractl->_workingset |= folio_test_workingset(folio); - ractl->_nr_pages++; - } + ractl->_nr_pages += folio_nr_pages(folio); + i += folio_nr_pages(folio); + } while (i < nr_to_read); /* * Now start the IO. We ignore I/O errors - if the folio is not -- 2.35.3