• Matthew Wilcox (Oracle)'s avatar
    mm/readahead: Fix readahead with large folios · b9ff43dd
    Matthew Wilcox (Oracle) authored
    Reading 100KB chunks from a big file (eg dd bs=100K) leads to poor
    readahead behaviour.  Studying the traces in detail, I noticed two
    problems.
    
    The first is that we were setting the readahead flag on the folio which
    contains the last byte read from the block.  This is wrong because we
    will trigger readahead at the end of the read without waiting to see
    if a subsequent read is going to use the pages we just read.  Instead,
    we need to set the readahead flag on the first folio _after_ the one
    which contains the last byte that we're reading.
    
    The second is that we were looking for the index of the folio with the
    readahead flag set to exactly match the start + size - async_size.
    If we've rounded this, either down (as previously) or up (as now),
    we'll think we hit a folio marked as readahead by a different read,
    and try to read the wrong pages.  So round the expected index to the
    order of the folio we hit.
    Reported-by: default avatarGuo Xuenan <guoxuenan@huawei.com>
    Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
    b9ff43dd
readahead.c 24.9 KB