Bug 1771712 - Make it more likely for child processes to be killed under OOM conditio...
commita203b827dbe7a70b863111582d6a804be2a3cef0
authorGabriele Svelto <gsvelto@mozilla.com>
Tue, 9 Aug 2022 16:05:48 +0000 (9 16:05 +0000)
committerGabriele Svelto <gsvelto@mozilla.com>
Tue, 9 Aug 2022 16:05:48 +0000 (9 16:05 +0000)
tree9dc5bbca55bd7bfd38f02e3beb306e9cf8e81db4
parent4811f2dce7ac9651a20a94f2f178e5b768c25b43
Bug 1771712 - Make it more likely for child processes to be killed under OOM conditions compared to the parent process on Linux r=jld

This patch implements hal::SetProcessPriority() on Linux and leverages
it to make it more likely that the parent process and foreground tab
survive an OOM situation, letting Linux' OOM killer reap preallocated
processes and background tabs first when reclaiming memory.

This is achieved by setting the `oom_score_adj` values of said processes
such that they will be killed in this order:

* Preallocated processes will be the first to go, they don't contain
  user data and are not visible, so they're a good candidate to free up
  memory
* Background tabs will be killed next, we don't generate crash reports
  for thoes nor do we inform the user, we just reload the tab, so in
  most cases one being killed will only be a small annoyance
* Background tabs playing video come next, but only if they're not also
  playing or recording audio
* Finally foreground tabs will be killed as a last resort, background
  tabs playing audio or with an active WebRTC session are also
  considered to be in the foreground as the user will immediately notice
  if they crash

Note that this patch only implements the low-level plumbing. The process
priority manager has not been enabled on Linux yet so that needs to
happen before this actually works.

Differential Revision: https://phabricator.services.mozilla.com/D153466
hal/linux/LinuxProcessPriority.cpp [new file with mode: 0644]
hal/moz.build