Commit d8becc3
zram: support asynchronous GC for lazy slot freeing
Swap freeing can be expensive when unmapping a VMA containing
many swap entries. This has been reported to significantly
delay memory reclamation during Android’s low-memory killing,
especially when multiple processes are terminated to free
memory, with slot_free() accounting for more than 80% of
the total cost of freeing swap entries.
Two earlier attempts by Lei and Zhiguo added a new thread in the mm core
to asynchronously collect and free swap entries [1][2], but the
design itself is fairly complex.
When anon folios and swap entries are mixed within a
process, reclaiming anon folios from killed processes
helps return memory to the system as quickly as possible,
so that newly launched applications can satisfy their
memory demands. It is not ideal for swap freeing to block
anon folio freeing. On the other hand, swap freeing can
still return memory to the system, although at a slower
rate due to memory compression.
Therefore, in zram, we introduce a GC worker to allow anon
folio freeing and slot_free to run in parallel, since
slot_free is performed asynchronously, maximizing the rate at
which memory is returned to the system.
Xueyuan’s test on RK3588 shows that unmapping a 256MB swap-filled
VMA becomes 3.4× faster when pinning tasks to CPU2, reducing the
execution time from 63,102,982 ns to 18,570,726 ns.
A positive side effect is that async GC also slightly improves
do_swap_page() performance, as it no longer has to wait for
slot_free() to complete.
Xueyuan’s test shows that swapping in 256MB of data (each page
filled with repeating patterns such as “1024 one”, “1024 two”,
“1024 three”, and “1024 four”) reduces execution time from
1,358,133,886 ns to 1,104,315,986 ns, achieving a 1.22× speedup.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
Tested-by: Xueyuan Chen <[email protected]>
Signed-off-by: Barry Song (Xiaomi) <[email protected]>1 parent 857ada9 commit d8becc3
2 files changed
Lines changed: 58 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1958 | 1958 | | |
1959 | 1959 | | |
1960 | 1960 | | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
| 1964 | + | |
| 1965 | + | |
| 1966 | + | |
| 1967 | + | |
| 1968 | + | |
| 1969 | + | |
| 1970 | + | |
| 1971 | + | |
| 1972 | + | |
| 1973 | + | |
| 1974 | + | |
| 1975 | + | |
| 1976 | + | |
| 1977 | + | |
1961 | 1978 | | |
1962 | 1979 | | |
1963 | 1980 | | |
| |||
1966 | 1983 | | |
1967 | 1984 | | |
1968 | 1985 | | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
1969 | 1989 | | |
1970 | 1990 | | |
1971 | 1991 | | |
1972 | 1992 | | |
1973 | 1993 | | |
1974 | 1994 | | |
1975 | 1995 | | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
1976 | 2004 | | |
1977 | 2005 | | |
1978 | 2006 | | |
| |||
1991 | 2019 | | |
1992 | 2020 | | |
1993 | 2021 | | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
| 2027 | + | |
| 2028 | + | |
| 2029 | + | |
1994 | 2030 | | |
1995 | 2031 | | |
1996 | 2032 | | |
1997 | 2033 | | |
1998 | 2034 | | |
1999 | 2035 | | |
| 2036 | + | |
| 2037 | + | |
2000 | 2038 | | |
2001 | 2039 | | |
2002 | 2040 | | |
| |||
2008 | 2046 | | |
2009 | 2047 | | |
2010 | 2048 | | |
| 2049 | + | |
| 2050 | + | |
2011 | 2051 | | |
2012 | 2052 | | |
2013 | 2053 | | |
| |||
2784 | 2824 | | |
2785 | 2825 | | |
2786 | 2826 | | |
| 2827 | + | |
| 2828 | + | |
| 2829 | + | |
| 2830 | + | |
| 2831 | + | |
| 2832 | + | |
| 2833 | + | |
| 2834 | + | |
| 2835 | + | |
| 2836 | + | |
| 2837 | + | |
| 2838 | + | |
| 2839 | + | |
2787 | 2840 | | |
2788 | 2841 | | |
2789 | 2842 | | |
| |||
2797 | 2850 | | |
2798 | 2851 | | |
2799 | 2852 | | |
2800 | | - | |
| 2853 | + | |
| 2854 | + | |
2801 | 2855 | | |
2802 | 2856 | | |
2803 | 2857 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
| |||
142 | 143 | | |
143 | 144 | | |
144 | 145 | | |
| 146 | + | |
| 147 | + | |
145 | 148 | | |
146 | 149 | | |
0 commit comments