From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98140C04AAC for ; Thu, 21 Sep 2023 12:03:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D5BF06B0203; Thu, 21 Sep 2023 08:03:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D0C506B0204; Thu, 21 Sep 2023 08:03:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BFBB46B0205; Thu, 21 Sep 2023 08:03:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id AF4FA6B0203 for ; Thu, 21 Sep 2023 08:03:57 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6E7701C9D31 for ; Thu, 21 Sep 2023 12:03:57 +0000 (UTC) X-FDA: 81260470914.12.3B7721C Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.67.158]) by imf13.hostedemail.com (Postfix) with ESMTP id 5A37B20024 for ; Thu, 21 Sep 2023 12:03:53 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf13.hostedemail.com: domain of wangjiexun@tinylab.org designates 43.155.67.158 as permitted sender) smtp.mailfrom=wangjiexun@tinylab.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695297835; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=TIBinANgfw+CN3IopSuPAnPbjX/MnD5IAMt7LSGFqLo=; b=SpQHJVxzKv6qaZdrhPQoLNDmCfwP2u7380A8qa0EKqIxQNE9Yvaw4N2rtoyq8bE4qz9MrC sgO18syKdB1R4PzQ+7THIZR2eycckdsI9KWoicaQz+YRyTSRNZWfcxyoAqhwzi+/GEvWSG TlFb0+TtL1lephMYcoskjttmgf/IlMg= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf13.hostedemail.com: domain of wangjiexun@tinylab.org designates 43.155.67.158 as permitted sender) smtp.mailfrom=wangjiexun@tinylab.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695297835; a=rsa-sha256; cv=none; b=UkpaetFh3ODUR9D+jQWg4NV8jMUlFAPnICXfITkLxzZ8wFnbc0iOs6LkSkyO29yGmt8N8Z auRCT9RZsjxbBgHvmFPb/g2s/pCLJcVaKx63hzy6FQz2XDTu70unc/y2Iq0PqGZ+ewQxA9 bl+YA3Qy8neehJR9lzYU/j2PXGZ1kBg= X-QQ-mid: bizesmtp75t1695297763t71egsuy Received: from wangjiexun-virtual-machine.loca ( [183.230.12.240]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 21 Sep 2023 20:02:38 +0800 (CST) X-QQ-SSF: 01200000000000102000000A0000000 X-QQ-FEAT: W+onFc5Tw4MLZZME9/OMscKOmM8rYCETnaS/w2JrJcP7TPRq2pRy2OQpgnAcY 8aBiMCh8hqorrSr6eYZxD3smZGZPRWAgH41ULRK6+DymdWyqSTR+3wcxiinXgOQjX/mcf1a 7acOhRlimD71EfBrslFgeoF4aQJxn47QkPdL5IEZtFFnz6qfBlcUO/BIv46cx6qsT/Mj12H cOGmdwgFYQStNLwVdHENny23oFq9E0CQLm2OHZ7kAXYdiRPZvVDEBU3wdscHvMQIQmvSNqr yyQGP6JHvhW5OpIrZ7q0lwn7ggU3rt6HJ7FZ53cDhkRERjWuMo1HqoUbIcAMbQcHw5gX91B MlsvlZGk+qtGJ/Mv5sN2cIMbnHGpkrHrNmGeiHxLnC+3oFa/Afz5QP+XbgsXQ== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 4322735122809284590 From: Jiexun Wang To: akpm@linux-foundation.org, brauner@kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, falcon@tinylab.org, tangjinyu@tinylab.org, Jiexun Wang Subject: [PATCH v2 0/1] mm/madvise: add cond_resched() in madvise_cold_or_pageout_pte_range() Date: Thu, 21 Sep 2023 20:02:15 +0800 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-0 X-Rspamd-Queue-Id: 5A37B20024 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 8cmkenc1jsj7g3sg9ds89qft5hu7eqg6 X-HE-Tag: 1695297833-607523 X-HE-Meta: U2FsdGVkX19TvNLIY+0OVUdVXHvkK0tjoCho7GREBZbPuL8GhGoTLMDdPYSsX/OrvlMm3+W3Yzq0hdQRogkmWa3hAqGZUMxEJ/m6qKnApMk0spdxf9o7lmhZf/pPEQACT9fOrhlH3lhV9oCGbCtLct1+E/HOar+fBsPbyWUyPaPNC3Fepv/R1qzvdBgARGK1d8OVdbEUbRz2kADTnexCI+Cda0AYv4EuLEcIAowjXEjdHUhF6rqCajJSu2R24DYlPzjvIznfatxxImVF8V+3bnAeyxbcagkQ4hk17zDQ6GkbDLWEZ+xNWUPFQ0TXsmNOeQdobQ4FAQ3WElQP8i5EG+jciCuXHnTDvzNfQnjfbJTBP6Iza60Ucj2RjBmXXkcHh2R6/JhMGVW/IWgk8+n8OyhJQTl7vTcthHs1uTvuu2Q1jlxZofNujqt3JZUol+8odZGaWdIQb4zmFIO42wAibDA91kCQ7YzFkqmgo6ZYZI1rc3taPMUVN5+peLSgg9xtJWpsIFOiAfSfcMXkhr7Lv1cTf4H30Y0bVPwyVT4RUS/clksIjLJVF14k4BY/Htga9SowERQNghJ7HlgubJEjP0BJjezM5AOXJEfPQtIzFf7r/FZR346aboaUlnPDK5qA7Af9HNoynHHy0p5pa1vFSNnJkD6XM+3EWD9S+mk1l8Jru+e1JDMl262FQgec8zqZiOH84Dm1HFEW0FTjMS84HN8AiA/4jaLTcK4WEXyJi/UJRR1z2KJUFXMhXSXyVyg8MzAqu6PhoHCZLc3Ok16611c/13ZX44H8xNhsBfYW4wMvpHQcVzah87qVu8c7lVT60RKDeJH2iry7mNdz6uRm4mUEPMhUpLE2TmbeYIr0zPHIjA6VZt4T71Ai77lswjFwO1mQJu4ly6JKerKQOMBPS6HLLq3c8mZfJ5YyhKxQ7+Xvy5j8WpJUTdvxaNPMetW5IjlVX4hsowgehTSb9aV QoUp0O+m oqnQJMKKrj5cA1Jw7+5O5iMV6JNbuOz+SW6shn/fKEloaWxltMdt2vDnDKHKEivVKg6be438vzwDGsOg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: I conducted real-time testing and observed that madvise_cold_or_pageout_pte_range() causes significant latency under memory pressure, which can be effectively reduced by adding cond_resched() within the loop. I tested on the LicheePi 4A board using Cylictest for latency testing and Ftrace for latency tracing. The board uses TH1520 processor and has a memory size of 8GB. The kernel version is 6.5.0 with the PREEMPT_RT patch applied. The script I tested is as follows: echo wakeup_rt > /sys/kernel/tracing/current_tracer echo 1 > /sys/kernel/tracing/tracing_on echo 0 > /sys/kernel/tracing/tracing_max_latency stress-ng --vm 8 --vm-bytes 2G & cyclictest --mlockall --smp --priority=99 --distance=0 --duration=30m echo 0 > /sys/kernel/tracing/tracing_on cat /sys/kernel/tracing/trace The tracing results before modification are as follows: # tracer: wakeup_rt # # wakeup_rt latency trace v1.1.5 on 6.5.0-rt6-r1208-00003-g999d221864bf # -------------------------------------------------------------------- # latency: 2552 us, #6/6, CPU#3 | (M:preempt_rt VP:0, KP:0, SP:0 HP:0 #P:4) # ----------------- # | task: cyclictest-196 (uid:0 nice:0 policy:1 rt_prio:99) # ----------------- # # _--------=> CPU# # / _-------=> irqs-off/BH-disabled # | / _------=> need-resched # || / _-----=> need-resched-lazy # ||| / _----=> hardirq/softirq # |||| / _---=> preempt-depth # ||||| / _--=> preempt-lazy-depth # |||||| / _-=> migrate-disable # ||||||| / delay # cmd pid |||||||| time | caller # \ / |||||||| \ | / stress-n-206 3dn.h512 2us : 206:120:R + [003] 196: 0:R cyclictest stress-n-206 3dn.h512 7us : => __ftrace_trace_stack => __trace_stack => probe_wakeup => ttwu_do_activate => try_to_wake_up => wake_up_process => hrtimer_wakeup => __hrtimer_run_queues => hrtimer_interrupt => riscv_timer_interrupt => handle_percpu_devid_irq => generic_handle_domain_irq => riscv_intc_irq => handle_riscv_irq => do_irq stress-n-206 3dn.h512 9us#: 0 stress-n-206 3d...3.. 2544us : __schedule stress-n-206 3d...3.. 2545us : 206:120:R ==> [003] 196: 0:R cyclictest stress-n-206 3d...3.. 2551us : => __ftrace_trace_stack => __trace_stack => probe_wakeup_sched_switch => __schedule => preempt_schedule => migrate_enable => rt_spin_unlock => madvise_cold_or_pageout_pte_range => walk_pgd_range => __walk_page_range => walk_page_range => madvise_pageout => madvise_vma_behavior => do_madvise => sys_madvise => do_trap_ecall_u => ret_from_exception The tracing results after modification are as follows: # tracer: wakeup_rt # # wakeup_rt latency trace v1.1.5 on 6.5.0-rt6-r1208-00004-gca3876fc69a6-dirty # -------------------------------------------------------------------- # latency: 1689 us, #6/6, CPU#0 | (M:preempt_rt VP:0, KP:0, SP:0 HP:0 #P:4) # ----------------- # | task: cyclictest-217 (uid:0 nice:0 policy:1 rt_prio:99) # ----------------- # # _--------=> CPU# # / _-------=> irqs-off/BH-disabled # | / _------=> need-resched # || / _-----=> need-resched-lazy # ||| / _----=> hardirq/softirq # |||| / _---=> preempt-depth # ||||| / _--=> preempt-lazy-depth # |||||| / _-=> migrate-disable # ||||||| / delay # cmd pid |||||||| time | caller # \ / |||||||| \ | / stress-n-232 0dn.h413 1us+: 232:120:R + [000] 217: 0:R cyclictest stress-n-232 0dn.h413 12us : => __ftrace_trace_stack => __trace_stack => probe_wakeup => ttwu_do_activate => try_to_wake_up => wake_up_process => hrtimer_wakeup => __hrtimer_run_queues => hrtimer_interrupt => riscv_timer_interrupt => handle_percpu_devid_irq => generic_handle_domain_irq => riscv_intc_irq => handle_riscv_irq => do_irq stress-n-232 0dn.h413 19us#: 0 stress-n-232 0d...3.. 1671us : __schedule stress-n-232 0d...3.. 1676us+: 232:120:R ==> [000] 217: 0:R cyclictest stress-n-232 0d...3.. 1687us : => __ftrace_trace_stack => __trace_stack => probe_wakeup_sched_switch => __schedule => preempt_schedule => migrate_enable => free_unref_page_list => release_pages => free_pages_and_swap_cache => tlb_batch_pages_flush => tlb_flush_mmu => unmap_page_range => unmap_vmas => unmap_region => do_vmi_align_munmap.constprop.0 => do_vmi_munmap => __vm_munmap => sys_munmap => do_trap_ecall_u => ret_from_exception After the modification, the cause of maximum latency is no longer madvise_cold_or_pageout_pte_range(), so this modification can reduce the latency caused by madvise_cold_or_pageout_pte_range(). Changes in v2: - re-enter the loop after the cond_resched() method Jiexun Wang (1): mm/madvise: add cond_resched() in madvise_cold_or_pageout_pte_range() mm/madvise.c | 11 +++++++++++ 1 file changed, 11 insertions(+) -- 2.34.1