]> git.hungrycats.org Git - linux/commitdiff
btrfs: lzo: remove the special handling inside one fs block
authorQu Wenruo <wqu@suse.com>
Thu, 15 Oct 2026 08:59:50 +0000 (19:29 +1030)
committerDavid Sterba <dsterba@suse.com>
Fri, 30 Oct 2026 20:36:17 +0000 (21:36 +0100)
Since commit 3eaf5f082c4c ("btrfs: extract inlined creation into a
dedicated delalloc helper"), even for inlined compressed extents the cb
range will be exact one block, aka [0, sector).

And several attempts to bring back the old compression range [0, i_size]
all failed with extra races against i_size.

So I think the behavior will stay. With that said, we can further
simplify the lzo compression path.
Since the range is always aligned to block size, and lzo compression is
already done block by block, there is no reason to handle sub-block
sized range.

We can safely remove the @sectorsize_mask, @sector_off and @in_len
variables, and always use @sectorsize as input length for each
compression iteration.

Finally add two ASSERT()s to make sure the range passed into
btrfs_compress_bio() is always block aligned.

Reviewed-by: Daniel Vacek <neelx@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/compression.c
fs/btrfs/lzo.c

index ad90e14032dbb37601efa7da5d09a7c4f25b9b69..b12b7f1b31fdfa7860a6852a9394ab8f49747517 100644 (file)
@@ -1010,6 +1010,9 @@ struct compressed_bio *btrfs_compress_bio(struct btrfs_inode *inode,
        struct compressed_bio *cb;
        int ret;
 
+       ASSERT(IS_ALIGNED(start, fs_info->sectorsize));
+       ASSERT(IS_ALIGNED(len, fs_info->sectorsize));
+
        cb = alloc_compressed_bio(inode, start, REQ_OP_WRITE | write_flags,
                                  end_bbio_compressed_write);
        cb->start = start;
index 2f0996692da05abcd5c80fd8226711abb4e7590f..0b2d9a825543b834473bb817577e03f66d9bf08c 100644 (file)
@@ -291,9 +291,6 @@ int lzo_compress_bio(struct list_head *ws, struct compressed_bio *cb)
 
        while (cur_in < start + len) {
                char *data_in;
-               const u32 sectorsize_mask = sectorsize - 1;
-               u32 sector_off = (cur_in - start) & sectorsize_mask;
-               u32 in_len;
                size_t out_len;
 
                /* Get the input page first. */
@@ -303,11 +300,9 @@ int lzo_compress_bio(struct list_head *ws, struct compressed_bio *cb)
                                goto out;
                }
 
-               /* Compress at most one sector of data each time. */
-               in_len = min_t(u32, start + len - cur_in, sectorsize - sector_off);
-               ASSERT(in_len);
+               /* Compress one sector of data each time. */
                data_in = kmap_local_folio(folio_in, offset_in_folio(folio_in, cur_in));
-               ret = lzo1x_1_compress(data_in, in_len, workspace->cbuf, &out_len,
+               ret = lzo1x_1_compress(data_in, sectorsize, workspace->cbuf, &out_len,
                                       workspace->mem);
                kunmap_local(data_in);
                if (unlikely(ret < 0)) {
@@ -321,7 +316,7 @@ int lzo_compress_bio(struct list_head *ws, struct compressed_bio *cb)
                if (ret < 0)
                        goto out;
 
-               cur_in += in_len;
+               cur_in += sectorsize;
 
                /*
                 * Check if we're making it bigger after two sectors.  And if