lkml.org 
[lkml]   [2024]   [Feb]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 07/13] readahead: rework loop in page_cache_ra_unbounded()
    Date
    From: Hannes Reinecke <hare@suse.de>

    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 <hare@suse.de>
    Co-developed-by: Pankaj Raghav <p.raghav@samsung.com>
    Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
    Acked-by: Darrick J. Wong <djwong@kernel.org>
    ---
    mm/readahead.c | 13 +++++++------
    1 file changed, 7 insertions(+), 6 deletions(-)

    diff --git a/mm/readahead.c b/mm/readahead.c
    index 325a25e4ee3a..ef0004147952 100644
    --- a/mm/readahead.c
    +++ b/mm/readahead.c
    @@ -212,7 +212,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
    @@ -230,7 +230,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++) {
    + while (i < nr_to_read) {
    struct folio *folio = xa_load(&mapping->i_pages, index + i);

    if (folio && !xa_is_value(folio)) {
    @@ -243,8 +243,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;
    }

    @@ -256,13 +256,14 @@ void page_cache_ra_unbounded(struct readahead_control *ractl,
    folio_put(folio);
    read_pages(ractl);
    ractl->_index++;
    - i = ractl->_index + ractl->_nr_pages - index - 1;
    + 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);
    }

    /*
    --
    2.43.0

    \
     
     \ /
      Last update: 2024-05-27 15:21    [W:4.176 / U:0.056 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site