diff --git a/dom/base/ChromeUtils.cpp b/dom/base/ChromeUtils.cpp index d412679e64c3..3e4a1fe0120f 100644 --- a/dom/base/ChromeUtils.cpp +++ b/dom/base/ChromeUtils.cpp @@ -1395,6 +1395,7 @@ static WebIDLProcType ProcTypeToWebIDL(mozilla::ProcType aType) { PROCTYPE_TO_WEBIDL_CASE(PrivilegedMozilla, Privilegedmozilla); PROCTYPE_TO_WEBIDL_CASE(WebCOOPCOEP, WithCoopCoep); PROCTYPE_TO_WEBIDL_CASE(WebServiceWorker, WebServiceWorker); + PROCTYPE_TO_WEBIDL_CASE(Inference, Inference); #define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, proc_typename, \ process_bin_type, procinfo_typename, \ @@ -1579,6 +1580,8 @@ already_AddRefed ChromeUtils::RequestProcInfo(GlobalObject& aGlobal, type = mozilla::ProcType::PrivilegedMozilla; } else if (remoteType == PREALLOC_REMOTE_TYPE) { type = mozilla::ProcType::Preallocated; + } else if (remoteType == INFERENCE_REMOTE_TYPE) { + type = mozilla::ProcType::Inference; } else if (StringBeginsWith(remoteType, DEFAULT_REMOTE_TYPE)) { type = mozilla::ProcType::Web; } else { diff --git a/dom/chrome-webidl/ChromeUtils.webidl b/dom/chrome-webidl/ChromeUtils.webidl index c0a4d900d48a..229e4e9de4c7 100644 --- a/dom/chrome-webidl/ChromeUtils.webidl +++ b/dom/chrome-webidl/ChromeUtils.webidl @@ -775,6 +775,7 @@ enum WebIDLProcType { "rdd", "socket", "remoteSandboxBroker", + "inference", #ifdef MOZ_ENABLE_FORKSERVER "forkServer", #endif diff --git a/dom/docs/ipc/process_model.rst b/dom/docs/ipc/process_model.rst index 2a6e17d4d861..72293a75ba6d 100644 --- a/dom/docs/ipc/process_model.rst +++ b/dom/docs/ipc/process_model.rst @@ -181,6 +181,18 @@ Shared Web Content The shared web content process is used to host content which is not isolated into one of the other web content process types. This includes almost all web content with Fission disabled, and web content which cannot be attributed to a specific origin with Fission enabled, such as user-initiated ``data:`` URI loads. + +Inference Content +""""""""""""""""" + +:remoteType: ``inference`` +:default count: 1 (``dom.ipc.processCount.inference``) + +The inference content process is used to isolate inference runtimes, currently ONNX runtime and Bergamot. This process hosts chrome workers that are running WASM runtimes along with some Javascript to perform inference tasks like translation or image-to-text. + +The models can allocate large amounts of memory, which can cause the process to be killed by the OS in memory-constrained environments like Android. This separation ensures other important processes like content processes are not killed. + + Isolated Web Content """""""""""""""""""" diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index db0e59eb7ba8..c445649d7093 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -2701,6 +2701,8 @@ mozilla::ipc::IPCResult ContentChild::RecvRemoteType( SetProcessName("Privileged Content"_ns, nullptr, &aProfile); } else if (aRemoteType == PRIVILEGEDMOZILLA_REMOTE_TYPE) { SetProcessName("Privileged Mozilla"_ns, nullptr, &aProfile); + } else if (aRemoteType == INFERENCE_REMOTE_TYPE) { + SetProcessName("Inference"_ns, nullptr, &aProfile); } else if (remoteTypePrefix == WITH_COOP_COEP_REMOTE_TYPE) { // The profiler can sanitize out the eTLD+1 nsDependentCSubstring etld = diff --git a/dom/ipc/RemoteType.h b/dom/ipc/RemoteType.h index 43183c7deeee..b3db8e937f1e 100644 --- a/dom/ipc/RemoteType.h +++ b/dom/ipc/RemoteType.h @@ -20,6 +20,7 @@ #define EXTENSION_REMOTE_TYPE "extension"_ns #define PRIVILEGEDABOUT_REMOTE_TYPE "privilegedabout"_ns #define PRIVILEGEDMOZILLA_REMOTE_TYPE "privilegedmozilla"_ns +#define INFERENCE_REMOTE_TYPE "inference"_ns #define DEFAULT_REMOTE_TYPE WEB_REMOTE_TYPE diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index bec8a72aed32..6afd5474836a 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -1985,6 +1985,9 @@ pref("dom.ipc.processCount.webIsolated", 1); pref("dom.ipc.processCount.webIsolated", 4); #endif +// For now we allow a single inference process +pref("dom.ipc.processCount.inference", 1); + // Keep a single privileged about process alive for performance reasons. // e.g. we do not want to throw content processes out every time we navigate // away from about:newtab. diff --git a/toolkit/components/aboutprocesses/content/aboutProcesses.js b/toolkit/components/aboutprocesses/content/aboutProcesses.js index 88159c84ea62..5e75cbe65b36 100644 --- a/toolkit/components/aboutprocesses/content/aboutProcesses.js +++ b/toolkit/components/aboutprocesses/content/aboutProcesses.js @@ -531,6 +531,9 @@ var View = { case "utility": fluentName = "about-processes-utility-process"; break; + case "inference": + fluentName = "about-processes-inference-process"; + break; // The following are probably not going to show up for users // but let's handle the case anyway to avoid heisenoranges // during tests in case of a leftover process from a previous diff --git a/toolkit/components/ml/content/EngineProcess.sys.mjs b/toolkit/components/ml/content/EngineProcess.sys.mjs index bb12d7b2847c..b2c12fefc4d3 100644 --- a/toolkit/components/ml/content/EngineProcess.sys.mjs +++ b/toolkit/components/ml/content/EngineProcess.sys.mjs @@ -282,7 +282,7 @@ export class EngineProcess { const browser = doc.createXULElement("browser"); browser.setAttribute("id", id); browser.setAttribute("remote", "true"); - browser.setAttribute("remoteType", "web"); + browser.setAttribute("remoteType", "inference"); browser.setAttribute("disableglobalhistory", "true"); browser.setAttribute("type", "content"); browser.setAttribute("src", url); diff --git a/toolkit/components/ml/tests/browser/browser_ml_engine.js b/toolkit/components/ml/tests/browser/browser_ml_engine.js index 8c75a181fe70..6e7052e6b560 100644 --- a/toolkit/components/ml/tests/browser/browser_ml_engine.js +++ b/toolkit/components/ml/tests/browser/browser_ml_engine.js @@ -38,6 +38,16 @@ async function setup({ disabled = false, prefs = [] } = {}) { const PIPELINE_OPTIONS = new PipelineOptions({ taskName: "moz-echo" }); +async function checkForRemoteType(remoteType) { + let procinfo3 = await ChromeUtils.requestProcInfo(); + for (const child of procinfo3.children) { + if (child.type === remoteType) { + return true; + } + } + return false; +} + add_task(async function test_ml_engine_basics() { const { cleanup, remoteClients } = await setup(); @@ -47,6 +57,9 @@ add_task(async function test_ml_engine_basics() { info("Get summarizer"); const summarizer = mlEngineParent.getEngine(PIPELINE_OPTIONS); + info("Check the inference process is running"); + Assert.equal(await checkForRemoteType("inference"), true); + info("Run the summarizer"); const inferencePromise = summarizer.run({ data: "This gets echoed." }); diff --git a/toolkit/components/processtools/ProcInfo.h b/toolkit/components/processtools/ProcInfo.h index 7fd2d7aae8be..8a118da710d2 100644 --- a/toolkit/components/processtools/ProcInfo.h +++ b/toolkit/components/processtools/ProcInfo.h @@ -47,6 +47,7 @@ enum class ProcType { PrivilegedMozilla, WebCOOPCOEP, WebServiceWorker, + Inference, // the rest matches GeckoProcessTypes.h #define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, proc_typename, \ process_bin_type, procinfo_typename, \ diff --git a/toolkit/locales/en-US/toolkit/about/aboutProcesses.ftl b/toolkit/locales/en-US/toolkit/about/aboutProcesses.ftl index d135de2e6c3c..a5e33c287202 100644 --- a/toolkit/locales/en-US/toolkit/about/aboutProcesses.ftl +++ b/toolkit/locales/en-US/toolkit/about/aboutProcesses.ftl @@ -52,6 +52,7 @@ about-processes-remote-sandbox-broker-process = Remote Sandbox Broker ({ $pid }) about-processes-fork-server-process = Fork Server ({ $pid }) about-processes-preallocated-process = Preallocated ({ $pid }) about-processes-utility-process = Utility ({ $pid }) +about-processes-inference-process = Inference ({ $pid }) # Unknown process names # Variables: diff --git a/toolkit/locales/en-US/toolkit/global/processTypes.ftl b/toolkit/locales/en-US/toolkit/global/processTypes.ftl index 05bfc1e94fe2..317d7d12d70d 100644 --- a/toolkit/locales/en-US/toolkit/global/processTypes.ftl +++ b/toolkit/locales/en-US/toolkit/global/processTypes.ftl @@ -52,6 +52,9 @@ process-type-socket = Socket # process used to decode media process-type-rdd = RDD +# process used to run inference +process-type-inference = Inference + # process used to run some IPC actor in their own sandbox process-type-utility = Sandboxed IPC Actor process-type-utility-actor-audio-decoder-generic = Utility Generic Audio Decoder diff --git a/toolkit/modules/ProcessType.sys.mjs b/toolkit/modules/ProcessType.sys.mjs index 4e1ef25552c7..25e46828a714 100644 --- a/toolkit/modules/ProcessType.sys.mjs +++ b/toolkit/modules/ProcessType.sys.mjs @@ -30,6 +30,7 @@ export const ProcessType = Object.freeze({ // Keys defined in dom/ipc/RemoteType.h extension: "process-type-extension", file: "process-type-file", + inference: "process-type-inference", prealloc: "process-type-prealloc", privilegedabout: "process-type-privilegedabout", privilegedmozilla: "process-type-privilegedmozilla",