How Android LMK Daemon Works on Chrome?

151 views
Skip to first unread message

Hao Liu

unread,
Dec 14, 2022, 10:11:07 AM12/14/22
to Chromium-dev
Hi,
I'm looking into what if the browser is killed by the Android LMK daemon. I know very little about Android, but my understanding is, 

Android LMK daemon just kills a process. It's not a proper shutdown. 
1, If that's a browser process, I suppose renderer processes would all be gone as well. 
2, If that's a renderer process, I imagine there would be some clean up, like, destroying the PageLoadTracker and other corresponding things in the browser process. 

I found some places that may be relevant like RenderFrameHostImpl::RenderProcessGone. but didn't find exactly where or how. 

Does someone know about this?
Thanks! 

Ian Clelland

unread,
Jan 3, 2023, 2:01:19 PM1/3/23
to hao...@chromium.org, Chromium-dev, Yaron Friedman
I'm not sure if this is still relevant, but for future solution seekers who come across this, if nothing else:

The low-memory killer is now a userspace daemon which runs as a background process on Android. The source code is available here: https://cs.android.com/android/platform/superproject/+/master:system/memory/lmkd/

Looking through that code, all attempts to kill processes eventually end up in reaper.cpp, and will (either synchronously or asynchronously) call pidfd_send_signal to send a KILL signal to the process. It doesn't do anything fancier than that to kill the process; the KILL signal should be sufficient.

If the browser process is killed, then all child processes (renderers, GPU process, everything) will be killed by the OS as well, and there's nothing we can do about it. If a renderer is killed, then I believe that the browser will become aware of this the next time any IPC is attempted, and either Mojo or Chrome IPC will notify the browser of that, through something like OnChannelError -> ProcessDied -> RenderProcessExited-> RenderProcessGone (the method you mentioned above).

For testing this, it should be sufficient to send the same sigkill to the renderer process, without needing to exhaust memory and hope that the lmkd daemon picks the right process to kill. (For testing a whole-browser-got-killed scenario, I'm not sure if there's any way. https://crbug.com/138855 has been open for 10+ years now. yfriedman@ may know more about the state of browser death tests on Android.) 

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/615b5856-3b86-48d5-8e22-d8c497a4e63bn%40chromium.org.

Hao Liu

unread,
Jan 4, 2023, 11:10:56 AM1/4/23
to Chromium-dev, Ian Clelland, Chromium-dev, Yaron Friedman, Hao Liu
Thanks for explaining!

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+unsubscribe@chromium.org.
Reply all
Reply to author
Forward
0 new messages