Skip to content

Show user-friendly memory size unit and accurate total physical available memory size - #554

Open
vjr wants to merge 12 commits into
mainfrom
vishal/memory-unit
Open

vjr wants to merge 12 commits into
mainfrom
vishal/memory-unit

Conversation

@vjr

@vjr vjr commented Sep 15, 2026

Copy link
Copy Markdown
Member

Observe the screenshots where before it would show eg. total memory as "125.4 GiB" and other memory size units in IEC format eg. "MiB" with the lowercase letter I.

This PR proposes a more user-friendly format to always show the units eg. "MB" or "GB" and if the size is an exact factor/power of 2 then exclude the decimal place eg. "128 GB" instead of "128.0 GB" otherwise show eg. "3.1 MB".

This is similar to elementary/settings-system#251 and elementary/settings-system#252 which can be considered prior art.

BEFORE:
memory-size-before

AFTER:
memory-size-after

vjr added 2 commits September 15, 2026 20:18
Set the IEC_UNITS flag separately for the value but refrain using it for the unit string.
Memory sizes unit strings are always shown without the lowercase letter I eg. "MB" or "GB" instead of "MiB" or "GiB".
Rationale for this commit is to not have your average user wonder what that lowercase letter I depicts.
Also update util memory size format function to:
 - show the full format with single decimal place eg. "3.1 MB" unless,
 - the size is an exact factor/power of 2 then show eg. "32 GB".

This is to show accurate total physical memory available eg. "32 GB" instead of previously showing "31.2 GiB" which libgtop would report.
@vjr vjr self-assigned this Sep 15, 2026
@vjr
vjr requested review from a team, danirabbit, ryonakano and stsdc September 15, 2026 16:10
Comment thread README.md Outdated
@vjr
vjr requested a review from ryonakano September 16, 2026 18:27
@ryonakano

Copy link
Copy Markdown
Member

Could you resolve the conflicts?

@vjr

vjr commented Sep 17, 2026

Copy link
Copy Markdown
Member Author

Could you resolve the conflicts?

@ryonakano done!

@ryonakano ryonakano left a comment

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.

I wonder whether you combined two changes into one PR; if so you should separate this PR into two.

Comment thread src/Resources/Memory.vala
Comment on lines -49 to +50
total = (double) (mem.total);
var total_physical_memory = get_total_physical_memory ();
total = (double) (total_physical_memory > 0 ? total_physical_memory : mem.total);

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.

Am I understand correctly that you used GUdev to get "accurate total physical available memory size"? Could you tell me the differences of values between GTop and GUdev?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

GUDev code gets you the actual installed physical memory size, meaning if your computer has 16 GiB it will get this exact number in bytes.

GTop on the other hand returns the "user accessible" memory size which is lower than what GUDev returns due to things like memory being reserved for kernel buffer cache, iGPU memory etc.

The switch from using GTop (still remains as fallback) to GUDev is shown in the before-after screenshots where you can see the "total memory" is lower with GTop used before.

Comment thread src/Utils.vala
);
}

public static string format_memory_size (uint64 size_in_bytes) {

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.

Could you leave some comments for what you're doing in this method?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will do.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@ryonakano added comments in efd0235 hope the wording makes for a sensible explanation?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's mainly to explain the fix in 81392c9

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Also see similar fix in #562

@vjr

vjr commented Sep 20, 2026

Copy link
Copy Markdown
Member Author

I wonder whether you combined two changes into one PR; if so you should separate this PR into two.

I feel these changes are closely related, it might just be a nitpick to separate them into two PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants