KernelSU
KernelSU copied to clipboard
Avoid try_umount() overhead if overlay is unused
If module is not used, the task_fix_setuid hook can be avoided entirely, which goes through rather expensive ksu_is_allow_uid() and try_umount() and its strcmp().
Even if module is used, try_umount() within ksu_handle_setuid() can be used selectively by detecting which partitions are overlay'ed.
For example, if only /system is overlay'ed, try_umount("/vendor") and try_umount("/product") can be skipped.
This probably needs communication between ksud if we don't want to hook the mount system-call too.
I'm not sure which way is the optimal way, I hope this issue serves as a starting point to discuss it further.
We have a should_umount: https://github.com/tiann/KernelSU/blob/128e7e394ef8f3df1204eb3af87e6833c8380979/kernel/core_hook.c#L362, and this shouldn't change after post-fs-data, maybe we can cache this result and make an early return for try_umount?
if you cache the result instead of parsing mountpoint needed to unmount and KSU overlay is already unmounted by someone afterward, it might unmount stock one