From 56ed6510d95d65f80735b56bd8c86dc1216525cb Mon Sep 17 00:00:00 2001 From: Sultan Alsawaf Date: Wed, 19 Feb 2020 14:47:13 -0800 Subject: [PATCH] mm: Stop kswapd early when nothing's waiting for it to free pages Keeping kswapd running when all the failed allocations that invoked it are satisfied incurs a high overhead due to unnecessary page eviction and writeback, as well as spurious VM pressure events to various registered shrinkers. When kswapd doesn't need to work to make an allocation succeed anymore, stop it prematurely to save resources. Signed-off-by: Sultan Alsawaf --- include/linux/mmzone.h | 1 + mm/page_alloc.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index a6f1148085c2..c4dae0bcc43b 100755 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -664,6 +664,7 @@ typedef struct pglist_data { unsigned long node_spanned_pages; /* total size of physical page range, including holes */ int node_id; + atomic_t kswapd_waiters; wait_queue_head_t kswapd_wait; wait_queue_head_t pfmemalloc_wait; struct task_struct *kswapd; /* Protected by diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 51de840d394d..3d8cbb397f63 100755 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4089,6 +4089,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, u64 utime, stime_s, stime_e, stime_d; task_cputime(current, &utime, &stime_s); + pg_data_t *pgdat = ac->preferred_zoneref->zone->zone_pgdat; bool woke_kswapd = false; /* @@ -6336,6 +6337,7 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat) pgdat_page_ext_init(pgdat); spin_lock_init(&pgdat->lru_lock); lruvec_init(node_lruvec(pgdat)); + pgdat->kswapd_waiters = (atomic_t)ATOMIC_INIT(0); pgdat->per_cpu_nodestats = &boot_nodestats;