Skip to content

Add configurable SI decimal vs IEC binary unit prefixes - #1970

Open
tenox7 wants to merge 1 commit into
htop-dev:mainfrom
tenox7:units
Open

tenox7 wants to merge 1 commit into
htop-dev:mainfrom
tenox7:units

Conversation

@tenox7

@tenox7 tenox7 commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

when displaying network or disk io meters allow to choose whether to use IEC or SI unit prefixes

@Explorer09

Explorer09 commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

Why do we need this feature? Also I have concerns about how the feature is implemented:

  1. If we want to provide a configurable unit display (even for just the toggle between binary and deciml units), it should either affect globally, or allow a per-meter and per-table-column configuration. Limiting the setting to affect only DiskIO and NetworkIO meters doesn't make sense.
  2. For the fixed units like KiB/s, what to do if the number displayed is very large that it overflows the displayable space? No safeguards against that.
  3. What to do if the set of units is to be expanded? Say, TiB, PiB, EiB?

@fasterit

Copy link
Copy Markdown
Member

Nobody requested such a feature, what is the rationale @tenox7 ?

@tenox7
tenox7 force-pushed the units branch 3 times, most recently from 73563ea to 5698430 Compare April 23, 2026 04:13
@tenox7

tenox7 commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Why do we need this feature? Also I have concerns about how the feature is implemented:

I humbly believe that display of a transfer rate / bandwidth usage should be in SI decimal units (power of 10) and not IEC units (power of 2). In my personal use case output of htop network speed doesn't align with network equipment bandwidth usage measurement. Or for that matter with iostat for disk. Of course this is somewhat controversial. Rater than forcing some arbitrary standard users at least deserve choice. Hence configurable parameter.

  1. If we want to provide a configurable unit display (even for just the toggle between binary and deciml units), it should either affect globally, or allow a per-meter and per-table-column configuration. Limiting the setting to affect only DiskIO and NetworkIO meters doesn't make sense.

Absolutely agree, however I did not see any other place where transfer rate is being displayed. Saying that I found and updated per process table rate. So this should be global now?

  1. For the fixed units like KiB/s, what to do if the number displayed is very large that it overflows the displayable space? No safeguards against that.

Are you referring to visual misalignment? I think this is user choice. If someone wants to display something in small units, large numbers and misalignment are expected. Most people sticks with auto. Forcing specific unit like MB/s is rather rare and specific.

  1. What to do if the set of units is to be expanded? Say, TiB, PiB, EiB?

Good question! I don't think these are achievable on a single machine at this time outside of L1/L2 cache speed. I have added TB/s and TiB/s for future use.

@Explorer09

Explorer09 commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor

Until there's a clarification on the requirements I don't think it worth it for you to revise the patches.

I humbly believe that display of a transfer rate / bandwidth usage should be in SI decimal units (power of 10) and not IEC units (power of 2). In my personal use case output of htop network speed doesn't align with network equipment bandwidth usage measurement. Of course this is somewhat controversial. Rater than forcing some arbitrary standard users at least deserve choice. Hence configurable parameter.

I have no personal objections on the SI vs. IEC unit switch. My concern is on the other part of the requirements that's either unclear or not worth it.

  1. If we want to provide a configurable unit display (even for just the toggle between binary and deciml units), it should either affect globally, or allow a per-meter and per-table-column configuration. Limiting the setting to affect only DiskIO and NetworkIO meters doesn't make sense.

Absolutely agree, however I did not see any other place where transfer rate is being displayed. Saying that I found and updated per process table rate. So this should be global now?

Grep the two keywords: Row_printRate and Row_printKBytes. The calls of these two utility functions are where the base-2 and base-10 unit switch are useful.

  1. For the fixed units like KiB/s, what to do if the number displayed is very large that it overflows the displayable space? No safeguards against that.

Are you referring to visual misalignment? I think this is user choice. If someone wants to display something in small units, large numbers and misalignment are expected. Most people sticks with auto. Forcing specific unit like MB/s is rather rare and specific.

Meter_humanUnit intentionally constrains the number of characters displayed to 5 (including the K, M, G or T prefix itself). If a decimal point is present, only a maximum of 3 digits can be printed. The reason was simply that extra digits of precision don't seem worth it.

I have added TB/s and TiB/s for future use.

My suggestion was to remove the fixed unit options altogether, and leave only the IEC and SI unit options. That would simplify the UI.

Because look at this:

5698430#diff-07aa5e06e3d4142e8e68a7c8ad5cc2da7a4843241640263649a7e24409d94792R317

   Panel_add(super, (Object*) NumberItem_newByRef("IO rate unit (0-auto IEC 1-auto SI 2-KiB/s 3-MiB/s 4-GiB/s 5-TiB/s 6-KB/s 7-MB/s 8-GB/s 9-TB/s)", &(settings->ioRateUnit), 0, 0, LAST_IO_UNIT - 1));

It can be expected in the future that there would be 10-PiB/s, 11-PB/s, etc. as a natural extensions of these. I would rather not have such a potential for scope creep. As you mentioned very few people would use these fixed units. Just ditch them. The original Meter_humanUnit code can work with units up to QiB (quebibytes) thanks to the unitPrefixes array and a loop that flexibly convert the numbers.

@fasterit

Copy link
Copy Markdown
Member

I think a IEC / SI switch could be acceptable, probably best to make an issue to discuss this first. I know this topic is a bit controversial among IT engineers.

I think the bulk of the PR does not stand a chance of getting merged.
It adds a lot of complexity for taking the auto-scaling feature (which is probably more useful the most of our users) away.

@fasterit

Copy link
Copy Markdown
Member

Prior art: #1187 and #224

@Explorer09

Copy link
Copy Markdown
Contributor

FYI, btop does have the SI / IEC unit switch.

@tenox7
tenox7 force-pushed the units branch 2 times, most recently from 5599d33 to 49acbd5 Compare April 23, 2026 13:18
@tenox7

tenox7 commented Apr 23, 2026

Copy link
Copy Markdown
Contributor Author

I have no personal objections on the SI vs. IEC unit switch. My concern is on the other part of the requirements that's either unclear or not worth it.

I have removed the non-auto sizing.

Grep the two keywords: Row_printRate and Row_printKBytes. The calls of these two utility functions are where the base-2 and base-10 unit switch are useful.

Okay I think this is addressed now.

My suggestion was to remove the fixed unit options altogether, and leave only the IEC and SI unit options. That would simplify the UI.

Done! I have no problem with that. My only requirement is to have SI / IEC unit choice in order to align with other tools.

@tenox7

tenox7 commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor Author

I think a IEC / SI switch could be acceptable, probably best to make an issue to discuss this first.

Awesome. This is really all thats needed.

I know this topic is a bit controversial among IT engineers.

Actually I don't think it's controversial among IT engineers. Whats controversial is how this whole IEC units came to light and how it was adopted in software. Making it configurable addresses the issue.

I think the bulk of the PR does not stand a chance of getting merged. It adds a lot of complexity for taking the auto-scaling feature (which is probably more useful the most of our users) away.

Removed the non-auto scaled path.

@tenox7
tenox7 force-pushed the units branch 3 times, most recently from 39324dd to 82fb340 Compare April 23, 2026 14:07
@tenox7 tenox7 changed the title support for configurable units for network/disk io Add configurable SI decimal vs IEC binary unit prefixes Apr 23, 2026
Comment thread Row.h Resolved
@BenBE

BenBE commented Apr 25, 2026

Copy link
Copy Markdown
Member

Just a note on organizing the enum: To be future-proof the most elegant solution would be to encode the LSb as IEC vs. SI, and use the other bits to denote the power to use, where 0 is "auto" and everything else is one step of the unit ladder.

But that aside, I see little benefit in this overall feature except to confuse people (for which it would work great). Historically we chose to use IEC throughout due to (visual) space constraints where we could not reliably tell the unit to the user otherwise. And given htop is resource monitor for telling you about memory consumption it makes most sense to use the IEC units as a basis.. This even holds when talking about transfer rates from and to disks, as the OS operates on sectors (IEC-based) and cache pages (also IEC-based). The only place where this historically broke down somewhat is with network related metrics as these use SI units mostly.

@Explorer09

Copy link
Copy Markdown
Contributor

Historically we chose to use IEC throughout due to (visual) space constraints where we could not reliably tell the unit to the user otherwise. And given htop is resource monitor for telling you about memory consumption it makes most sense to use the IEC units as a basis.. This even holds when talking about transfer rates from and to disks, as the OS operates on sectors (IEC-based) and cache pages (also IEC-based). The only place where this historically broke down somewhat is with network related metrics as these use SI units mostly.

I agree that the IEC units should remain the default as the main thing htop users would want to monitor is the memory usage.

For hard disks and SSDs, despite the fact that sector sizes are usually engineered to be a power of two, disk sizes are instead marketed in base-10 units. (A 1 TB SSD is 1000 GB of space, not 1024 GiB.) Fortunately monitoring hard disks is not the primary use case of htop, thus the unit problem affects only a niche group of people. Just for your information.

@tenox7

tenox7 commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor Author

It is a niche group of people, but the problem is that having only IEC units is sometimes incompatible with other monitoring tools, for example iostat even on latest Ubuntu or FreeBSD, or network monitoring software.

I would like to have option to switch to SI units to compare or correlate results from htop with network monitoring software which as @BenBE mentioned uses SI units, or iostat and related.

Perhaps instead of menu configurable option we can add flag --units or something like that?

@tenox7

tenox7 commented May 18, 2026

Copy link
Copy Markdown
Contributor Author

So what would take to merge this PR? Does anything need to be changed?

@Explorer09

Copy link
Copy Markdown
Contributor

For me, the only question remains is whether we need to special case the memory KiB units (this comment). I have no other objections.

@coderabbitai

coderabbitai Bot commented May 25, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review
Walkthrough

Adds Settings.decimalUnits, with a default value of false, configuration read/write support, and a display-options checkbox. Adds Meter_ioRateUnit(...) for SI and IEC bytes-per-second formatting. Extends Row_printRate with a decimal flag. Updates disk and network meters and Linux and PCP process displays to use the configured unit system.

Suggested reviewers: benbe, explorer09, fasterit, natoscott

Change: Feature

Merge Risk: Low · up to df0db

Small I/O rates in decimal mode can display as zero or be rounded up. The other previously flagged concerns (config parsing, history migration, pinned title width) remain open but are minor. The change is mergeable with owner awareness.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

SI or IEC, rates now align,
Settings select the scale by design,
Meters show each unit clear,
Rows render values without fear,
Read and write follow the chosen sign.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5a9972ce-0472-4b07-81a8-cedfe13dc8a5

📥 Commits

Reviewing files that changed from the base of the PR and between 1579d02 and f9d0cdc.

📒 Files selected for processing (12)
  • DiskIOMeter.c
  • DisplayOptionsPanel.c
  • Meter.c
  • Meter.h
  • NetworkIOMeter.c
  • Row.c
  • Row.h
  • Settings.c
  • Settings.h
  • linux/LinuxProcess.c
  • pcp/PCPDynamicColumn.c
  • pcp/PCPProcess.c

Comment thread Meter.c Resolved
Comment thread Row.c Resolved
Comment thread Row.c Resolved
@tenox7

tenox7 commented May 30, 2026

Copy link
Copy Markdown
Contributor Author

Is there anything outstanding on this PR? Can I get an approval? Thanks!

@BenBE

BenBE commented May 31, 2026

Copy link
Copy Markdown
Member

@tenox7 This PR has not been forgotten. Just had little time the past days and also there's internally still an open question. Of the two commits I'm inclined to merge at least the first one (might even happen out-of-line); the second one still is under consideration.

Copilot AI lite review requested due to automatic review settings August 20, 2026 02:39
@tenox7

tenox7 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

Hi, is there any update on this? Can I somehow rework or split it to make it easier to work with?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a new user setting to choose between IEC binary (KiB/MiB/…) and SI decimal (KB/MB/…) scaling when displaying I/O rates, and wires that preference through the I/O rate formatting paths used by meters and process/dynamic columns.

Changes:

  • Introduce a persisted decimalUnits setting (read/write to config + UI toggle in Display Options).
  • Extend Row_printRate() to accept a decimal flag and scale using base 1000 vs 1024.
  • Add Meter_ioRateUnit() and update Disk/Network I/O meters to render the appropriate suffix (iB/s vs B/s).

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Settings.h Adds decimalUnits to the settings struct.
Settings.c Persists decimal_units in settings read/write; initializes default.
Row.h Updates Row_printRate signature and clarifies units/scaling behavior.
Row.c Implements base-1000 vs base-1024 scaling for rate display.
linux/LinuxProcess.c Passes decimalUnits into Row_printRate for per-process I/O rate fields.
pcp/PCPProcess.c Passes decimalUnits into Row_printRate for PCP per-process I/O rate fields.
pcp/PCPDynamicColumn.c Applies decimalUnits when rendering dynamic rate-like columns.
Meter.h Declares new Meter_ioRateUnit() helper for I/O rate formatting.
Meter.c Implements Meter_ioRateUnit() (SI/IEC scaling + suffix selection).
NetworkIOMeter.c Uses decimalUnits to format rate values and suffixes in the network I/O meter.
DiskIOMeter.c Uses decimalUnits to format rate values and suffixes in the disk I/O meter.
DisplayOptionsPanel.c Adds a UI checkbox to toggle decimal vs binary I/O rate units.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5b923ba6-fbd8-4a92-b5dc-20c2726a42d9

