Skip to content

linux: add a disk-backed swap meter - #2081

Closed
blacks1ne wants to merge 1 commit into
htop-dev:mainfrom
blacks1ne:main
Closed

linux: add a disk-backed swap meter#2081
blacks1ne wants to merge 1 commit into
htop-dev:mainfrom
blacks1ne:main

Conversation

@blacks1ne

@blacks1ne blacks1ne commented Aug 21, 2026

Copy link
Copy Markdown

Expose disk-backed swap separately from zram so users can distinguish backing-store pressure from compressed RAM usage.
I chose Dsw abbreviation that is open to a better alternative.

@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d1a117eb-402d-4316-aec0-d464be0d8292

📥 Commits

Reviewing files that changed from the base of the PR and between 82b0400 and ef24653.

📒 Files selected for processing (1)
  • linux/DiskSwapMeter.c

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


📝 Walkthrough

Walkthrough

The change collects non-zram disk-backed swap usage from /proc/swaps. It stores total and used values in LinuxMachine. A new DiskSwapMeter formats and displays these values. The platform registers the meter and transfers machine values to it. The new header and source files are added to the Linux build lists.

Poem

Swap pages gather, zram steps aside,
Procfs records the values supplied.
A meter shows totals in view,
The platform carries the numbers through.
Build lists bind the feature tight.

Merge Risk: ⚪ Minimal · up to ef246

No actionable merge-blocking risk remains; the change is merge-ready after normal checks and review.


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

Comment @coderabbitai help to get the list of available commands.

Expose disk-backed swap separately from zram so users can distinguish backing-store pressure from compressed RAM usage.

Co-authored-by: Codex <noreply@openai.com>
@fasterit

Copy link
Copy Markdown
Member

There's a swap meter already. Extend that in case you feel the zram use case warrants that?

@blacks1ne

blacks1ne commented Aug 21, 2026

Copy link
Copy Markdown
Author

There's a swap meter already. Extend that in case you feel the zram use case warrants that?

Thanks, I'm ready to extend the existing Swap meter rather than add a separate meter.

One UI question before I revise it.

/proc/swaps provides per-device Used values, but those include pages reported globally as SwapCached. The current Swap meter shows that cache separately.

Would you prefer disk-backed and zram components to show backing-store occupancy, with SwapCached moved to text-only/removed from the bar.

That would make the displayed disk/zram components honest and non-overlapping.

Let me try to illustrate:

Submitted implementation

Swap: 2.25G / 40G
[ used 2.25G ][ cache 0.25G ][ free … ]

Zram: 0.7G (2.0G) / 8G
[ compressed 0.7G ][ uncompressed 1.3G ][ free … ]

Suggested: extend the Swap meter

Swap: 2.5G / 40G cache: 0.25G (included in a backing store)
[ Disk 0.5G ][ Zram 2.0G ][ free … ]

@fasterit

Copy link
Copy Markdown
Member

Do the math properly?

ChatGPT Codex recommends:

/proc/swaps gives you enough to calculate current swap usage by device, including zram.

Example:

$ cat /proc/swaps
Filename Type Size Used Priority
/dev/zram0 partition 8388604 1234567 100
/dev/sda3 partition 16777212 2345678 -2

The columns are in KiB:

  • Size = total swap capacity

  • Used = currently used swap

  • Free = Size - Used

  • Usage % = Used / Size × 100

So in this example:

Device Type Size Used Usage
/dev/zram0 zram 8 GiB ~1.18 GiB ~14.7%
/dev/sda3 disk 16 GiB ~2.24 GiB ~13.9%

Shell command

You can calculate it directly from /proc/swaps:

awk 'NR>1 {
    size=$3
    used=$4
    printf "%-20s size=%6.2f GiB used=%6.2f GiB free=%6.2f GiB usage=%5.1f%%\n",
           $1, size/1048576, used/1048576,
           (size-used)/1048576, 100*used/size
}' /proc/swaps

To specifically distinguish zram vs disk swap, you can use:

awk 'NR>1 {
    if ($1 ~ /zram/) zram_size+=$3; zram_used+=$4
    else disk_size+=$3; disk_used+=$4
}
END {
    printf "zram: %6.2f GiB used / %6.2f GiB total (%5.1f%%)\n",
           zram_used/1048576, zram_size/1048576,
           100*zram_used/zram_size
    printf "disk: %6.2f GiB used / %6.2f GiB total (%5.1f%%)\n",
           disk_used/1048576, disk_size/1048576,
           disk_size ? 100*disk_used/disk_size : 0
}' /proc/swaps

Important: zram's Used in /proc/swaps is the amount of compressed data occupying zram swap, not necessarily the amount of physical RAM consumed by the zram device. If you're trying to calculate the actual RAM overhead of zram, /sys/block/zram*/mm_stat is more informative.

@blacks1ne

Copy link
Copy Markdown
Author

Thank you for the review and guidance.

I’ll maintain the change in my fork as a separate disk-swap meter. Its purpose is to make disk-backed swap immediately visible, since it has materially different latency and stall implications from RAM-backed zram, a direction that may not fit upstream.

The existing Zram meter remains useful for its compression and RAM-cost view.

@blacks1ne blacks1ne closed this Aug 21, 2026
@BenBE BenBE added enhancement Extension or improvement to existing feature Linux 🐧 Linux related issues labels Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Extension or improvement to existing feature Linux 🐧 Linux related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants