Skip to content

linux: avoid repeated zram ENOENT probes#1977

Merged
BenBE merged 1 commit intohtop-dev:mainfrom
Komzpa:fixer-zram-enoent-probes
May 1, 2026
Merged

linux: avoid repeated zram ENOENT probes#1977
BenBE merged 1 commit intohtop-dev:mainfrom
Komzpa:fixer-zram-enoent-probes

Conversation

@Komzpa
Copy link
Copy Markdown
Contributor

@Komzpa Komzpa commented May 1, 2026

Summary

This changes Linux zram accounting to enumerate existing /sys/block/zramN devices instead of probing zram0, zram1, and so on until a file open fails.

On systems without zram, htop otherwise repeats failed sysfs lookups for /sys/block/zram0/disksize and /sys/block/zram0/mm_stat on refresh. Enumerating /sys/block avoids that repeated ENOENT path and also naturally handles non-contiguous zram numbering.

The implementation follows the existing Linux compat style: each enumerated zram directory is opened relative to the /sys/block directory using the openat-style path, and disksize / mm_stat are read with Compat_readfileat rather than fopen.

Validation

  • git diff --check
  • ./autogen.sh && ./configure && make -j2

@BenBE BenBE added enhancement Extension or improvement to existing feature Linux 🐧 Linux related issues labels May 1, 2026
@BenBE
Copy link
Copy Markdown
Member

BenBE commented May 1, 2026

Please avoid the fopen API (they cause trouble in high-memory-pressure situations.

Also, given we are already enumerating a directory using its fd, try to use the openat style APIs that help the kernel with resolving paths quicker.

Also take a look at the Compat_readfileat function to read the entire file contents at once.

Regarding building: Try to ./autogen.sh && ./configure && make, which should give a good starting point to check your changes.

@Komzpa Komzpa force-pushed the fixer-zram-enoent-probes branch from d6e5934 to 9fe974b Compare May 1, 2026 14:04
@Komzpa
Copy link
Copy Markdown
Contributor Author

Komzpa commented May 1, 2026

Thanks, fixed. The zram scan no longer uses fopen for the sysfs files: it opens each enumerated zram directory relative to /sys/block using the openat-style compat path and reads disksize/mm_stat with Compat_readfileat.

I also reran the requested build path successfully: ./autogen.sh && ./configure && make -j2

@BenBE BenBE merged commit 24731bc into htop-dev:main May 1, 2026
20 checks passed
@BenBE BenBE modified the milestone: 3.6.0 May 1, 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.

2 participants