linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: swapfile: check usable swap device in __folio_throttle_swaprate()
@ 2024-04-18 13:56 Kefeng Wang
  0 siblings, 0 replies; only message in thread
From: Kefeng Wang @ 2024-04-18 13:56 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, Tejun Heo, Kefeng Wang

Skip blk_cgroup_congested() if no usable swap device since no swapin/out,
suppose that no thorottle when swapon/swapoff, so no swap_lock, difference
as shows below from perf date of CoW pagefault,

 perf report -g -i perf.data.swapoff  | egrep "blk_cgroup_congested|__folio_throttle_swaprate"
     1.01%     0.16%  page_fault2_pro  [kernel.kallsyms]      [k] __folio_throttle_swaprate
     0.83%     0.80%  page_fault2_pro  [kernel.kallsyms]      [k] blk_cgroup_congested

 perf report -g -i perf.data.swapon   | egrep "blk_cgroup_congested|__folio_throttle_swaprate"
     0.15%     0.15%  page_fault2_pro  [kernel.kallsyms]      [k] __folio_throttle_swaprate

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 mm/swapfile.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 28642c188c93..96606580ee09 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -2444,13 +2444,17 @@ static void reinsert_swap_info(struct swap_info_struct *p)
 	spin_unlock(&swap_lock);
 }
 
+static bool __has_usable_swap(void)
+{
+	return !plist_head_empty(&swap_active_head);
+}
+
 bool has_usable_swap(void)
 {
-	bool ret = true;
+	bool ret;
 
 	spin_lock(&swap_lock);
-	if (plist_head_empty(&swap_active_head))
-		ret = false;
+	ret = __has_usable_swap();
 	spin_unlock(&swap_lock);
 	return ret;
 }
@@ -3710,6 +3714,9 @@ void __folio_throttle_swaprate(struct folio *folio, gfp_t gfp)
 	if (!(gfp & __GFP_IO))
 		return;
 
+	if (!__has_usable_swap())
+		return;
+
 	if (!blk_cgroup_congested())
 		return;
 
-- 
2.27.0



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-18 13:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-18 13:56 [PATCH] mm: swapfile: check usable swap device in __folio_throttle_swaprate() Kefeng Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).