f2fs: clean up i_compress_flag and i_compress_level usage
[ Upstream commit b90e5086df6bf5ba819216d5ecf0667370bd565f ]
.i_compress_level was introduced by commit 3fde13f817 ("f2fs: compress:
support compress level"), but never be used.
This patch updates as below:
- load high 8-bits of on-disk .i_compress_flag to in-memory .i_compress_level
- load low 8-bits of on-disk .i_compress_flag to in-memory .i_compress_flag
- change type of in-memory .i_compress_flag from unsigned short to unsigned
char.
w/ above changes, we can avoid unneeded bit shift whenever during
.init_compress_ctx(), and shrink size of struct f2fs_inode_info.
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Stable-dep-of: f5f3bd903a5d ("f2fs: set the default compress_level on ioctl")
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
2c14f49916
commit
84a8d913fb
3 changed files with 19 additions and 12 deletions
|
|
@ -241,7 +241,7 @@ static int lz4_init_compress_ctx(struct compress_ctx *cc)
|
||||||
unsigned int size = LZ4_MEM_COMPRESS;
|
unsigned int size = LZ4_MEM_COMPRESS;
|
||||||
|
|
||||||
#ifdef CONFIG_F2FS_FS_LZ4HC
|
#ifdef CONFIG_F2FS_FS_LZ4HC
|
||||||
if (F2FS_I(cc->inode)->i_compress_flag >> COMPRESS_LEVEL_OFFSET)
|
if (F2FS_I(cc->inode)->i_compress_level)
|
||||||
size = LZ4HC_MEM_COMPRESS;
|
size = LZ4HC_MEM_COMPRESS;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -267,8 +267,7 @@ static void lz4_destroy_compress_ctx(struct compress_ctx *cc)
|
||||||
#ifdef CONFIG_F2FS_FS_LZ4HC
|
#ifdef CONFIG_F2FS_FS_LZ4HC
|
||||||
static int lz4hc_compress_pages(struct compress_ctx *cc)
|
static int lz4hc_compress_pages(struct compress_ctx *cc)
|
||||||
{
|
{
|
||||||
unsigned char level = F2FS_I(cc->inode)->i_compress_flag >>
|
unsigned char level = F2FS_I(cc->inode)->i_compress_level;
|
||||||
COMPRESS_LEVEL_OFFSET;
|
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
if (level)
|
if (level)
|
||||||
|
|
@ -340,8 +339,7 @@ static int zstd_init_compress_ctx(struct compress_ctx *cc)
|
||||||
zstd_cstream *stream;
|
zstd_cstream *stream;
|
||||||
void *workspace;
|
void *workspace;
|
||||||
unsigned int workspace_size;
|
unsigned int workspace_size;
|
||||||
unsigned char level = F2FS_I(cc->inode)->i_compress_flag >>
|
unsigned char level = F2FS_I(cc->inode)->i_compress_level;
|
||||||
COMPRESS_LEVEL_OFFSET;
|
|
||||||
|
|
||||||
if (!level)
|
if (!level)
|
||||||
level = F2FS_ZSTD_DEFAULT_CLEVEL;
|
level = F2FS_ZSTD_DEFAULT_CLEVEL;
|
||||||
|
|
|
||||||
|
|
@ -840,7 +840,7 @@ struct f2fs_inode_info {
|
||||||
unsigned char i_compress_algorithm; /* algorithm type */
|
unsigned char i_compress_algorithm; /* algorithm type */
|
||||||
unsigned char i_log_cluster_size; /* log of cluster size */
|
unsigned char i_log_cluster_size; /* log of cluster size */
|
||||||
unsigned char i_compress_level; /* compress level (lz4hc,zstd) */
|
unsigned char i_compress_level; /* compress level (lz4hc,zstd) */
|
||||||
unsigned short i_compress_flag; /* compress flag */
|
unsigned char i_compress_flag; /* compress flag */
|
||||||
unsigned int i_cluster_size; /* cluster size */
|
unsigned int i_cluster_size; /* cluster size */
|
||||||
|
|
||||||
unsigned int atomic_write_cnt;
|
unsigned int atomic_write_cnt;
|
||||||
|
|
@ -4339,9 +4339,8 @@ static inline int set_compress_context(struct inode *inode)
|
||||||
if ((F2FS_I(inode)->i_compress_algorithm == COMPRESS_LZ4 ||
|
if ((F2FS_I(inode)->i_compress_algorithm == COMPRESS_LZ4 ||
|
||||||
F2FS_I(inode)->i_compress_algorithm == COMPRESS_ZSTD) &&
|
F2FS_I(inode)->i_compress_algorithm == COMPRESS_ZSTD) &&
|
||||||
F2FS_OPTION(sbi).compress_level)
|
F2FS_OPTION(sbi).compress_level)
|
||||||
F2FS_I(inode)->i_compress_flag |=
|
F2FS_I(inode)->i_compress_level =
|
||||||
F2FS_OPTION(sbi).compress_level <<
|
F2FS_OPTION(sbi).compress_level;
|
||||||
COMPRESS_LEVEL_OFFSET;
|
|
||||||
F2FS_I(inode)->i_flags |= F2FS_COMPR_FL;
|
F2FS_I(inode)->i_flags |= F2FS_COMPR_FL;
|
||||||
set_inode_flag(inode, FI_COMPRESSED_FILE);
|
set_inode_flag(inode, FI_COMPRESSED_FILE);
|
||||||
stat_inc_compr_inode(inode);
|
stat_inc_compr_inode(inode);
|
||||||
|
|
|
||||||
|
|
@ -450,11 +450,17 @@ static int do_read_inode(struct inode *inode)
|
||||||
(fi->i_flags & F2FS_COMPR_FL)) {
|
(fi->i_flags & F2FS_COMPR_FL)) {
|
||||||
if (F2FS_FITS_IN_INODE(ri, fi->i_extra_isize,
|
if (F2FS_FITS_IN_INODE(ri, fi->i_extra_isize,
|
||||||
i_log_cluster_size)) {
|
i_log_cluster_size)) {
|
||||||
|
unsigned short compress_flag;
|
||||||
|
|
||||||
atomic_set(&fi->i_compr_blocks,
|
atomic_set(&fi->i_compr_blocks,
|
||||||
le64_to_cpu(ri->i_compr_blocks));
|
le64_to_cpu(ri->i_compr_blocks));
|
||||||
fi->i_compress_algorithm = ri->i_compress_algorithm;
|
fi->i_compress_algorithm = ri->i_compress_algorithm;
|
||||||
fi->i_log_cluster_size = ri->i_log_cluster_size;
|
fi->i_log_cluster_size = ri->i_log_cluster_size;
|
||||||
fi->i_compress_flag = le16_to_cpu(ri->i_compress_flag);
|
compress_flag = le16_to_cpu(ri->i_compress_flag);
|
||||||
|
fi->i_compress_level = compress_flag >>
|
||||||
|
COMPRESS_LEVEL_OFFSET;
|
||||||
|
fi->i_compress_flag = compress_flag &
|
||||||
|
(BIT(COMPRESS_LEVEL_OFFSET) - 1);
|
||||||
fi->i_cluster_size = 1 << fi->i_log_cluster_size;
|
fi->i_cluster_size = 1 << fi->i_log_cluster_size;
|
||||||
set_inode_flag(inode, FI_COMPRESSED_FILE);
|
set_inode_flag(inode, FI_COMPRESSED_FILE);
|
||||||
}
|
}
|
||||||
|
|
@ -675,13 +681,17 @@ void f2fs_update_inode(struct inode *inode, struct page *node_page)
|
||||||
if (f2fs_sb_has_compression(F2FS_I_SB(inode)) &&
|
if (f2fs_sb_has_compression(F2FS_I_SB(inode)) &&
|
||||||
F2FS_FITS_IN_INODE(ri, F2FS_I(inode)->i_extra_isize,
|
F2FS_FITS_IN_INODE(ri, F2FS_I(inode)->i_extra_isize,
|
||||||
i_log_cluster_size)) {
|
i_log_cluster_size)) {
|
||||||
|
unsigned short compress_flag;
|
||||||
|
|
||||||
ri->i_compr_blocks =
|
ri->i_compr_blocks =
|
||||||
cpu_to_le64(atomic_read(
|
cpu_to_le64(atomic_read(
|
||||||
&F2FS_I(inode)->i_compr_blocks));
|
&F2FS_I(inode)->i_compr_blocks));
|
||||||
ri->i_compress_algorithm =
|
ri->i_compress_algorithm =
|
||||||
F2FS_I(inode)->i_compress_algorithm;
|
F2FS_I(inode)->i_compress_algorithm;
|
||||||
ri->i_compress_flag =
|
compress_flag = F2FS_I(inode)->i_compress_flag |
|
||||||
cpu_to_le16(F2FS_I(inode)->i_compress_flag);
|
F2FS_I(inode)->i_compress_level <<
|
||||||
|
COMPRESS_LEVEL_OFFSET;
|
||||||
|
ri->i_compress_flag = cpu_to_le16(compress_flag);
|
||||||
ri->i_log_cluster_size =
|
ri->i_log_cluster_size =
|
||||||
F2FS_I(inode)->i_log_cluster_size;
|
F2FS_I(inode)->i_log_cluster_size;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue