linux-stable/mm/damon
Barry Song 2864f3d0f5 mm: madvise: pageout: ignore references rather than clearing young
While doing MADV_PAGEOUT, the current code will clear PTE young so that
vmscan won't read young flags to allow the reclamation of madvised folios
to go ahead.  It seems we can do it by directly ignoring references, thus
we can remove tlb flush in madvise and rmap overhead in vmscan.

Regarding the side effect, in the original code, if a parallel thread runs
side by side to access the madvised memory with the thread doing madvise,
folios will get a chance to be re-activated by vmscan (though the time gap
is actually quite small since checking PTEs is done immediately after
clearing PTEs young).  But with this patch, they will still be reclaimed. 
But this behaviour doing PAGEOUT and doing access at the same time is
quite silly like DoS.  So probably, we don't need to care.  Or ignoring
the new access during the quite small time gap is even better.

For DAMON's DAMOS_PAGEOUT based on physical address region, we still keep
its behaviour as is since a physical address might be mapped by multiple
processes.  MADV_PAGEOUT based on virtual address is actually much more
aggressive on reclamation.  To untouch paddr's DAMOS_PAGEOUT, we simply
pass ignore_references as false in reclaim_pages().

A microbench as below has shown 6% decrement on the latency of
MADV_PAGEOUT,

 #define PGSIZE 4096
 main()
 {
 	int i;
 #define SIZE 512*1024*1024
 	volatile long *p = mmap(NULL, SIZE, PROT_READ | PROT_WRITE,
 			MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

 	for (i = 0; i < SIZE/sizeof(long); i += PGSIZE / sizeof(long))
 		p[i] =  0x11;

 	madvise(p, SIZE, MADV_PAGEOUT);
 }

w/o patch                    w/ patch
root@10:~# time ./a.out      root@10:~# time ./a.out
real	0m49.634s            real   0m46.334s
user	0m0.637s             user   0m0.648s
sys	0m47.434s            sys    0m44.265s

Link: https://lkml.kernel.org/r/20240226005739.24350-1-21cnbao@gmail.com
Signed-off-by: Barry Song <v-songbaohua@oppo.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Cc: SeongJae Park <sj@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-03-04 17:01:18 -08:00
..
Kconfig mm/damon: rename CONFIG_DAMON_DBGFS to DAMON_DBGFS_DEPRECATED 2024-02-22 10:24:45 -08:00
Makefile mm/damon/modules: deduplicate init steps for DAMON context setup 2022-11-30 15:01:26 -08:00
core-test.h mm/damon/core-test: test max_nr_accesses overflow caused divide-by-zero 2023-12-20 14:48:13 -08:00
core.c mm/damon/core: implement PSI metric DAMOS quota goal 2024-02-23 17:48:28 -08:00
dbgfs-test.h mm/damon: update email of SeongJae 2023-12-20 14:48:13 -08:00
dbgfs.c mm/damon/dbgfs: rename monitor_on file to monitor_on_DEPRECATED 2024-02-22 10:24:46 -08:00
lru_sort.c mm/damon/lru_sort: fix quota status loss due to online tunings 2024-02-20 14:20:50 -08:00
modules-common.c mm/damon: update email of SeongJae 2023-12-20 14:48:13 -08:00
modules-common.h mm/damon/modules: deduplicate init steps for DAMON context setup 2022-11-30 15:01:26 -08:00
ops-common.c mm/damon/ops-common: avoid divide-by-zero during region hotness calculation 2023-10-25 16:47:15 -07:00
ops-common.h mm/damon/ops-common: atomically test and clear young on ptes and pmds 2023-06-09 16:25:55 -07:00
paddr.c mm: madvise: pageout: ignore references rather than clearing young 2024-03-04 17:01:18 -08:00
reclaim.c mm/damon/reclaim: implement memory PSI-driven quota self-tuning 2024-02-23 17:48:30 -08:00
sysfs-common.c mm/damon/sysfs: make kobj_type structures constant 2023-02-09 16:51:45 -08:00
sysfs-common.h mm/damon/sysfs: use only quota->goals 2024-02-23 17:48:27 -08:00
sysfs-schemes.c mm/damon/sysfs-schemes: support PSI-based quota auto-tune 2024-02-23 17:48:29 -08:00
sysfs-test.h mm/damon/sysfs-test: add a unit test for damon_sysfs_set_targets() 2023-10-25 16:47:15 -07:00
sysfs.c mm/damon/sysfs: use only quota->goals 2024-02-23 17:48:27 -08:00
vaddr-test.h mm/damon: update email of SeongJae 2023-12-20 14:48:13 -08:00
vaddr.c mm/damon/vaddr: change asm-generic/mman-common.h to linux/mman.h 2023-12-29 11:58:57 -08:00