Commit 7de56c05 authored by Liu Shixin's avatar Liu Shixin
Browse files

mm/readahead: don't decrease mmap_miss when folio has workingset flags

maillist inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I8EXN6

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=555ca2b8b9f71cbb08274649be5b65334049dcc8

--------------------------------

If there are too many folios that are recently evicted in a file, then
they will probably continue to be evicted.  In such situation, there is no
positive effect to read-ahead this file since it is only a waste of IO.

The mmap_miss is increased in do_sync_mmap_readahead() and decreased in
both do_async_mmap_readahead() and filemap_map_pages().  In order to skip
read-ahead in above scenario, the mmap_miss have to increased exceed
MMAP_LOTSAMISS.  This can be done by stop decreased mmap_miss when folio
has workingset flags.  The async path is not to care because in above
scenario, it's hard to run into the async path.

Link: https://lkml.kernel.org/r/20240322093555.226789-3-liushixin2@huawei.com


Signed-off-by: default avatarLiu Shixin <liushixin2@huawei.com>
Reviewed-by: default avatarJan Kara <jack@suse.cz>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jinjiang Tu <tujinjiang@huawei.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Conflicts:
	mm/filemap.c
Signed-off-by: default avatarLiu Shixin <liushixin2@huawei.com>
parent 947767f4
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -3168,7 +3168,14 @@ void filemap_map_pages(struct vm_fault *vmf,
		if (xas.xa_index >= max_idx)
			goto unlock;

		if (mmap_miss > 0)
		/*
		 * If there are too many pages that are recently evicted
		 * in a file, they will probably continue to be evicted.
		 * In such situation, read-ahead is only a waste of IO.
		 * Don't decrease mmap_miss in this scenario to make sure
		 * we can stop read-ahead.
		 */
		if (mmap_miss > 0 && !PageWorkingset(page))
			mmap_miss--;

		vmf->address += (xas.xa_index - last_pgoff) << PAGE_SHIFT;