Skip to content

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

Merged
codebytere merged 6 commits intoelectron:mainfrom
cucbin:fix/correct_mem_free_value_in_get_system_mem_info
Aug 20, 2025
Merged

feat: add fileBacked and purgeable fields to process.getSystemMemoryInfo() for macOS#47628
codebytere merged 6 commits intoelectron:mainfrom
cucbin:fix/correct_mem_free_value_in_get_system_mem_info

Conversation

@cucbin
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

cucbin commented Jul 2, 2025

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

Copy link
Copy Markdown
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
Copy Markdown
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
dict.Set("free", free);

#if BUILDFLAG(IS_MAC)
dict.Set("cached", mem_info.file_backed);
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

cucbin commented Jul 11, 2025

@codebytere
could you please also review the changes?

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@cucbin cucbin force-pushed the fix/correct_mem_free_value_in_get_system_mem_info branch from b68f43c to e0327c1 Compare August 19, 2025 06:32
@cucbin
Copy link
Copy Markdown
Contributor Author

cucbin commented Aug 19, 2025

Hi @codebytere
I have rebased the code with latest code. Could you please help to speed up the PR's progress?
Thanks.

@codebytere codebytere merged commit 83a5ba1 into electron:main Aug 20, 2025
52 of 54 checks passed
@release-clerk
Copy link
Copy Markdown

release-clerk bot commented Aug 20, 2025

Release Notes Persisted

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

@trop
Copy link
Copy Markdown
Contributor

trop bot commented Aug 20, 2025

I was unable to backport this PR to "38-x-y" cleanly;
you will need to perform this backport manually.

@trop trop bot removed the target/38-x-y PR should also be added to the "38-x-y" branch. label Aug 20, 2025
@trop
Copy link
Copy Markdown
Contributor

trop bot commented Aug 20, 2025

I was unable to backport this PR to "37-x-y" cleanly;
you will need to perform this backport manually.

@trop
Copy link
Copy Markdown
Contributor

trop bot commented Aug 21, 2025

@cucbin has manually backported this PR to "37-x-y", please check out #48143

@trop
Copy link
Copy Markdown
Contributor

trop bot commented Aug 21, 2025

@cucbin has manually backported this PR to "38-x-y", please check out #48146

@trop trop bot added merged/37-x-y PR was merged to the "37-x-y" branch. merged/38-x-y PR was merged to the "38-x-y" branch. and removed in-flight/37-x-y in-flight/38-x-y labels Aug 28, 2025
kigh-ota pushed a commit to kigh-ota/electron that referenced this pull request Sep 30, 2025
…moryInfo()` for macOS (electron#47628)

* fix: Optimize the value of memory.free in the return data of getSystemMemoryInfo().

* fix: Improve the value of memory in the return data of getSystemMemoryInfo().

* fix: complete API doc.

* Update docs/api/process.md

Co-authored-by: Will Anderson <will@itsananderson.com>

* fix: update name to fileBacked.

* fix: fix with code conflict

---------

Co-authored-by: Will Anderson <will@itsananderson.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-review/approved ✅ merged/37-x-y PR was merged to the "37-x-y" branch. merged/38-x-y PR was merged to the "38-x-y" branch. semver/minor backwards-compatible functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants