Skip to content

Add zswap usage and compression meters#2047

Merged
BenBE merged 1 commit into
htop-dev:mainfrom
ABHIRAMSHIBU:feature/zswap-meters
Jul 19, 2026
Merged

Add zswap usage and compression meters#2047
BenBE merged 1 commit into
htop-dev:mainfrom
ABHIRAMSHIBU:feature/zswap-meters

Conversation

@ABHIRAMSHIBU

Copy link
Copy Markdown
Contributor

Summary

Add Linux zswap visibility to htop without changing existing memory or swap accounting.

This introduces:

  • A Zswap bar meter showing compressed pool usage against the configured pool limit.
  • A ZswapStats meter showing compressed usage, original size, and compression ratio.
  • Detection of zswap being disabled.
  • Clear disabled and unavailable states when appropriate.
  • Support for systems where the pool limit is unavailable.

The pool limit is derived from the configured max_pool_percent value and total system memory.

Testing

  • make -j4
  • make check
  • git diff --check
  • Manually verified zswap-enabled and zswap-disabled states.

@coderabbitai coderabbitai Bot added the Linux 🐧 Linux related issues label Jul 18, 2026
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

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

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: 93e6fd60-0260-428e-876c-4669130edcfb

📥 Commits

Reviewing files that changed from the base of the PR and between 593a7c8 and fdf6309.

📒 Files selected for processing (6)
  • Makefile.am
  • linux/LinuxMachine.c
  • linux/Platform.c
  • linux/ZswapMeter.c
  • linux/ZswapMeter.h
  • linux/ZswapStats.h

📝 Walkthrough

Walkthrough

Linux scanning now detects Zswap counters, enablement, and pool limits. Two Linux meter classes display compressed pool usage and compression statistics. Their declarations and implementations are added to the Linux build lists, and both classes are registered in the platform meter registry.

Suggested labels: Linux :penguin:

Suggested reviewers: intelfx, benbe

Poem

Zswap wakes beneath the load,
Counters parse the kernel road.
Pools and ratios take the stage,
Two new meters fill the gauge.
Linux builds the parts in line.


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.

Comment thread linux/LinuxMachine.c Outdated
Comment thread linux/ZswapMeter.c Outdated
Comment thread linux/ZswapMeter.c Outdated
@ABHIRAMSHIBU
ABHIRAMSHIBU requested a review from BenBE July 18, 2026 19:29
@coderabbitai coderabbitai Bot removed the Linux 🐧 Linux related issues label Jul 18, 2026

@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 platform limitations.

⚠️ Outside diff range comments (1)
linux/LinuxMachine.c (1)

249-254: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Skip max_pool_percent when zswap is disabled. memory_t is 64-bit, so there’s no overflow concern here; the only gain is avoiding an unnecessary sysfs read on the disabled path.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 01a3a96d-c92f-4f51-bd27-bc15e197d3d2

📥 Commits

Reviewing files that changed from the base of the PR and between c8564b2 and 330da97.

📒 Files selected for processing (2)
  • linux/LinuxMachine.c
  • linux/ZswapMeter.c

@coderabbitai coderabbitai Bot added the Linux 🐧 Linux related issues label Jul 18, 2026

@BenBE BenBE 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.

LGTM. Only minor notes remaining; nothing critical.

Comment thread linux/ZswapMeter.h
Comment thread linux/LinuxMachine.c Outdated
Comment thread linux/ZswapStats.h Outdated
@BenBE BenBE added this to the 3.6.0 milestone Jul 18, 2026

@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 platform limitations.

⚠️ Outside diff range comments (1)
linux/LinuxMachine.c (1)

162-170: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Avoid adding another function-like macro.

tryReadFlag duplicates parsing logic and hides break control flow inside a macro. Replace it with a small static helper or explicit parsing code in the Z case so the control flow remains visible.

As per coding guidelines, avoid function-like macros.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0e709f55-1cae-4f49-b7d9-15774e11bba2

📥 Commits

Reviewing files that changed from the base of the PR and between 504da1a and 593a7c8.

📒 Files selected for processing (3)
  • linux/LinuxMachine.c
  • linux/ZswapMeter.h
  • linux/ZswapStats.h

@ABHIRAMSHIBU

Copy link
Copy Markdown
Contributor Author

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)

linux/LinuxMachine.c (1)> 162-170: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Avoid adding another function-like macro.
tryReadFlag duplicates parsing logic and hides break control flow inside a macro. Replace it with a small static helper or explicit parsing code in the Z case so the control flow remains visible.
As per coding guidelines, avoid function-like macros.

Source: Coding guidelines

ℹ️ Review info
⚙️ Run configuration

📥 Commits

📒 Files selected for processing (3)

Initially I was thinking to move it to a function above the current function as LinuxMachine_tryReadFlag(), then felt to duplicate as I didnt know if it was a good idea to do that because it didnt feel right spot to put it after reading the file.

@BenBE

BenBE commented Jul 19, 2026

Copy link
Copy Markdown
Member

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)

linux/LinuxMachine.c (1)> 162-170: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Avoid adding another function-like macro.
tryReadFlag duplicates parsing logic and hides break control flow inside a macro. Replace it with a small static helper or explicit parsing code in the Z case so the control flow remains visible.
As per coding guidelines, avoid function-like macros.

Source: Coding guidelines

ℹ️ Review info

@coderabbitai These function-like macros for parsing are fine when defined for a very limited, local purpose. Copying the existing macro and extending it for the task at hand is fine.

@ABHIRAMSHIBU Can you rebase/squash your commits. Bug fixes to previous parts of a PR should be absorbed into where those issues were introduced.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@BenBE Understood. Given the established local parsing-macro pattern in linux/LinuxMachine.c, extending it with tryReadFlag is consistent with the surrounding code. I’m withdrawing this comment.


✏️ Learnings added
Learnt from: BenBE
URL: https://github.com/htop-dev/htop/pull/2047

Timestamp: 2026-07-19T07:54:09.132Z
Learning: In `linux/LinuxMachine.c`, function-like parsing macros with a tightly limited local scope are an accepted project pattern. Extending an existing local parsing macro for related `/proc/meminfo` parsing is preferred over extracting a separate helper solely to avoid duplication.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Add bar and statistics meters for zswap pool usage, including disabled and unavailable states.

Assisted-by: OpenAI Codex
@ABHIRAMSHIBU
ABHIRAMSHIBU force-pushed the feature/zswap-meters branch from 593a7c8 to fdf6309 Compare July 19, 2026 08:19
@BenBE
BenBE merged commit 255b014 into htop-dev:main Jul 19, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Linux 🐧 Linux related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants