ANDROID: introduce a vendor hook to allow speculative swap pagefaults

Since SPF is an out-of-tree feature, the risks of changing its behavior
are higher. Add a vendor hook to enable speculative swap pagefaults. By
default it's disabled and should not cause troubles for current users.

Bug: 322762567
Change-Id: I3df7c545aa27d2707ee51ea42368f785c5faa735
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
This commit is contained in:
Suren Baghdasaryan
2024-02-08 14:19:04 -08:00
parent d47a714fa7
commit c9ca12bfd2
3 changed files with 12 additions and 3 deletions

View File

@@ -514,6 +514,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_err_handler);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_err_check_ctrl); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_err_check_ctrl);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_err_print_ctrl); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_err_print_ctrl);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_vmscan_kswapd_done); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_vmscan_kswapd_done);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_do_swap_page_spf);
/* /*
* For type visibility * For type visibility
*/ */

View File

@@ -362,6 +362,9 @@ DECLARE_HOOK(android_vh_madvise_cold_or_pageout_abort,
DECLARE_HOOK(android_vh_skip_swapcache, DECLARE_HOOK(android_vh_skip_swapcache,
TP_PROTO(swp_entry_t entry, bool *skip), TP_PROTO(swp_entry_t entry, bool *skip),
TP_ARGS(entry, skip)); TP_ARGS(entry, skip));
DECLARE_HOOK(android_vh_do_swap_page_spf,
TP_PROTO(bool *allow_swap_spf),
TP_ARGS(allow_swap_spf));
/* macro versions of hooks are no longer required */ /* macro versions of hooks are no longer required */
#endif /* _TRACE_HOOK_MM_H */ #endif /* _TRACE_HOOK_MM_H */

View File

@@ -3623,11 +3623,16 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
void *shadow = NULL; void *shadow = NULL;
if (vmf->flags & FAULT_FLAG_SPECULATIVE) { if (vmf->flags & FAULT_FLAG_SPECULATIVE) {
bool allow_swap_spf = false;
/* ksm_might_need_to_copy() needs a stable VMA, spf can't be used */ /* ksm_might_need_to_copy() needs a stable VMA, spf can't be used */
#ifdef CONFIG_KSM #ifndef CONFIG_KSM
trace_android_vh_do_swap_page_spf(&allow_swap_spf);
#endif
if (!allow_swap_spf) {
pte_unmap(vmf->pte); pte_unmap(vmf->pte);
return VM_FAULT_RETRY; return VM_FAULT_RETRY;
#endif }
} }
ret = pte_unmap_same(vmf); ret = pte_unmap_same(vmf);