BACKPORT: f2fs: compress: remove unneeded preallocation

commit 8f1d49832636 upstream.

We will reserve iblocks for compression saved, so during compressed
cluster overwrite, we don't need to preallocate blocks for later
write.

In addition, it adds a bug_on to detect wrong reserved iblock number
in __f2fs_cluster_blocks().

Bug fix in the original patch by Jaegeuk:
If we released compressed blocks having an immutable bit, we can see less
number of compressed block addresses. Let's fix wrong BUG_ON.

Bug: 237904436
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Change-Id: I673af616581a9e7bf711e60d1588856f24f65dc9
This commit is contained in:
Chao Yu
2021-05-12 17:52:58 +08:00
committed by Greg Kroah-Hartman
parent 012ab662e2
commit 3cf0f8245d
2 changed files with 3 additions and 28 deletions

View File

@@ -809,6 +809,9 @@ static int __f2fs_cluster_blocks(struct compress_ctx *cc, bool compr)
ret++;
}
}
f2fs_bug_on(F2FS_I_SB(inode),
!compr && ret != cc->cluster_size && !IS_IMMUTABLE(inode));
}
fail:
f2fs_put_dnode(&dn);
@@ -879,21 +882,16 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,
struct f2fs_sb_info *sbi = F2FS_I_SB(cc->inode);
struct address_space *mapping = cc->inode->i_mapping;
struct page *page;
struct dnode_of_data dn;
sector_t last_block_in_bio;
unsigned fgp_flag = FGP_LOCK | FGP_WRITE | FGP_CREAT;
pgoff_t start_idx = start_idx_of_cluster(cc);
int i, ret;
bool prealloc;
retry:
ret = f2fs_cluster_blocks(cc, false);
if (ret <= 0)
return ret;
/* compressed case */
prealloc = (ret < cc->cluster_size);
ret = f2fs_init_compress_ctx(cc);
if (ret)
return ret;
@@ -949,25 +947,6 @@ retry:
}
}
if (prealloc) {
__do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, true);
set_new_dnode(&dn, cc->inode, NULL, NULL, 0);
for (i = cc->cluster_size - 1; i > 0; i--) {
ret = f2fs_get_block(&dn, start_idx + i);
if (ret) {
i = cc->cluster_size;
break;
}
if (dn.data_blkaddr != NEW_ADDR)
break;
}
__do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, false);
}
if (likely(!ret)) {
*fsdata = cc->rpages;
*pagep = cc->rpages[offset_in_cluster(cc, index)];

View File

@@ -80,10 +80,6 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
err = ret;
goto err;
} else if (ret) {
if (ret < F2FS_I(inode)->i_cluster_size) {
err = -EAGAIN;
goto err;
}
need_alloc = false;
}
}