Bug 247445 - ZFS - memory leak in dsl_scan_visitbp()
Summary: ZFS - memory leak in dsl_scan_visitbp()
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Mark Johnston
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-06-20 19:07 UTC by jdolecek@NetBSD.org
Modified: 2020-07-27 14:13 UTC (History)
2 users (show)

See Also:


Attachments
Memory leak fix (569 bytes, patch)
2020-06-20 19:07 UTC, jdolecek@NetBSD.org
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description jdolecek@NetBSD.org 2020-06-20 19:07:35 UTC
Created attachment 215825 [details]
Memory leak fix

File: sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_scan.c

dsl_scan_visitbp() doesn't free allocated memory when dsl_scan_recurse() fails. This is probably very rare, seems it's only possible on I/O errors.

I've attached what I believe is the fix, but it's not tested.

Memory leak was introduced with this change (git checkout):

commit a73aecd5f1b3afb968ba2977945b1a62d47d0353
Author: sef <sef@FreeBSD.org>
Date:   Fri Jun 8 17:38:28 2018 +0000

    This originated from ZFS On Linux, as
    https://github.com/zfsonlinux/zfs/commit/d4a72f23863382bdf6d0ae33196f5b5decbc48fd
    
    During scans (scrubs or resilvers), it sorts the blocks in each transaction
    group by block offset; the result can be a significant improvement. (On my
    test system just now, which I put some effort to introduce fragmentation into
    the pool since I set it up yesterday, a scrub went from 1h2m to 33.5m with the
    changes.) I've seen similar rations on production systems.
    
    Approved by:    Alexander Motin
    Obtained from:  ZFS On Linux
    Relnotes:       Yes (improved scrub performance, with tunables)
    Differential Revision:  https://reviews.freebsd.org/D15562
Comment 1 commit-hook freebsd_committer 2020-07-20 17:05:58 UTC
A commit references this bug:

Author: markj
Date: Mon Jul 20 17:05:44 UTC 2020
New revision: 363373
URL: https://svnweb.freebsd.org/changeset/base/363373

Log:
  Fix a memory leak in dsl_scan_visitbp().

  This should be triggered only if arc_read() fails, i.e., quite rarely.
  The same logic is already present in OpenZFS.

  PR:		247445
  Submitted by:	jdolecek@NetBSD.org
  MFC after:	1 week

Changes:
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_scan.c
Comment 2 commit-hook freebsd_committer 2020-07-27 14:10:27 UTC
A commit references this bug:

Author: markj
Date: Mon Jul 27 14:10:13 UTC 2020
New revision: 363602
URL: https://svnweb.freebsd.org/changeset/base/363602

Log:
  MFC r363373:
  Fix a memory leak in dsl_scan_visitbp().

  PR:	247445

Changes:
_U  stable/12/
  stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_scan.c
Comment 3 commit-hook freebsd_committer 2020-07-27 14:11:28 UTC
A commit references this bug:

Author: markj
Date: Mon Jul 27 14:11:09 UTC 2020
New revision: 363603
URL: https://svnweb.freebsd.org/changeset/base/363603

Log:
  MFC r363373:
  Fix a memory leak in dsl_scan_visitbp().

  PR:	247445

Changes:
_U  stable/11/
  stable/11/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_scan.c
Comment 4 Mark Johnston freebsd_committer 2020-07-27 14:13:10 UTC
Thanks for the report.