Commit 2eae077e authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

f2fs: reduce stack memory cost by using bitfield in struct f2fs_io_info

This patch tries to use bitfield in struct f2fs_io_info to improve
memory usage.

struct f2fs_io_info {
...
	unsigned int need_lock:8;	/* indicate we need to lock cp_rwsem */
	unsigned int version:8;		/* version of the node */
	unsigned int submitted:1;	/* indicate IO submission */
	unsigned int in_list:1;		/* indicate fio is in io_list */
	unsigned int is_por:1;		/* indicate IO is from recovery or not */
	unsigned int retry:1;		/* need to reallocate block address */
	unsigned int encrypted:1;	/* indicate file is encrypted */
	unsigned int post_read:1;	/* require post read */
...
};

After this patch, size of struct f2fs_io_info reduces from 136 to 120.

[Nathan: fix a compile warning (single-bit-bitfield-constant-conversion)]
Signed-off-by: default avatarNathan Chancellor <nathan@kernel.org>
Signed-off-by: default avatarChao Yu <chao@kernel.org>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent a28bca0f
...@@ -70,7 +70,7 @@ static struct page *__get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index, ...@@ -70,7 +70,7 @@ static struct page *__get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index,
.old_blkaddr = index, .old_blkaddr = index,
.new_blkaddr = index, .new_blkaddr = index,
.encrypted_page = NULL, .encrypted_page = NULL,
.is_por = !is_meta, .is_por = !is_meta ? 1 : 0,
}; };
int err; int err;
...@@ -237,8 +237,8 @@ int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, ...@@ -237,8 +237,8 @@ int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages,
.op = REQ_OP_READ, .op = REQ_OP_READ,
.op_flags = sync ? (REQ_META | REQ_PRIO) : REQ_RAHEAD, .op_flags = sync ? (REQ_META | REQ_PRIO) : REQ_RAHEAD,
.encrypted_page = NULL, .encrypted_page = NULL,
.in_list = false, .in_list = 0,
.is_por = (type == META_POR), .is_por = (type == META_POR) ? 1 : 0,
}; };
struct blk_plug plug; struct blk_plug plug;
int err; int err;
......
...@@ -1213,10 +1213,11 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc, ...@@ -1213,10 +1213,11 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
.page = NULL, .page = NULL,
.encrypted_page = NULL, .encrypted_page = NULL,
.compressed_page = NULL, .compressed_page = NULL,
.submitted = false, .submitted = 0,
.io_type = io_type, .io_type = io_type,
.io_wbc = wbc, .io_wbc = wbc,
.encrypted = fscrypt_inode_uses_fs_layer_crypto(cc->inode), .encrypted = fscrypt_inode_uses_fs_layer_crypto(cc->inode) ?
1 : 0,
}; };
struct dnode_of_data dn; struct dnode_of_data dn;
struct node_info ni; struct node_info ni;
......
...@@ -992,7 +992,7 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) ...@@ -992,7 +992,7 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
bio_page = fio->page; bio_page = fio->page;
/* set submitted = true as a return value */ /* set submitted = true as a return value */
fio->submitted = true; fio->submitted = 1;
inc_page_count(sbi, WB_DATA_TYPE(bio_page)); inc_page_count(sbi, WB_DATA_TYPE(bio_page));
...@@ -1008,7 +1008,7 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) ...@@ -1008,7 +1008,7 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
(fio->type == DATA || fio->type == NODE) && (fio->type == DATA || fio->type == NODE) &&
fio->new_blkaddr & F2FS_IO_SIZE_MASK(sbi)) { fio->new_blkaddr & F2FS_IO_SIZE_MASK(sbi)) {
dec_page_count(sbi, WB_DATA_TYPE(bio_page)); dec_page_count(sbi, WB_DATA_TYPE(bio_page));
fio->retry = true; fio->retry = 1;
goto skip; goto skip;
} }
io->bio = __bio_alloc(fio, BIO_MAX_VECS); io->bio = __bio_alloc(fio, BIO_MAX_VECS);
...@@ -2776,10 +2776,10 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, ...@@ -2776,10 +2776,10 @@ int f2fs_write_single_data_page(struct page *page, int *submitted,
.old_blkaddr = NULL_ADDR, .old_blkaddr = NULL_ADDR,
.page = page, .page = page,
.encrypted_page = NULL, .encrypted_page = NULL,
.submitted = false, .submitted = 0,
.compr_blocks = compr_blocks, .compr_blocks = compr_blocks,
.need_lock = LOCK_RETRY, .need_lock = LOCK_RETRY,
.post_read = f2fs_post_read_required(inode), .post_read = f2fs_post_read_required(inode) ? 1 : 0,
.io_type = io_type, .io_type = io_type,
.io_wbc = wbc, .io_wbc = wbc,
.bio = bio, .bio = bio,
...@@ -2900,7 +2900,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, ...@@ -2900,7 +2900,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted,
} }
if (submitted) if (submitted)
*submitted = fio.submitted ? 1 : 0; *submitted = fio.submitted;
return 0; return 0;
......
...@@ -1210,19 +1210,19 @@ struct f2fs_io_info { ...@@ -1210,19 +1210,19 @@ struct f2fs_io_info {
struct page *encrypted_page; /* encrypted page */ struct page *encrypted_page; /* encrypted page */
struct page *compressed_page; /* compressed page */ struct page *compressed_page; /* compressed page */
struct list_head list; /* serialize IOs */ struct list_head list; /* serialize IOs */
bool submitted; /* indicate IO submission */ unsigned int compr_blocks; /* # of compressed block addresses */
int need_lock; /* indicate we need to lock cp_rwsem */ unsigned int need_lock:8; /* indicate we need to lock cp_rwsem */
bool in_list; /* indicate fio is in io_list */ unsigned int version:8; /* version of the node */
bool is_por; /* indicate IO is from recovery or not */ unsigned int submitted:1; /* indicate IO submission */
bool retry; /* need to reallocate block address */ unsigned int in_list:1; /* indicate fio is in io_list */
int compr_blocks; /* # of compressed block addresses */ unsigned int is_por:1; /* indicate IO is from recovery or not */
bool encrypted; /* indicate file is encrypted */ unsigned int retry:1; /* need to reallocate block address */
bool post_read; /* require post read */ unsigned int encrypted:1; /* indicate file is encrypted */
unsigned int post_read:1; /* require post read */
enum iostat_type io_type; /* io type */ enum iostat_type io_type; /* io type */
struct writeback_control *io_wbc; /* writeback control */ struct writeback_control *io_wbc; /* writeback control */
struct bio **bio; /* bio for ipu */ struct bio **bio; /* bio for ipu */
sector_t *last_block; /* last block number in bio */ sector_t *last_block; /* last block number in bio */
unsigned char version; /* version of the node */
}; };
struct bio_entry { struct bio_entry {
......
...@@ -1156,8 +1156,8 @@ static int ra_data_block(struct inode *inode, pgoff_t index) ...@@ -1156,8 +1156,8 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
.op = REQ_OP_READ, .op = REQ_OP_READ,
.op_flags = 0, .op_flags = 0,
.encrypted_page = NULL, .encrypted_page = NULL,
.in_list = false, .in_list = 0,
.retry = false, .retry = 0,
}; };
int err; int err;
...@@ -1245,8 +1245,8 @@ static int move_data_block(struct inode *inode, block_t bidx, ...@@ -1245,8 +1245,8 @@ static int move_data_block(struct inode *inode, block_t bidx,
.op = REQ_OP_READ, .op = REQ_OP_READ,
.op_flags = 0, .op_flags = 0,
.encrypted_page = NULL, .encrypted_page = NULL,
.in_list = false, .in_list = 0,
.retry = false, .retry = 0,
}; };
struct dnode_of_data dn; struct dnode_of_data dn;
struct f2fs_summary sum; struct f2fs_summary sum;
......
...@@ -1586,7 +1586,7 @@ static int __write_node_page(struct page *page, bool atomic, bool *submitted, ...@@ -1586,7 +1586,7 @@ static int __write_node_page(struct page *page, bool atomic, bool *submitted,
.op_flags = wbc_to_write_flags(wbc), .op_flags = wbc_to_write_flags(wbc),
.page = page, .page = page,
.encrypted_page = NULL, .encrypted_page = NULL,
.submitted = false, .submitted = 0,
.io_type = io_type, .io_type = io_type,
.io_wbc = wbc, .io_wbc = wbc,
}; };
......
...@@ -3314,10 +3314,10 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, ...@@ -3314,10 +3314,10 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
struct f2fs_bio_info *io; struct f2fs_bio_info *io;
if (F2FS_IO_ALIGNED(sbi)) if (F2FS_IO_ALIGNED(sbi))
fio->retry = false; fio->retry = 0;
INIT_LIST_HEAD(&fio->list); INIT_LIST_HEAD(&fio->list);
fio->in_list = true; fio->in_list = 1;
io = sbi->write_io[fio->type] + fio->temp; io = sbi->write_io[fio->type] + fio->temp;
spin_lock(&io->io_lock); spin_lock(&io->io_lock);
list_add_tail(&fio->list, &io->io_list); list_add_tail(&fio->list, &io->io_list);
...@@ -3398,7 +3398,7 @@ void f2fs_do_write_meta_page(struct f2fs_sb_info *sbi, struct page *page, ...@@ -3398,7 +3398,7 @@ void f2fs_do_write_meta_page(struct f2fs_sb_info *sbi, struct page *page,
.new_blkaddr = page->index, .new_blkaddr = page->index,
.page = page, .page = page,
.encrypted_page = NULL, .encrypted_page = NULL,
.in_list = false, .in_list = 0,
}; };
if (unlikely(page->index >= MAIN_BLKADDR(sbi))) if (unlikely(page->index >= MAIN_BLKADDR(sbi)))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment