Commit e8a2c76e authored by Kefeng Wang's avatar Kefeng Wang Committed by Peng Zhang
Browse files

mm: swapfile: check usable swap device in __folio_throttle_swaprate()

maillist inclusion
category: performance
bugzilla: https://gitee.com/openeuler/kernel/issues/I9JAY9
CVE: NA

Reference: https://lore.kernel.org/linux-mm/20240418135644.2736748-1-wangkefeng.wang@huawei.com/

--------------------------------

Skip blk_cgroup_congested() if there is no usable swap device since no
swapin/out will occur, Thereby avoid taking swap_lock.  The difference is
shown 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

Link: https://lkml.kernel.org/r/20240418135644.2736748-1-wangkefeng.wang@huawei.com


Signed-off-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarZhangPeng <zhangpeng362@huawei.com>
parent 2b090d87
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -2465,13 +2465,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;
}
@@ -3728,6 +3732,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;