From 55f8f63a4cfd028fed65c1e26df59dc56b581923 Mon Sep 17 00:00:00 2001 From: yipeng xiang Date: Tue, 21 Jan 2025 16:55:43 +0800 Subject: [PATCH] ANDROID: vendor_hooks: add hooks for f2fs issue checkpoint Add hooks to solve the priority inversion. while the key thread needs to update fs data, it should wake and wait for f2fs checkpoint thread to complete the work. So one scheme is needed to ensure the priority of checkpoint thread especially in CPU high load scenarios. Bug: 375088532 Change-Id: Iaa181cd1c8368310d9dd4c78adda6c7add5858b3 Signed-off-by: yipeng xiang --- drivers/android/vendor_hooks.c | 2 ++ fs/f2fs/checkpoint.c | 12 ++++++++++-- include/trace/hooks/fs.h | 8 ++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index dce2d7e95005..edd1dbe3ac34 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -113,6 +113,8 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_send_tm_command); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_check_int_errors); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_update_sdev); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_f2fs_down_read); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_f2fs_improve_priority); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_f2fs_restore_priority); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_io_statistics); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cgroup_attach); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_iommu_setup_dma_ops); diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 6b3113958f6b..2a241d039a5e 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -1903,10 +1903,18 @@ int f2fs_issue_checkpoint(struct f2fs_sb_info *sbi) if (waitqueue_active(&cprc->ckpt_wait_queue)) wake_up(&cprc->ckpt_wait_queue); - if (cprc->f2fs_issue_ckpt) + if (cprc->f2fs_issue_ckpt) { + bool prio_changed = false; + int saved_prio; + + trace_android_vh_f2fs_improve_priority(cprc->f2fs_issue_ckpt, &saved_prio, + &prio_changed); wait_for_completion(&req.wait); - else + if (prio_changed) + trace_android_vh_f2fs_restore_priority(cprc->f2fs_issue_ckpt, saved_prio); + } else { flush_remained_ckpt_reqs(sbi, &req); + } return req.ret; } diff --git a/include/trace/hooks/fs.h b/include/trace/hooks/fs.h index 93132d98c846..eff712e6a503 100644 --- a/include/trace/hooks/fs.h +++ b/include/trace/hooks/fs.h @@ -13,6 +13,14 @@ DECLARE_RESTRICTED_HOOK(android_rvh_f2fs_down_read, TP_PROTO(wait_queue_head_t *read_waiters, struct rw_semaphore *rwsem, bool *skip), TP_ARGS(read_waiters, rwsem, skip), 1); +DECLARE_HOOK(android_vh_f2fs_improve_priority, + TP_PROTO(struct task_struct *p, int *saved_prio, bool *skip), + TP_ARGS(p, saved_prio, skip)); + +DECLARE_HOOK(android_vh_f2fs_restore_priority, + TP_PROTO(struct task_struct *p, int saved_prio), + TP_ARGS(p, saved_prio)); + #endif /* _TRACE_HOOK_FS_H */ /* This part must be outside protection */