Skip to content
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

Fast Dedup: ZAP Shrinking #15888

Merged
merged 3 commits into from
Apr 24, 2024
Merged

Conversation

allanjude
Copy link
Contributor

Motivation and Context

If ZAP records are deleted such that an entire leaf block of the ZAP object is emptied, the block is not reclaimed.
In addition to allowing directories and other users of ZAPs to shrink when a large number of objects are removed, this is required for Fast Dedup's DDT pruning feature.

Description

This change addresses this issue in part by noticing when adjacent blocks are emptied, and collapses them into a single empty block, thereby reducing the total amount of space in the ZAP object.

This adds a tuneable, zfs_zap_shrink_enabled, set by default. If disabled, the shrinking behaviour is disabled.

This replaces #14088

How Has This Been Tested?

TBD.

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:

@behlendorf behlendorf mentioned this pull request Feb 15, 2024
@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Feb 15, 2024
@robn robn force-pushed the fdt-rel-zap-shrink branch from a076382 to b9c2849 Compare February 15, 2024 19:58
module/zfs/zap.c Outdated Show resolved Hide resolved
module/zfs/zap.c Outdated Show resolved Hide resolved
module/zfs/zap.c Outdated Show resolved Hide resolved
module/zfs/zap.c Outdated Show resolved Hide resolved
module/zfs/zap.c Outdated Show resolved Hide resolved
module/zfs/zap.c Outdated
uint64_t sl_hash = ZAP_PREFIX_HASH(sl_prefix, prefix_len);
int slbit = prefix & 1;

ASSERT3U(zt_shift, ==, zap_f_phys(zap)->zap_ptrtbl.zt_shift);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should re-read zt_shift from ZAP after reacquiring the ZAP lock below, where it may actually change, instead of asserting this here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@bhodgens
Copy link

I'm extremely happy to see this one getting attention! This has been one of my 'pet bugs' for years.

module/zfs/zap.c Outdated
uint64_t sl_hash = ZAP_PREFIX_HASH(sl_prefix, prefix_len);
int slbit = prefix & 1;

ASSERT3S(zap_leaf_phys(l)->l_hdr.lh_nentries, ==, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ASSERT3S(zap_leaf_phys(l)->l_hdr.lh_nentries, ==, 0);
ASSERT3U(zap_leaf_phys(l)->l_hdr.lh_nentries, ==, 0);

module/zfs/zap.c Outdated Show resolved Hide resolved
Copy link
Member

@amotin amotin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks you.

Copy link
Contributor

@behlendorf behlendorf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As part of this commit let's add explicit test coverage for at least one of the most common cases. Specifically creating a directory, adding a large number of files so it's converted to a fatzap, then removing those files and verifying the zap is collapsed.

The tests/zfs-tests/tests/functional/cp_files/cp_files_001_pos.ksh already does most of this and would be relatively easy to extend by using zdb check the zap stats.

Can you also add your signed off by when refreshing this.

module/zfs/zap.c Show resolved Hide resolved
This allows ZAPs to shrink. When there are two empty sibling leafs,
one of them is collapsed and its storage space is reused.
This improved performance on directories that at one time contained
a large number of files, but many or all of those files have since
been deleted.

This also applies to all other types of ZAPs as well.

Sponsored-by: iXsystems, Inc.
Sponsored-by: Klara, Inc.
Signed-off-by: Alexander Stetsenko <alex.stetsenko@klarasystems.com>
Sponsored-by: iXsystems, Inc.
Sponsored-by: Klara, Inc.
Signed-off-by: Alexander Stetsenko <alex.stetsenko@klarasystems.com>
@alex-stetsenko alex-stetsenko force-pushed the fdt-rel-zap-shrink branch 3 times, most recently from fcd91d5 to 2599b25 Compare April 15, 2024 09:55
@alex-stetsenko alex-stetsenko force-pushed the fdt-rel-zap-shrink branch 3 times, most recently from a22f7d1 to 1c3c09a Compare April 19, 2024 18:07
Sponsored-by: iXsystems, Inc.
Sponsored-by: Klara, Inc.
Signed-off-by: Alexander Stetsenko <alex.stetsenko@klarasystems.com>
@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Apr 22, 2024
@behlendorf behlendorf merged commit 5044c4e into openzfs:master Apr 24, 2024
24 of 25 checks passed
@jumbi77
Copy link
Contributor

jumbi77 commented Apr 25, 2024

Awesome that this got merged! Thanks to klarasystems & iX!

@behlendorf It is possible that this can be backported and released in a 2.2.x release, independent from the whole/complete fast dedupe feature?

@behlendorf
Copy link
Contributor

@jumbi77 yes, but we'll want it to have had a lot of soak time in the master branch first.

@don-brady don-brady mentioned this pull request May 14, 2024
13 tasks
@robn robn mentioned this pull request Jul 20, 2024
13 tasks
@jumbi77
Copy link
Contributor

jumbi77 commented Aug 28, 2024

@jumbi77 yes, but we'll want it to have had a lot of soak time in the master branch first.

May i ask if around 4 month is enough soak time? @tonyhutter is it possible to pull this into current 2.2.6?

lundman pushed a commit to openzfsonwindows/openzfs that referenced this pull request Sep 4, 2024
This allows ZAPs to shrink. When there are two empty sibling leafs,
one of them is collapsed and its storage space is reused.
This improved performance on directories that at one time contained
a large number of files, but many or all of those files have since
been deleted.

This also applies to all other types of ZAPs as well.

Sponsored-by: iXsystems, Inc.
Sponsored-by: Klara, Inc.
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Signed-off-by: Alexander Stetsenko <alex.stetsenko@klarasystems.com>
Closes openzfs#15888
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.

6 participants