KernelSU icon indicating copy to clipboard operation
KernelSU copied to clipboard

Avoid try_umount() overhead if overlay is unused

Open arter97 opened this issue 2 years ago • 2 comments

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.

arter97 avatar May 27 '23 17:05 arter97

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?

tiann avatar May 29 '23 02:05 tiann

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

HuskyDG avatar May 29 '23 06:05 HuskyDG