📥 Commits

Reviewing files that changed from the base of the PR and between 5da7a07 and 86a8472.

📒 Files selected for processing (6)
  • DisplayOptionsPanel.c
  • Meter.c
  • Meter.h
  • Settings.c
  • Settings.h
  • linux/LinuxProcess.c

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Comment thread Meter.c Resolved
Comment thread Settings.c Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (2)

Minor · Publish the migrated history file only after the copy completes. · Settings.c:963-965

Settings.c:963-965
Minor · Data Integrity & Integration · Quick win

Publish the migrated history file only after the copy completes.

Settings_migrateHistory() creates htop_history with O_EXCL before it copies anything. If the process is killed mid-copy, the cleanup at line 991 never runs. Later runs then fail O_EXCL and skip migration, so the intact legacy file is never loaded. Copy to a temporary file in the state directory, then publish it with link(), which fails if the target exists. Remove the temporary file afterward.

Minor · Measure pinned titles in display cells, not bytes. · Row.c:214-217

Row.c:214-217
Minor · Functional Correctness · Poor tradeoff

Measure pinned titles in display cells, not bytes.

RowField_pinnedWidth sums strlen of each pinned title. For a pinned dynamic column with a non-ASCII heading, that sum exceeds the header's rendered cell count. Panel.c uses the value as a screen column, so the header's scrolling part shifts relative to the rows. Compute the width in cells. Also pad dynamic headings by cells in alignedTitleDynamicColumn (Row.c:136).

Note

Follow-up findings are listed below so you can review them separately from inline comments.

Follow-up (1)
Minor (1)
Minor · Also migrate ~/.htop_history when the config has moved to XDG. · Settings.c:1036-1038

Settings.c:1036-1038
Minor · Functional Correctness · Poor tradeoff

Also migrate ~/.htop_history when the config has moved to XDG.

Settings_getHistoryFile derives the legacy history path from the active config path. After a ~/.htoprc migration, that path is the XDG config path, so the lookup checks ~/.config/htop/htop_history. A ~/.htop_history left by an older htop is never migrated.

Additional comments: 1
darwin/DarwinProcess.c-509-509: 1

509-509: Minor · Potential issue · Heavy lift

Unverified finding
We couldn't verify this from the code. It is shown for review, not as a verified issue.

The new 64-bit thread_id is passed to a process-table lookup after conversion to pid_t. IDs outside the pid_t range may truncate or become negative, causing lookup collisions or the subsequent assertion to fail.

A thread can be attributed to the wrong row, or a debug build can abort.

This can occur when: macOS supplies a thread identifier greater than PID_MAX or INT_MAX while userland threads are displayed.

Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: d8e82e5d-a3a8-4704-b9ff-ad7096307ef2
Commits

Reviewing files that changed from the base of the PR and between 86a8472 and 74c63d4.

Files selected for processing: 9
  • DisplayOptionsPanel.c
  • Meter.h
  • Row.c
  • Row.h
  • Settings.c
  • Settings.h
  • darwin/DarwinProcess.c
  • linux/LinuxProcess.c
  • pcp/PCPProcess.c

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Comment thread Meter.c Resolved
Adds a Display Options toggle (and decimal_units config key) to show I/O rates in SI decimal units (KB/s, MB/s) instead of IEC binary (KiB/s, MiB/s). Affects the disk/network I/O meters and the per-process IO rate columns; memory stays IEC.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Antoni Sawicki <as@tenoware.com>
@tenox7

tenox7 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: e9a15aaa-dd4e-4285-b09c-dbc5c763ca33
Commits

Reviewing files that changed from the base of the PR and between 74c63d4 and df0dbd9.

Files selected for processing: 1

  • Meter.c

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Comment thread Meter.c Resolved
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.

5 participants