* [f2fs-dev] [PATCH 1/2] f2fs: introduce {page, io}_is_mergeable() for readability
@ 2019-07-12 8:55 Chao Yu
2019-07-12 8:55 ` [f2fs-dev] [PATCH 2/2] f2fs: fix panic of IO alignment feature Chao Yu
2019-08-23 3:02 ` [f2fs-dev] [PATCH 1/2] f2fs: introduce {page, io}_is_mergeable() for readability Chao Yu
0 siblings, 2 replies; 5+ messages in thread
From: Chao Yu @ 2019-07-12 8:55 UTC (permalink / raw)
To: jaegeuk; +Cc: linux-kernel, linux-f2fs-devel
Wrap merge condition into function for readability, no logic change.
Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
v2: remove bio validation check in page_is_mergeable().
fs/f2fs/data.c | 40 +++++++++++++++++++++++++++++++++-------
1 file changed, 33 insertions(+), 7 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 6a8db4abdf5f..f1e401f9fc13 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -482,6 +482,33 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
return 0;
}
+static bool page_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio,
+ block_t last_blkaddr, block_t cur_blkaddr)
+{
+ if (last_blkaddr != cur_blkaddr)
+ return false;
+ return __same_bdev(sbi, cur_blkaddr, bio);
+}
+
+static bool io_type_is_mergeable(struct f2fs_bio_info *io,
+ struct f2fs_io_info *fio)
+{
+ if (io->fio.op != fio->op)
+ return false;
+ return io->fio.op_flags == fio->op_flags;
+}
+
+static bool io_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio,
+ struct f2fs_bio_info *io,
+ struct f2fs_io_info *fio,
+ block_t last_blkaddr,
+ block_t cur_blkaddr)
+{
+ if (!page_is_mergeable(sbi, bio, last_blkaddr, cur_blkaddr))
+ return false;
+ return io_type_is_mergeable(io, fio);
+}
+
int f2fs_merge_page_bio(struct f2fs_io_info *fio)
{
struct bio *bio = *fio->bio;
@@ -495,8 +522,8 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
trace_f2fs_submit_page_bio(page, fio);
f2fs_trace_ios(fio, 0);
- if (bio && (*fio->last_block + 1 != fio->new_blkaddr ||
- !__same_bdev(fio->sbi, fio->new_blkaddr, bio))) {
+ if (bio && !page_is_mergeable(fio->sbi, bio, *fio->last_block,
+ fio->new_blkaddr)) {
__submit_bio(fio->sbi, bio, fio->type);
bio = NULL;
}
@@ -569,9 +596,8 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
inc_page_count(sbi, WB_DATA_TYPE(bio_page));
- if (io->bio && (io->last_block_in_bio != fio->new_blkaddr - 1 ||
- (io->fio.op != fio->op || io->fio.op_flags != fio->op_flags) ||
- !__same_bdev(sbi, fio->new_blkaddr, io->bio)))
+ if (io->bio && !io_is_mergeable(sbi, io->bio, io, fio,
+ io->last_block_in_bio, fio->new_blkaddr))
__submit_merged_bio(io);
alloc_new:
if (io->bio == NULL) {
@@ -1643,8 +1669,8 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page,
* This page will go to BIO. Do we need to send this
* BIO off first?
*/
- if (bio && (*last_block_in_bio != block_nr - 1 ||
- !__same_bdev(F2FS_I_SB(inode), block_nr, bio))) {
+ if (bio && !page_is_mergeable(F2FS_I_SB(inode), bio,
+ *last_block_in_bio, block_nr - 1)) {
submit_and_realloc:
__submit_bio(F2FS_I_SB(inode), bio, DATA);
bio = NULL;
--
2.18.0.rc1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [f2fs-dev] [PATCH 2/2] f2fs: fix panic of IO alignment feature
2019-07-12 8:55 [f2fs-dev] [PATCH 1/2] f2fs: introduce {page, io}_is_mergeable() for readability Chao Yu
@ 2019-07-12 8:55 ` Chao Yu
2019-08-23 3:02 ` [f2fs-dev] [PATCH 1/2] f2fs: introduce {page, io}_is_mergeable() for readability Chao Yu
1 sibling, 0 replies; 5+ messages in thread
From: Chao Yu @ 2019-07-12 8:55 UTC (permalink / raw)
To: jaegeuk; +Cc: linux-kernel, linux-f2fs-devel
Since 07173c3ec276 ("block: enable multipage bvecs"), one bio vector
can store multi pages, so that we can not calculate max IO size of
bio as PAGE_SIZE * bio->bi_max_vecs. However IO alignment feature of
f2fs always has that assumption, so finally, it may cause panic during
IO submission as below stack.
kernel BUG at fs/f2fs/data.c:317!
RIP: 0010:__submit_merged_bio+0x8b0/0x8c0
Call Trace:
f2fs_submit_page_write+0x3cd/0xdd0
do_write_page+0x15d/0x360
f2fs_outplace_write_data+0xd7/0x210
f2fs_do_write_data_page+0x43b/0xf30
__write_data_page+0xcf6/0x1140
f2fs_write_cache_pages+0x3ba/0xb40
f2fs_write_data_pages+0x3dd/0x8b0
do_writepages+0xbb/0x1e0
__writeback_single_inode+0xb6/0x800
writeback_sb_inodes+0x441/0x910
wb_writeback+0x261/0x650
wb_workfn+0x1f9/0x7a0
process_one_work+0x503/0x970
worker_thread+0x7d/0x820
kthread+0x1ad/0x210
ret_from_fork+0x35/0x40
This patch adds one extra condition to check left space in bio while
trying merging page to bio, to avoid panic.
This bug was reported in bugzilla:
https://bugzilla.kernel.org/show_bug.cgi?id=204043
Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
v2: add IO type check.
fs/f2fs/data.c | 10 ++++++++++
fs/f2fs/super.c | 2 +-
include/linux/f2fs_fs.h | 1 +
3 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index f1e401f9fc13..1971e59cdedb 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -504,6 +504,16 @@ static bool io_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio,
block_t last_blkaddr,
block_t cur_blkaddr)
{
+ if (F2FS_IO_ALIGNED(sbi) && (fio->type == DATA || fio->type == NODE)) {
+ unsigned int filled_blocks =
+ F2FS_BYTES_TO_BLK(bio->bi_iter.bi_size);
+ unsigned int io_size = F2FS_IO_SIZE(sbi);
+ unsigned int left_vecs = bio->bi_max_vecs - bio->bi_vcnt;
+
+ /* IOs in bio is aligned and left space of vectors is not enough */
+ if (!(filled_blocks % io_size) && left_vecs < io_size)
+ return false;
+ }
if (!page_is_mergeable(sbi, bio, last_blkaddr, cur_blkaddr))
return false;
return io_type_is_mergeable(io, fio);
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index d95a681ef7c9..a98e3b93395d 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -3204,7 +3204,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
if (err)
goto free_bio_info;
- if (F2FS_IO_SIZE(sbi) > 1) {
+ if (F2FS_IO_ALIGNED(sbi)) {
sbi->write_io_dummy =
mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0);
if (!sbi->write_io_dummy) {
diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h
index 65559900d4d7..52af9ac164b4 100644
--- a/include/linux/f2fs_fs.h
+++ b/include/linux/f2fs_fs.h
@@ -41,6 +41,7 @@
#define F2FS_IO_SIZE_BYTES(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 12)) /* B */
#define F2FS_IO_SIZE_BITS(sbi) (F2FS_OPTION(sbi).write_io_size_bits) /* power of 2 */
#define F2FS_IO_SIZE_MASK(sbi) (F2FS_IO_SIZE(sbi) - 1)
+#define F2FS_IO_ALIGNED(sbi) (F2FS_IO_SIZE(sbi) > 1)
/* This flag is used by node and meta inodes, and by recovery */
#define GFP_F2FS_ZERO (GFP_NOFS | __GFP_ZERO)
--
2.18.0.rc1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [f2fs-dev] [PATCH 1/2] f2fs: introduce {page, io}_is_mergeable() for readability
2019-07-12 8:55 [f2fs-dev] [PATCH 1/2] f2fs: introduce {page, io}_is_mergeable() for readability Chao Yu
2019-07-12 8:55 ` [f2fs-dev] [PATCH 2/2] f2fs: fix panic of IO alignment feature Chao Yu
@ 2019-08-23 3:02 ` Chao Yu
2019-08-23 14:57 ` Jaegeuk Kim
1 sibling, 1 reply; 5+ messages in thread
From: Chao Yu @ 2019-08-23 3:02 UTC (permalink / raw)
To: jaegeuk; +Cc: linux-kernel, linux-f2fs-devel
On 2019/7/12 16:55, Chao Yu wrote:
> Wrap merge condition into function for readability, no logic change.
>
> Signed-off-by: Chao Yu <yuchao0@huawei.com>
> ---
> v2: remove bio validation check in page_is_mergeable().
> fs/f2fs/data.c | 40 +++++++++++++++++++++++++++++++++-------
> 1 file changed, 33 insertions(+), 7 deletions(-)
>
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 6a8db4abdf5f..f1e401f9fc13 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -482,6 +482,33 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
> return 0;
> }
>
> +static bool page_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio,
> + block_t last_blkaddr, block_t cur_blkaddr)
> +{
> + if (last_blkaddr != cur_blkaddr)
if (last_blkaddr + 1 != cur_blkaddr)
Merge condition is wrong here.
> + return false;
> + return __same_bdev(sbi, cur_blkaddr, bio);
> +}
> +
> +static bool io_type_is_mergeable(struct f2fs_bio_info *io,
> + struct f2fs_io_info *fio)
> +{
> + if (io->fio.op != fio->op)
> + return false;
> + return io->fio.op_flags == fio->op_flags;
> +}
> +
> +static bool io_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio,
> + struct f2fs_bio_info *io,
> + struct f2fs_io_info *fio,
> + block_t last_blkaddr,
> + block_t cur_blkaddr)
> +{
> + if (!page_is_mergeable(sbi, bio, last_blkaddr, cur_blkaddr))
> + return false;
> + return io_type_is_mergeable(io, fio);
> +}
> +
> int f2fs_merge_page_bio(struct f2fs_io_info *fio)
> {
> struct bio *bio = *fio->bio;
> @@ -495,8 +522,8 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
> trace_f2fs_submit_page_bio(page, fio);
> f2fs_trace_ios(fio, 0);
>
> - if (bio && (*fio->last_block + 1 != fio->new_blkaddr ||
> - !__same_bdev(fio->sbi, fio->new_blkaddr, bio))) {
> + if (bio && !page_is_mergeable(fio->sbi, bio, *fio->last_block,
> + fio->new_blkaddr)) {
> __submit_bio(fio->sbi, bio, fio->type);
> bio = NULL;
> }
> @@ -569,9 +596,8 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
>
> inc_page_count(sbi, WB_DATA_TYPE(bio_page));
>
> - if (io->bio && (io->last_block_in_bio != fio->new_blkaddr - 1 ||
> - (io->fio.op != fio->op || io->fio.op_flags != fio->op_flags) ||
> - !__same_bdev(sbi, fio->new_blkaddr, io->bio)))
> + if (io->bio && !io_is_mergeable(sbi, io->bio, io, fio,
> + io->last_block_in_bio, fio->new_blkaddr))
> __submit_merged_bio(io);
> alloc_new:
> if (io->bio == NULL) {
> @@ -1643,8 +1669,8 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page,
> * This page will go to BIO. Do we need to send this
> * BIO off first?
> */
> - if (bio && (*last_block_in_bio != block_nr - 1 ||
> - !__same_bdev(F2FS_I_SB(inode), block_nr, bio))) {
> + if (bio && !page_is_mergeable(F2FS_I_SB(inode), bio,
> + *last_block_in_bio, block_nr - 1)) {
*last_block_in_bio, block_nr)
Sorry, anyway, let me send v2.
> submit_and_realloc:
> __submit_bio(F2FS_I_SB(inode), bio, DATA);
> bio = NULL;
>
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [f2fs-dev] [PATCH 1/2] f2fs: introduce {page, io}_is_mergeable() for readability
2019-08-23 3:02 ` [f2fs-dev] [PATCH 1/2] f2fs: introduce {page, io}_is_mergeable() for readability Chao Yu
@ 2019-08-23 14:57 ` Jaegeuk Kim
0 siblings, 0 replies; 5+ messages in thread
From: Jaegeuk Kim @ 2019-08-23 14:57 UTC (permalink / raw)
To: Chao Yu; +Cc: linux-kernel, linux-f2fs-devel
On 08/23, Chao Yu wrote:
> On 2019/7/12 16:55, Chao Yu wrote:
> > Wrap merge condition into function for readability, no logic change.
> >
> > Signed-off-by: Chao Yu <yuchao0@huawei.com>
> > ---
> > v2: remove bio validation check in page_is_mergeable().
> > fs/f2fs/data.c | 40 +++++++++++++++++++++++++++++++++-------
> > 1 file changed, 33 insertions(+), 7 deletions(-)
> >
> > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> > index 6a8db4abdf5f..f1e401f9fc13 100644
> > --- a/fs/f2fs/data.c
> > +++ b/fs/f2fs/data.c
> > @@ -482,6 +482,33 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
> > return 0;
> > }
> >
> > +static bool page_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio,
> > + block_t last_blkaddr, block_t cur_blkaddr)
> > +{
> > + if (last_blkaddr != cur_blkaddr)
>
> if (last_blkaddr + 1 != cur_blkaddr)
>
> Merge condition is wrong here.
>
> > + return false;
> > + return __same_bdev(sbi, cur_blkaddr, bio);
> > +}
> > +
> > +static bool io_type_is_mergeable(struct f2fs_bio_info *io,
> > + struct f2fs_io_info *fio)
> > +{
> > + if (io->fio.op != fio->op)
> > + return false;
> > + return io->fio.op_flags == fio->op_flags;
> > +}
> > +
> > +static bool io_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio,
> > + struct f2fs_bio_info *io,
> > + struct f2fs_io_info *fio,
> > + block_t last_blkaddr,
> > + block_t cur_blkaddr)
> > +{
> > + if (!page_is_mergeable(sbi, bio, last_blkaddr, cur_blkaddr))
> > + return false;
> > + return io_type_is_mergeable(io, fio);
> > +}
> > +
> > int f2fs_merge_page_bio(struct f2fs_io_info *fio)
> > {
> > struct bio *bio = *fio->bio;
> > @@ -495,8 +522,8 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
> > trace_f2fs_submit_page_bio(page, fio);
> > f2fs_trace_ios(fio, 0);
> >
> > - if (bio && (*fio->last_block + 1 != fio->new_blkaddr ||
> > - !__same_bdev(fio->sbi, fio->new_blkaddr, bio))) {
> > + if (bio && !page_is_mergeable(fio->sbi, bio, *fio->last_block,
> > + fio->new_blkaddr)) {
> > __submit_bio(fio->sbi, bio, fio->type);
> > bio = NULL;
> > }
> > @@ -569,9 +596,8 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
> >
> > inc_page_count(sbi, WB_DATA_TYPE(bio_page));
> >
> > - if (io->bio && (io->last_block_in_bio != fio->new_blkaddr - 1 ||
> > - (io->fio.op != fio->op || io->fio.op_flags != fio->op_flags) ||
> > - !__same_bdev(sbi, fio->new_blkaddr, io->bio)))
> > + if (io->bio && !io_is_mergeable(sbi, io->bio, io, fio,
> > + io->last_block_in_bio, fio->new_blkaddr))
> > __submit_merged_bio(io);
> > alloc_new:
> > if (io->bio == NULL) {
> > @@ -1643,8 +1669,8 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page,
> > * This page will go to BIO. Do we need to send this
> > * BIO off first?
> > */
> > - if (bio && (*last_block_in_bio != block_nr - 1 ||
> > - !__same_bdev(F2FS_I_SB(inode), block_nr, bio))) {
> > + if (bio && !page_is_mergeable(F2FS_I_SB(inode), bio,
> > + *last_block_in_bio, block_nr - 1)) {
>
> *last_block_in_bio, block_nr)
>
> Sorry, anyway, let me send v2.
Fixed, thanks,
>
> > submit_and_realloc:
> > __submit_bio(F2FS_I_SB(inode), bio, DATA);
> > bio = NULL;
> >
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* [f2fs-dev] [PATCH 1/2] f2fs: introduce {page, io}_is_mergeable() for readability
@ 2019-07-11 10:38 Chao Yu
0 siblings, 0 replies; 5+ messages in thread
From: Chao Yu @ 2019-07-11 10:38 UTC (permalink / raw)
To: jaegeuk; +Cc: linux-kernel, linux-f2fs-devel
Wrap merge condition into function for readability, no logic change.
Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
fs/f2fs/data.c | 42 +++++++++++++++++++++++++++++++++++-------
1 file changed, 35 insertions(+), 7 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 6a8db4a..bdfd8fb 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -482,6 +482,35 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
return 0;
}
+static bool page_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio,
+ block_t last_blkaddr, block_t cur_blkaddr)
+{
+ if (!bio)
+ return true;
+ if (last_blkaddr != cur_blkaddr)
+ return false;
+ return __same_bdev(sbi, cur_blkaddr, bio);
+}
+
+static bool io_type_is_mergeable(struct f2fs_bio_info *io,
+ struct f2fs_io_info *fio)
+{
+ if (io->fio.op != fio->op)
+ return false;
+ return io->fio.op_flags == fio->op_flags;
+}
+
+static bool io_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio,
+ struct f2fs_bio_info *io,
+ struct f2fs_io_info *fio,
+ block_t last_blkaddr,
+ block_t cur_blkaddr)
+{
+ if (!page_is_mergeable(sbi, bio, last_blkaddr, cur_blkaddr))
+ return false;
+ return io_type_is_mergeable(io, fio);
+}
+
int f2fs_merge_page_bio(struct f2fs_io_info *fio)
{
struct bio *bio = *fio->bio;
@@ -495,8 +524,8 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
trace_f2fs_submit_page_bio(page, fio);
f2fs_trace_ios(fio, 0);
- if (bio && (*fio->last_block + 1 != fio->new_blkaddr ||
- !__same_bdev(fio->sbi, fio->new_blkaddr, bio))) {
+ if (!page_is_mergeable(fio->sbi, bio, *fio->last_block,
+ fio->new_blkaddr)) {
__submit_bio(fio->sbi, bio, fio->type);
bio = NULL;
}
@@ -569,9 +598,8 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
inc_page_count(sbi, WB_DATA_TYPE(bio_page));
- if (io->bio && (io->last_block_in_bio != fio->new_blkaddr - 1 ||
- (io->fio.op != fio->op || io->fio.op_flags != fio->op_flags) ||
- !__same_bdev(sbi, fio->new_blkaddr, io->bio)))
+ if (!io_is_mergeable(sbi, io->bio, io, fio,
+ io->last_block_in_bio, fio->new_blkaddr))
__submit_merged_bio(io);
alloc_new:
if (io->bio == NULL) {
@@ -1643,8 +1671,8 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page,
* This page will go to BIO. Do we need to send this
* BIO off first?
*/
- if (bio && (*last_block_in_bio != block_nr - 1 ||
- !__same_bdev(F2FS_I_SB(inode), block_nr, bio))) {
+ if (!page_is_mergeable(F2FS_I_SB(inode), bio,
+ *last_block_in_bio, block_nr - 1)) {
submit_and_realloc:
__submit_bio(F2FS_I_SB(inode), bio, DATA);
bio = NULL;
--
2.7.4
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-08-23 14:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-12 8:55 [f2fs-dev] [PATCH 1/2] f2fs: introduce {page, io}_is_mergeable() for readability Chao Yu
2019-07-12 8:55 ` [f2fs-dev] [PATCH 2/2] f2fs: fix panic of IO alignment feature Chao Yu
2019-08-23 3:02 ` [f2fs-dev] [PATCH 1/2] f2fs: introduce {page, io}_is_mergeable() for readability Chao Yu
2019-08-23 14:57 ` Jaegeuk Kim
-- strict thread matches above, loose matches on Subject: below --
2019-07-11 10:38 Chao Yu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).