diff --git a/mm/filemap.c b/mm/filemap.c index 4619ad47ea9b6c587d9a8004c268aa0a0558cb05..218130c6e46a45b02704baab58b2a5e8c8921bc1 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2434,6 +2434,13 @@ static int generic_file_buffered_read_get_pages(struct kiocb *iocb, goto find_page; } +static inline bool pos_same_page(loff_t pos1, loff_t pos2, struct page *page) +{ + unsigned int shift = page_shift(page); + + return (pos1 >> shift == pos2 >> shift); +} + /** * generic_file_buffered_read - generic file read routine * @iocb: the iocb to read @@ -2524,11 +2531,10 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb, writably_mapped = mapping_writably_mapped(mapping); /* - * When a sequential read accesses a page several times, only + * When a read accesses a page several times, only * mark it as accessed the first time. */ - if (iocb->ki_pos >> PAGE_SHIFT != - ra->prev_pos >> PAGE_SHIFT) + if (!pos_same_page(iocb->ki_pos, ra->prev_pos -1, pages[0])) mark_page_accessed(pages[0]); for (i = 1; i < pg_nr; i++) mark_page_accessed(pages[i]);