Commit 4fec80f
zram: defer zs_free() in swap slot free notification path
zram_slot_free_notify() is called on the process exit path when
unmapping swap entries. The slot_free() it calls internally invokes
zs_free(), which accounts for ~87% of slot_free() cost due to zsmalloc
internal locking (pool->lock, class->lock) and potential zspage freeing.
This blocks the process exit path, delaying overall memory release
during Android low-memory killing.
Split slot_free() into slot_free_extract() and the actual zs_free()
call. slot_free_extract() handles all slot metadata cleanup (clearing
flags, updating stats, zeroing handle/size) and returns the zsmalloc
handle that needs freeing. This separation has two benefits:
1. It makes the two responsibilities of slot_free() explicit: slot
metadata management (must be done under slot lock) vs zsmalloc
memory release (can be deferred).
2. It allows zram_slot_free_notify() to use zs_free_deferred() for
the handle, deferring the expensive zs_free() to a workqueue so
the exit path can release memory faster.
While at it, merge three separate clear_slot_flag() calls for
ZRAM_IDLE, ZRAM_INCOMPRESSIBLE, and ZRAM_PP_SLOT into a single
bitmask operation via clear_slot_flags_on_free(), reducing redundant
read-modify-write cycles on the same flags word.
All other slot_free() callers (write, discard, meta_free) continue
to use synchronous zs_free() through the unchanged slot_free()
wrapper.
Signed-off-by: Barry Song (Xiaomi) <[email protected]>
Signed-off-by: Wenchao Hao <[email protected]>1 parent 029543c commit 4fec80f
1 file changed
Lines changed: 28 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
168 | 177 | | |
169 | 178 | | |
170 | 179 | | |
| |||
2000 | 2009 | | |
2001 | 2010 | | |
2002 | 2011 | | |
2003 | | - | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
2004 | 2018 | | |
2005 | | - | |
| 2019 | + | |
2006 | 2020 | | |
2007 | 2021 | | |
2008 | 2022 | | |
2009 | 2023 | | |
2010 | 2024 | | |
2011 | | - | |
2012 | | - | |
2013 | | - | |
| 2025 | + | |
2014 | 2026 | | |
2015 | 2027 | | |
2016 | 2028 | | |
| |||
2041 | 2053 | | |
2042 | 2054 | | |
2043 | 2055 | | |
2044 | | - | |
2045 | | - | |
2046 | | - | |
| 2056 | + | |
2047 | 2057 | | |
2048 | 2058 | | |
2049 | 2059 | | |
2050 | 2060 | | |
2051 | 2061 | | |
2052 | 2062 | | |
2053 | 2063 | | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
2054 | 2073 | | |
2055 | 2074 | | |
2056 | 2075 | | |
| |||
2797 | 2816 | | |
2798 | 2817 | | |
2799 | 2818 | | |
2800 | | - | |
| 2819 | + | |
2801 | 2820 | | |
2802 | 2821 | | |
2803 | 2822 | | |
| |||
0 commit comments