
From: Tang Yizhou <tangyizhou@huawei.com> ascend inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I4EUVI CVE: NA ------------------------------------------------- /proc/sys/vm/sharepool_perf_k2u allows us to track the time consuming of sp_k2u. Signed-off-by: Tang Yizhou <tangyizhou@huawei.com> Signed-off-by: Zhou Guanghui <zhouguanghui1@huawei.com> Reviewed-by: Weilong Chen <chenweilong@huawei.com> Reviewed-by: Ding Tianhong <dingtianhong@huawei.com> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> --- include/linux/share_pool.h | 2 ++ kernel/sysctl.c | 9 +++++++++ mm/share_pool.c | 37 +++++++++++++++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/include/linux/share_pool.h b/include/linux/share_pool.h index e118ac1cf15ca..2c71d7ded2cac 100644 --- a/include/linux/share_pool.h +++ b/include/linux/share_pool.h @@ -47,6 +47,8 @@ extern unsigned long sysctl_sp_compact_interval; extern unsigned long sysctl_sp_compact_interval_max; extern int sysctl_sp_perf_alloc; +extern int sysctl_sp_perf_k2u; + #ifdef CONFIG_HAVE_ARCH_HUGE_VMALLOC extern bool vmap_allow_huge; #endif diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 165d5ccd384f7..3d8c79986575a 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1816,6 +1816,15 @@ static struct ctl_table vm_table[] = { .extra1 = &zero, .extra2 = &ten_thousand, }, + { + .procname = "sharepool_perf_k2u", + .data = &sysctl_sp_perf_k2u, + .maxlen = sizeof(sysctl_sp_perf_k2u), + .mode = 0600, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &ten_thousand, + }, #endif { } }; diff --git a/mm/share_pool.c b/mm/share_pool.c index 824163e764e63..f3168eed3efc6 100644 --- a/mm/share_pool.c +++ b/mm/share_pool.c @@ -91,6 +91,8 @@ int sysctl_share_pool_map_lock_enable; int sysctl_sp_perf_alloc; +int sysctl_sp_perf_k2u; + static int share_pool_group_mode = SINGLE_GROUP_MODE; static int system_group_count; @@ -2581,8 +2583,36 @@ struct sp_k2u_context { unsigned long size_aligned; unsigned long sp_flags; int spg_id; + struct timespec64 start; + struct timespec64 end; }; +static void trace_sp_k2u_begin(struct sp_k2u_context *kc) +{ + if (!sysctl_sp_perf_k2u) + return; + + ktime_get_ts64(&kc->start); +} + +static void trace_sp_k2u_finish(struct sp_k2u_context *kc, void *uva, int to_task) +{ + unsigned long cost; + + if (!sysctl_sp_perf_k2u) + return; + + ktime_get_ts64(&kc->end); + + cost = SEC2US(kc->end.tv_sec - kc->start.tv_sec) + + NS2US(kc->end.tv_nsec - kc->start.tv_nsec); + if (cost >= (unsigned long)sysctl_sp_perf_k2u) { + pr_err("Task %s(%d/%d) sp_k2u returns 0x%lx consumes %luus, size is %luKB, size_aligned is %luKB, " + "sp_flags is %lx, to_task is %d\n", + current->comm, current->tgid, current->pid, + (unsigned long)uva, cost, byte2kb(kc->size), byte2kb(kc->size_aligned), kc->sp_flags, to_task); + } +} static int sp_k2u_prepare(unsigned long kva, unsigned long size, unsigned long sp_flags, int spg_id, struct sp_k2u_context *kc) { @@ -2590,6 +2620,8 @@ static int sp_k2u_prepare(unsigned long kva, unsigned long size, unsigned int page_size = PAGE_SIZE; unsigned long kva_aligned, size_aligned; + trace_sp_k2u_begin(kc); + if (sp_flags & ~SP_DVPP) { pr_err_ratelimited("k2u sp_flags %lx error\n", sp_flags); return -EINVAL; @@ -2629,13 +2661,14 @@ static int sp_k2u_prepare(unsigned long kva, unsigned long size, return 0; } -static void *sp_k2u_finish(void *uva, struct sp_k2u_context *kc) +static void *sp_k2u_finish(void *uva, int to_task, struct sp_k2u_context *kc) { if (IS_ERR(uva)) vmalloc_area_clr_flag(kc->kva_aligned, VM_SHAREPOOL); else uva = uva + (kc->kva - kc->kva_aligned); + trace_sp_k2u_finish(kc, uva, to_task); sp_dump_stack(); return uva; } @@ -2685,7 +2718,7 @@ void *sp_make_share_k2u(unsigned long kva, unsigned long size, } else uva = ERR_PTR(to_task); - return sp_k2u_finish(uva, &kc); + return sp_k2u_finish(uva, to_task, &kc); } EXPORT_SYMBOL_GPL(sp_make_share_k2u); -- 2.25.1