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

file_zbc: punch hole on zone reset #660

Open
kdave opened this issue Jun 25, 2021 · 1 comment
Open

file_zbc: punch hole on zone reset #660

kdave opened this issue Jun 25, 2021 · 1 comment

Comments

@kdave
Copy link

kdave commented Jun 25, 2021

Zone reset is simply rewriting the write pointer to the beginning without touching the actual zone data. It would be nice and easy to implement a hole punch, file operation freeing the metadata and data of the requested range. That way a backing file can be shrunk to only live zones. It's a bit like thin provisioning, the file starts sparsely allocated (using just the targetcli commands). I've measured the time of the hole punch on a moderately fragmented file on btrfs, with zone size 256M, the fallocate() call takes like 0.1s, ie. 100ms which is IMO acceptable.

Code change goes like

static void __zbc_reset_wp(struct zbc_dev *zdev, struct zbc_zone *zone)
{
        if (zbc_zone_conv(zone))
                return;

        if (zbc_zone_is_open(zone))
                __zbc_close_zone(zdev, zone);

        zone->wp = zone->start;
        zone->cond = ZBC_ZONE_COND_EMPTY;
        zone->non_seq = 0;
        zone->reset = 0;
        fallocate(zbc_dev->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, zone->start, zone->length);
}

Errors can be ignored, it's just best effort.

@kdave
Copy link
Author

kdave commented Jun 25, 2021

There's system command fallocate, with option --dig-holes it can detect zeroed blocks and punch the hole, but for the test image I had the previous non-zero data and as a result only 2G were removed from a 46G backing file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant