Skip to content

freebsd: unifying buffer/cache memory usage for both ufs and zfs#2033

Merged
BenBE merged 1 commit into
htop-dev:mainfrom
crocidb:main
Jun 24, 2026
Merged

freebsd: unifying buffer/cache memory usage for both ufs and zfs#2033
BenBE merged 1 commit into
htop-dev:mainfrom
crocidb:main

Conversation

@crocidb

@crocidb crocidb commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Hi everyone! :)

This is more of a suggestion on how to improve readability of FreeBSD memory monitoring. Here I'm basically unifying MEMORY_CLASS_BUFFER and MEMORY_CLASS_ARC into MEMORY_CLASS_CACHE. This is because of a few reasons:

  1. MEMORY_CLASS_BUFFER is checking for vfs.bufspace, which reports the metadata buffer cache for UFS specifically. On ZFS only, it's always zero, because ARC bypasses the vfs system.
  2. MEMORY_CLASS_ARC is not being subtracted from wired memory (although being part of it), and is being counted as used memory, although MEMORY_CLASS_BUFFER is not. And the behavior of disk cache on Linux is to not being counted as used.

With the new MEMORY_CLASS_CACHE, it will always report the current buffer/cache for the current filesystems. It's easier to understand and more accurate not considering ARC cache as used memory.

EDIT: I did not consider, at first, that both UFS and ZFS could be active in the system, but it's not true. So I changed to effectively sum those two values.

Thanks.

@coderabbitai

coderabbitai Bot commented Jun 24, 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: dadecf1b-c6e9-4280-adf4-30b2a5ed20fb

📥 Commits

Reviewing files that changed from the base of the PR and between 2853fc9 and b174af9.

📒 Files selected for processing (3)
  • freebsd/FreeBSDMachine.c
  • freebsd/FreeBSDMachine.h
  • freebsd/Platform.c

📝 Walkthrough

Walkthrough

The PR replaces FreeBSD buffers and ARC accounting with a single cacheMem value. FreeBSDMachine_scanMemoryInfo() now derives that value from vfs.bufspace, adds ZFS shrinkable space when present, and subtracts it from wired memory. The FreeBSD struct and platform memory classes were updated to use cacheMem and a single CACHE class, with showCachedMemory controlling whether cache is shown separately or merged into wired memory.

Poem

Buffers and ARC moved out of sight,
Cache took their place in cleaner light.
Bufspace hums, wired sums fall,
One steady class now covers it all.


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.

@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: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: fa32b47a-121c-4367-9db0-6061d621518c

📥 Commits

Reviewing files that changed from the base of the PR and between f137d5a and 05bb928.

📒 Files selected for processing (3)
  • freebsd/FreeBSDMachine.c
  • freebsd/FreeBSDMachine.h
  • freebsd/Platform.c

Comment thread freebsd/FreeBSDMachine.c Outdated
Comment thread freebsd/FreeBSDMachine.c Outdated
Comment thread freebsd/Platform.c

@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)
freebsd/FreeBSDMachine.c (1)

319-321: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Update the ZFS comment to match cacheMem.

This still refers to the ARC total and the old “buffer” class, but the code now uses a shrinkable ARC fallback for cacheMem.

Proposed wording
-   // With ZFS, the ARC area is NOT counted in the 'buffers' class, but is still counted in the 'wired'
-   // class. The ARC total must thus be subtracted from the 'wired' class AND added to the 'buffer' class,
-   // so that the result is consistent with what ZFS users would expect.
+   // With ZFS, ARC is NOT counted in vfs.bufspace, but is still counted in the 'wired'
+   // class. Use the shrinkable ARC portion as a cache approximation when vfs.bufspace
+   // is unavailable, then subtract that cache value from 'wired'.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b19c03eb-0ff6-450e-a158-ae22861e5ecd

📥 Commits

Reviewing files that changed from the base of the PR and between 05bb928 and ba8b4a0.

📒 Files selected for processing (2)
  • freebsd/FreeBSDMachine.c
  • freebsd/Platform.c

@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

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 11ef57f1-d19c-4963-9fec-f5ceda5eb3ba

📥 Commits

Reviewing files that changed from the base of the PR and between ba8b4a0 and edd7e1c.

📒 Files selected for processing (1)
  • freebsd/FreeBSDMachine.c

Comment thread freebsd/FreeBSDMachine.c Outdated
@BenBE

BenBE commented Jun 24, 2026

Copy link
Copy Markdown
Member

@crocidb Thank you for this PR. On first glance the code looks okay. Please review that one cache size clamping issue that got flagged, as these kinds of edge cases tend to produce very annoying display issues. Apart from this, the code style asks for commits to be "final" without later commits in a PR reverting or fixing them. Please use git rebase to squash/fixup the commits in your PR so these fixes are integrated with where each issue was introduced.

@BenBE BenBE added enhancement Extension or improvement to existing feature FreeBSD 👹 FreeBSD related issues labels Jun 24, 2026
@crocidb

crocidb commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Hi @BenBE! Thanks for the quick reply. I applied the changes suggested and squashed into one single commit.

@BenBE BenBE added this to the 3.6.0 milestone Jun 24, 2026
@BenBE BenBE merged commit 81ed8c1 into htop-dev:main Jun 24, 2026
21 checks passed
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 FreeBSD 👹 FreeBSD related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants