linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v0 0/2] mm: swap: Gather swap entries and batch async release
@ 2025-09-09  6:53 Lei Liu
  2025-09-09  6:53 ` [PATCH v0 1/2] mm: swap: Gather swap entries and batch async release core Lei Liu
                   ` (3 more replies)
  0 siblings, 4 replies; 26+ messages in thread
From: Lei Liu @ 2025-09-09  6:53 UTC (permalink / raw)
  To: Michal Hocko, David Rientjes, Shakeel Butt, Andrew Morton,
	Kemeng Shi, Kairui Song, Nhat Pham, Baoquan He, Barry Song,
	Chris Li, Johannes Weiner, Roman Gushchin, Muchun Song,
	David Hildenbrand, Lorenzo Stoakes, Liam R. Howlett,
	Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan,
	Brendan Jackman, Zi Yan, Peter Zijlstra (Intel),
	Chen Yu, Hao Jia, Kirill A. Shutemov, Usama Arif, Oleg Nesterov,
	Christian Brauner, Mateusz Guzik, Steven Rostedt,
	Andrii Nakryiko, Al Viro, Fushuai Wang,
	open list:MEMORY MANAGEMENT - OOM KILLER, open list,
	open list:CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG)
  Cc: Lei Liu

1. Problem Scenario
On systems with ZRAM and swap enabled, simultaneous process exits create
contention. The primary bottleneck occurs during swap entry release
operations, causing exiting processes to monopolize CPU resources. This
leads to scheduling delays for high-priority processes.

2. Android Use Case
During camera launch, LMKD terminates background processes to free memory.
Exiting processes compete for CPU cycles, delaying the camera preview
thread and causing visible stuttering - directly impacting user
experience.

3. Root Cause Analysis
When background applications heavily utilize swap space, process exit
profiling reveals 55% of time spent in free_swap_and_cache_nr():

Function              Duration (ms)   Percentage
do_signal               791.813     **********100%
do_group_exit           791.813     **********100%
do_exit                 791.813     **********100%
exit_mm                 577.859        *******73%
exit_mmap               577.497        *******73%
zap_pte_range           558.645        *******71%
free_swap_and_cache_nr  433.381          *****55%
free_swap_slot          403.568          *****51%
swap_entry_free         393.863          *****50%
swap_range_free         372.602           ****47%

4. Optimization Approach
a) For processes exceeding swap entry threshold: aggregate and isolate
swap entries to enable fast exit
b) Asynchronously release batched entries when isolation reaches
configured threshold

5. Performance Gains (User Scenario: Camera Cold Launch)
a) 74% reduction in process exit latency (>500ms cases)
b) ~4% lower peak CPU load during concurrent process exits
c) ~70MB additional free memory during camera preview initialization
d) 40% reduction in camera preview stuttering probability

6. Prior Art & Improvements
Reference: Zhiguo Jiang's patch
(https://lore.kernel.org/all/20240805153639.1057-1-justinjiang@vivo.com/)

Key enhancements:
a) Reimplemented logic moved from mmu_gather.c to swapfile.c for clarity
b) Async release delegated to workqueue kworkers with configurable
max_active for NUMA-optimized concurrency

Lei Liu (2):
  mm: swap: Gather swap entries and batch async release core
  mm: swap: Forced swap entries release under memory pressure

 include/linux/oom.h           |  23 ++++++
 include/linux/swapfile.h      |   2 +
 include/linux/vm_event_item.h |   1 +
 kernel/exit.c                 |   2 +
 mm/memcontrol.c               |   6 --
 mm/memory.c                   |   4 +-
 mm/page_alloc.c               |   4 +
 mm/swapfile.c                 | 134 ++++++++++++++++++++++++++++++++++
 mm/vmstat.c                   |   1 +
 9 files changed, 170 insertions(+), 7 deletions(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2025-10-14 20:42 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-09  6:53 [PATCH v0 0/2] mm: swap: Gather swap entries and batch async release Lei Liu
2025-09-09  6:53 ` [PATCH v0 1/2] mm: swap: Gather swap entries and batch async release core Lei Liu
2025-09-10  1:39   ` kernel test robot
2025-09-10  3:12   ` kernel test robot
2025-09-09  6:53 ` [PATCH v0 2/2] mm: swap: Forced swap entries release under memory pressure Lei Liu
2025-09-10  5:36   ` kernel test robot
2025-09-09  7:30 ` [PATCH v0 0/2] mm: swap: Gather swap entries and batch async release Kairui Song
2025-09-09  9:24   ` Barry Song
2025-09-09 16:15     ` Chris Li
2025-09-09 18:01       ` Chris Li
2025-09-10 14:07     ` Lei Liu
2025-10-14 20:42       ` Barry Song
2025-09-09 15:38   ` Chris Li
2025-09-10 14:01   ` Lei Liu
2025-09-09 19:21 ` Shakeel Butt
2025-09-09 19:48   ` Suren Baghdasaryan
2025-09-10 14:14     ` Lei Liu
2025-09-10 14:56       ` Suren Baghdasaryan
2025-09-10 16:05       ` Chris Li
2025-09-10 20:12       ` Shakeel Butt
2025-09-11  3:04         ` Lei Liu
2025-09-10 15:40     ` Chris Li
2025-09-10 20:10     ` Shakeel Butt
2025-09-10 20:41       ` Suren Baghdasaryan
2025-09-10 22:10         ` T.J. Mercier
2025-09-10 22:33           ` Shakeel Butt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox