Skip to content

arcstat: prevent ZeroDivisionError when L2ARC becomes empty #17348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025

Conversation

ixhamza
Copy link
Member

@ixhamza ixhamza commented May 19, 2025

Motivation and Context

Prevent a ZeroDivisionError in arcstat when the L2ARC exists but becomes empty during monitoring.

Description

When monitoring L2ARC usage with arcstat, if the L2ARC device is present but its size l2_asize drops to zero, arcstat crashes with a ZeroDivisionError during percentage calculation:

$ arcstat -f time,l2size 1

Traceback (most recent call last):
  File "/bin/arcstat", line 802, in <module>
    main()
  File "/bin/arcstat", line 786, in main
    calculate()
  File "/bin/arcstat", line 754, in calculate
    v["l2pref%"] = 100 * v["l2pref"] / v["l2asize"]
                   ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
ZeroDivisionError: division by zero

How Has This Been Tested?

  • Manually verified that arcstat no longer crashes when L2ARC becomes empty during runtime.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

@amotin amotin added the Status: Code Review Needed Ready for review and testing label May 19, 2025
@amotin amotin added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels May 19, 2025
Signed-off-by: Ameer Hamza <ahamza@ixsystems.com>
@ixhamza ixhamza force-pushed the NAS-133831-arcstat-div0 branch from 5786393 to ce468a2 Compare May 19, 2025 16:47
@github-actions github-actions bot removed the Status: Accepted Ready to integrate (reviewed, tested) label May 19, 2025
@amotin amotin added the Status: Accepted Ready to integrate (reviewed, tested) label May 19, 2025
@ryao
Copy link
Contributor

ryao commented May 19, 2025

A nice follow-up to this would be to add a CodeQL check to detect potential ZeroDivisionError issues in Python code.

@behlendorf behlendorf merged commit f0baaa3 into openzfs:master May 19, 2025
23 of 24 checks passed
robn pushed a commit to robn/zfs that referenced this pull request May 23, 2025
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Richard Yao <richard@ryao.dev>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: George Melikov <mail@gmelikov.ru>
Signed-off-by: Ameer Hamza <ahamza@ixsystems.com>
Closes openzfs#17348
(cherry picked from commit f0baaa3)
@robn robn mentioned this pull request May 23, 2025
14 tasks
robn pushed a commit to robn/zfs that referenced this pull request May 24, 2025
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Richard Yao <richard@ryao.dev>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: George Melikov <mail@gmelikov.ru>
Signed-off-by: Ameer Hamza <ahamza@ixsystems.com>
Closes openzfs#17348
(cherry picked from commit f0baaa3)
tonyhutter pushed a commit that referenced this pull request May 28, 2025
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Richard Yao <richard@ryao.dev>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: George Melikov <mail@gmelikov.ru>
Signed-off-by: Ameer Hamza <ahamza@ixsystems.com>
Closes #17348
(cherry picked from commit f0baaa3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants