Skip to content

Commit f0d3b4c

Browse files
committed
btrfs: zstd: don't cache sectorsize in a local variable
The sectorsize is used once or at most twice in the callbacks, no need to cache it on stack. Minor effect on zstd_compress_folios() where it saves 8 bytes of stack. Signed-off-by: David Sterba <dsterba@suse.com>
1 parent efcf089 commit f0d3b4c

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

fs/btrfs/zstd.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ void zstd_free_workspace(struct list_head *ws)
370370

371371
struct list_head *zstd_alloc_workspace(struct btrfs_fs_info *fs_info, int level)
372372
{
373-
const u32 blocksize = fs_info->sectorsize;
374373
struct workspace *workspace;
375374

376375
workspace = kzalloc_obj(*workspace);
@@ -383,7 +382,7 @@ struct list_head *zstd_alloc_workspace(struct btrfs_fs_info *fs_info, int level)
383382
workspace->req_level = level;
384383
workspace->last_used = jiffies;
385384
workspace->mem = kvmalloc(workspace->size, GFP_KERNEL | __GFP_NOWARN);
386-
workspace->buf = kmalloc(blocksize, GFP_KERNEL);
385+
workspace->buf = kmalloc(fs_info->sectorsize, GFP_KERNEL);
387386
if (!workspace->mem || !workspace->buf)
388387
goto fail;
389388

@@ -414,7 +413,6 @@ int zstd_compress_bio(struct list_head *ws, struct compressed_bio *cb)
414413
const u64 start = cb->start;
415414
const u32 len = cb->len;
416415
const u64 end = start + len;
417-
const u32 blocksize = fs_info->sectorsize;
418416
const u32 min_folio_size = btrfs_min_folio_size(fs_info);
419417

420418
workspace->params = zstd_get_btrfs_parameters(workspace->req_level, len);
@@ -463,7 +461,7 @@ int zstd_compress_bio(struct list_head *ws, struct compressed_bio *cb)
463461
}
464462

465463
/* Check to see if we are making it bigger. */
466-
if (tot_in + workspace->in_buf.pos > blocksize * 2 &&
464+
if (tot_in + workspace->in_buf.pos > fs_info->sectorsize * 2 &&
467465
tot_in + workspace->in_buf.pos < tot_out + workspace->out_buf.pos) {
468466
ret = -E2BIG;
469467
goto out;
@@ -590,7 +588,6 @@ int zstd_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
590588
size_t srclen = bio_get_size(&cb->bbio.bio);
591589
zstd_dstream *stream;
592590
int ret = 0;
593-
const u32 blocksize = fs_info->sectorsize;
594591
const unsigned int min_folio_size = btrfs_min_folio_size(fs_info);
595592
unsigned long folio_in_index = 0;
596593
unsigned long total_folios_in = DIV_ROUND_UP(srclen, min_folio_size);
@@ -620,7 +617,7 @@ int zstd_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
620617

621618
workspace->out_buf.dst = workspace->buf;
622619
workspace->out_buf.pos = 0;
623-
workspace->out_buf.size = blocksize;
620+
workspace->out_buf.size = fs_info->sectorsize;
624621

625622
while (1) {
626623
size_t ret2;
@@ -682,7 +679,6 @@ int zstd_decompress(struct list_head *ws, const u8 *data_in,
682679
{
683680
struct workspace *workspace = list_entry(ws, struct workspace, list);
684681
struct btrfs_fs_info *fs_info = btrfs_sb(folio_inode(dest_folio)->i_sb);
685-
const u32 sectorsize = fs_info->sectorsize;
686682
zstd_dstream *stream;
687683
int ret = 0;
688684
unsigned long to_copy = 0;
@@ -706,7 +702,7 @@ int zstd_decompress(struct list_head *ws, const u8 *data_in,
706702

707703
workspace->out_buf.dst = workspace->buf;
708704
workspace->out_buf.pos = 0;
709-
workspace->out_buf.size = sectorsize;
705+
workspace->out_buf.size = fs_info->sectorsize;
710706

711707
/*
712708
* Since both input and output buffers should not exceed one sector,

0 commit comments

Comments
 (0)