From 441cff700b8b6e2043211f2a06f2c21cc4a9884c Mon Sep 17 00:00:00 2001 From: BILL SHEN <15865969+cucbin@users.noreply.github.com> Date: Fri, 29 Aug 2025 01:57:06 +0800 Subject: [PATCH] feat: add `fileBacked` and `purgeable` fields to `process.getSystemMemoryInfo()` for macOS (#48146) feat: add fileBacked and purgeable fields to process.getSystemMemoryInfo() for macOS --- docs/api/process.md | 4 ++++ shell/common/api/electron_bindings.cc | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/api/process.md b/docs/api/process.md index 3c24d5db5798..91e42942fff4 100644 --- a/docs/api/process.md +++ b/docs/api/process.md @@ -211,6 +211,10 @@ Returns `Object`: system. * `free` Integer - The total amount of memory not being used by applications or disk cache. +* `fileBacked` Integer _macOS_ - The amount of memory that currently has been paged out to storage. + Includes memory for file caches, network buffers, and other system services. +* `purgeable` Integer _macOS_ - The amount of memory that is marked as "purgeable". The system can reclaim it + if memory pressure increases. * `swapTotal` Integer _Windows_ _Linux_ - The total amount of swap memory in Kilobytes available to the system. * `swapFree` Integer _Windows_ _Linux_ - The free amount of swap memory in Kilobytes available to the diff --git a/shell/common/api/electron_bindings.cc b/shell/common/api/electron_bindings.cc index e77be156bce9..b1015abff374 100644 --- a/shell/common/api/electron_bindings.cc +++ b/shell/common/api/electron_bindings.cc @@ -183,8 +183,11 @@ v8::Local ElectronBindings::GetSystemMemoryInfo( #endif dict.Set("free", free); +#if BUILDFLAG(IS_MAC) + dict.Set("fileBacked", mem_info.file_backed); + dict.Set("purgeable", mem_info.purgeable); +#else // NB: These return bogus values on macOS -#if !BUILDFLAG(IS_MAC) dict.Set("swapTotal", mem_info.swap_total); dict.Set("swapFree", mem_info.swap_free); #endif