From 97e5f9c0f8993ab07e555ca0f978356c7ca86c74 Mon Sep 17 00:00:00 2001 From: Charan Teja Reddy Date: Mon, 31 May 2021 16:24:52 +0530 Subject: [PATCH] FROMLIST: mm: compaction: fix wakeup logic of proactive compaction Currently, proactive compaction tries to get triggered for every HPAGE_FRAG_CHECK_INTERVAL_MSEC(=500msec) even when proactive compaction is disabled with sysctl.compaction_proactiveness = 0. This results in kcompactd thread wakes up and goes to sleep for every 500msec with out the need of doing proactive compaction. Though this doesn't have any overhead, few cpu cycles can be saved by avoid of waking up kcompactd thread for proactive compaction when it is disabled. Bug: 186387247 Link: https://lore.kernel.org/patchwork/patch/1438213/ Signed-off-by: Charan Teja Reddy Change-Id: I7e32dc0eec628df7d88d554dd325acfc9ac1ae57 --- mm/compaction.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 8284fb8cb896..c1a02788282b 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2868,11 +2868,14 @@ static int kcompactd(void *p) while (!kthread_should_stop()) { unsigned long pflags; + long timeout; + timeout = sysctl_compaction_proactiveness ? + msecs_to_jiffies(HPAGE_FRAG_CHECK_INTERVAL_MSEC) : + MAX_SCHEDULE_TIMEOUT; trace_mm_compaction_kcompactd_sleep(pgdat->node_id); if (wait_event_freezable_timeout(pgdat->kcompactd_wait, - kcompactd_work_requested(pgdat), - msecs_to_jiffies(HPAGE_FRAG_CHECK_INTERVAL_MSEC)) && + kcompactd_work_requested(pgdat), timeout) && !pgdat->proactive_compact_trigger) { psi_memstall_enter(&pflags);