Skip to content

feat: add fileBacked and purgeable fields to process.getSystemMemoryInfo() for macOS #47628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

cucbin
Copy link
Contributor

@cucbin cucbin commented Jul 1, 2025

Description of Change

On macOS, the free value in the memory data obtained from process.getSystemMemoryInfo() differs significantly from the value displayed in Activity Monitor.

The reason is that the free value is calculated from free_count in vm_statistics64_data_t.

The relevant code is located in: https://source.chromium.org/chromium/chromium/src/+/main:base/process/process_metrics_apple.mm;drc=bcbe20a25707502c2ba340cfd4dbe8cd015fa864;l=255

To handle this issue, I propose two approaches:

  • Calculate and return the adjusted value directly in electron_bindings.cc while maintaining the original data format.

  • Add two new fields: cached and purgeable, to provide more granular memory usage details.

Checklist

Release Notes

Notes: Added fileBacked and purgeable fields to process.getSystemMemoryInfo() for macOS.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Jul 1, 2025
Copy link
Member

@MarshallOfSound MarshallOfSound left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to expose new numbers, not change existing ones as people will have existing metrics that we'd be breaking.

Also cc @felixrieseberg because I know you've stared at how memory metrics work a lot in the past, any thoughts here

@cucbin cucbin changed the title fix: Optimize the value of memory.free in the return data of getSystemMemoryInfo() fix: Optimize the value of memory in the return data of getSystemMemoryInfo() Jul 2, 2025
@cucbin cucbin changed the title fix: Optimize the value of memory in the return data of getSystemMemoryInfo() fix: Improve the value of memory in the return data of getSystemMemoryInfo() Jul 2, 2025
@cucbin
Copy link
Contributor Author

cucbin commented Jul 2, 2025

@MarshallOfSound I agree with you. I have changed the code.
Thanks.

Copy link
Member

@nikwen nikwen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Could you please also adjust the docs?

### `process.getSystemMemoryInfo()`

Could you please also update the PR title and release notes to reflect your most recent change?

@nikwen nikwen changed the title fix: Improve the value of memory in the return data of getSystemMemoryInfo() fix: improve the value of memory in the return data of getSystemMemoryInfo() Jul 2, 2025
@cucbin
Copy link
Contributor Author

cucbin commented Jul 3, 2025

@nikwen
Thanks. Sure, I will complete the relevant API docs. Currently, I'm waiting to see the opinions of other members to determine whether additional data fields are needed or if these two fields are sufficient.

@nikwen nikwen changed the title fix: improve the value of memory in the return data of getSystemMemoryInfo() feat: improve the value of memory in the return data of getSystemMemoryInfo() Jul 3, 2025
@@ -183,8 +183,11 @@ v8::Local<v8::Value> ElectronBindings::GetSystemMemoryInfo(
#endif
dict.Set("free", free);

#if BUILDFLAG(IS_MAC)
dict.Set("cached", mem_info.file_backed);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be named fileBacked instead? I see another property named cached and want to make sure this won't conflict in the future.
https://source.chromium.org/chromium/chromium/src/+/main:base/process/process_metrics.h;l=365;drc=17b4c42cfb3512836655464b0d41d319e819c0b6

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this field name might be better, I have considered using this name before.
Originally I wanted to make the name of this field consistent with what is displayed in the Activity Monitor.

Copy link
Member

@itsananderson itsananderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple suggestions for tweaking the docs wording

@cucbin cucbin force-pushed the fix/correct_mem_free_value_in_get_system_mem_info branch from b28f1be to 37ef641 Compare July 4, 2025 16:24
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened recently label Jul 8, 2025
@cucbin
Copy link
Contributor Author

cucbin commented Jul 11, 2025

@codebytere
could you please also review the changes?

Copy link
Member

@codebytere codebytere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

Copy link
Member

@samuelmaddock samuelmaddock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

Copy link
Member

@nikwen nikwen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding docs! The code looks fine to me.

  1. Could you please update the release notes in the PR description?
  2. Could you please use a more descriptive title for the PR? This will be the commit message once the PR is merged.

@cucbin cucbin changed the title feat: improve the value of memory in the return data of getSystemMemoryInfo() feat: Added fileBacked and purgeable fields to getSystemMemoryInfo() for macOS. Jul 18, 2025
@cucbin cucbin changed the title feat: Added fileBacked and purgeable fields to getSystemMemoryInfo() for macOS. feat: Added fileBacked and purgeable fields to getSystemMemoryInfo() for macOS Jul 18, 2025
@cucbin cucbin requested a review from nikwen July 18, 2025 13:17
@cucbin
Copy link
Contributor Author

cucbin commented Jul 18, 2025

@nikwen
Thanks for your suggestion.

@cucbin cucbin changed the title feat: Added fileBacked and purgeable fields to getSystemMemoryInfo() for macOS feat: Added fileBacked and purgeable fields to process.getSystemMemoryInfo() for macOS Jul 18, 2025
@nikwen
Copy link
Member

nikwen commented Jul 18, 2025

Thanks for the changes!

Please take a look at the commit message guidelines. The "add" in the PR title should be present tense and lowercase.

Additionally, it's always great to wrap any function or field names in backticks to render them as code, e.g.,fileBacked. This applies to both the PR title and the release notes.

@codebytere codebytere changed the title feat: Added fileBacked and purgeable fields to process.getSystemMemoryInfo() for macOS feat: add fileBacked and purgeable fields to process.getSystemMemoryInfo() for macOS Jul 18, 2025
@codebytere codebytere changed the title feat: add fileBacked and purgeable fields to process.getSystemMemoryInfo() for macOS feat: add fileBacked and purgeable fields to process.getSystemMemoryInfo() for macOS Jul 18, 2025
@cucbin
Copy link
Contributor Author

cucbin commented Jul 18, 2025

Thanks.
After searching the historical commit records, I found that there were many cases where "Added" was used, so I decided to use "Added".
I will pay attention to these rules when submitting PR next time.

@nikwen
Copy link
Member

nikwen commented Jul 18, 2025

Thanks! We use present tense and lowercase for commit messages ("add"). We use past tense and capitalized for release notes ("Added").

Copy link
Member

@itsananderson itsananderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

@cucbin cucbin force-pushed the fix/correct_mem_free_value_in_get_system_mem_info branch from 37ef641 to 7e9faab Compare July 28, 2025 08:29
@cucbin
Copy link
Contributor Author

cucbin commented Jul 28, 2025

@codebytere
I rebase the code, please help me to trigger the check jobs. If it is all well, please help me merge it.
Thanks.

@codebytere codebytere added semver/minor backwards-compatible functionality target/37-x-y PR should also be added to the "37-x-y" branch. target/38-x-y PR should also be added to the "38-x-y" branch. labels Aug 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-review/approved ✅ semver/minor backwards-compatible functionality target/37-x-y PR should also be added to the "37-x-y" branch. target/38-x-y PR should also be added to the "38-x-y" branch.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy