From: Chao Yu <yuchao0@huawei.com> To: <jaegeuk@kernel.org> Cc: <linux-f2fs-devel@lists.sourceforge.net>, <linux-kernel@vger.kernel.org>, <chao@kernel.org>, Chao Yu <yuchao0@huawei.com> Subject: [PATCH 3/5] f2fs: shrink node_write lock coverage Date: Thu, 18 Jun 2020 14:36:23 +0800 [thread overview] Message-ID: <20200618063625.110273-3-yuchao0@huawei.com> (raw) In-Reply-To: <20200618063625.110273-1-yuchao0@huawei.com> - to avoid race between checkpoint and quota file writeback, it just needs to hold read lock of node_write in writeback path. - node_write lock has covered all LFS data write paths, it's not necessary, we only need to hold node_write lock at write path of quota file. Signed-off-by: Chao Yu <yuchao0@huawei.com> --- fs/f2fs/compress.c | 18 +++++++++++++++--- fs/f2fs/data.c | 12 ++++++++++++ fs/f2fs/segment.c | 11 ----------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index 36b51795b0c3..3ff6c0305ec6 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1096,8 +1096,16 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc, loff_t psize; int i, err; - if (!IS_NOQUOTA(inode) && !f2fs_trylock_op(sbi)) + if (IS_NOQUOTA(inode)) { + /* + * We need to wait for node_write to avoid block allocation during + * checkpoint. This can only happen to quota writes which can cause + * the below discard race condition. + */ + down_read(&sbi->node_write); + } else if (!f2fs_trylock_op(sbi)) { return -EAGAIN; + } set_new_dnode(&dn, cc->inode, NULL, NULL, 0); @@ -1203,7 +1211,9 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc, set_inode_flag(inode, FI_FIRST_BLOCK_WRITTEN); f2fs_put_dnode(&dn); - if (!IS_NOQUOTA(inode)) + if (IS_NOQUOTA(inode)) + up_read(&sbi->node_write); + else f2fs_unlock_op(sbi); spin_lock(&fi->i_size_lock); @@ -1230,7 +1240,9 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc, out_put_dnode: f2fs_put_dnode(&dn); out_unlock_op: - if (!IS_NOQUOTA(inode)) + if (IS_NOQUOTA(inode)) + up_read(&sbi->node_write); + else f2fs_unlock_op(sbi); return -EAGAIN; } diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index c78ce08f6400..cbdf062d3562 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2719,8 +2719,20 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, /* Dentry/quota blocks are controlled by checkpoint */ if (S_ISDIR(inode->i_mode) || IS_NOQUOTA(inode)) { + /* + * We need to wait for node_write to avoid block allocation during + * checkpoint. This can only happen to quota writes which can cause + * the below discard race condition. + */ + if (IS_NOQUOTA(inode)) + down_read(&sbi->node_write); + fio.need_lock = LOCK_DONE; err = f2fs_do_write_data_page(&fio); + + if (IS_NOQUOTA(inode)) + up_read(&sbi->node_write); + goto done; } diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 5b2a6f865a6d..cb861ed98ee3 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -3107,14 +3107,6 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, type = CURSEG_COLD_DATA; } - /* - * We need to wait for node_write to avoid block allocation during - * checkpoint. This can only happen to quota writes which can cause - * the below discard race condition. - */ - if (IS_DATASEG(type)) - down_write(&sbi->node_write); - down_read(&SM_I(sbi)->curseg_lock); mutex_lock(&curseg->curseg_mutex); @@ -3180,9 +3172,6 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, up_read(&SM_I(sbi)->curseg_lock); - if (IS_DATASEG(type)) - up_write(&sbi->node_write); - if (put_pin_sem) up_read(&sbi->pin_sem); } -- 2.18.0.rc1
WARNING: multiple messages have this Message-ID (diff)
From: Chao Yu <yuchao0@huawei.com> To: <jaegeuk@kernel.org> Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: [f2fs-dev] [PATCH 3/5] f2fs: shrink node_write lock coverage Date: Thu, 18 Jun 2020 14:36:23 +0800 [thread overview] Message-ID: <20200618063625.110273-3-yuchao0@huawei.com> (raw) In-Reply-To: <20200618063625.110273-1-yuchao0@huawei.com> - to avoid race between checkpoint and quota file writeback, it just needs to hold read lock of node_write in writeback path. - node_write lock has covered all LFS data write paths, it's not necessary, we only need to hold node_write lock at write path of quota file. Signed-off-by: Chao Yu <yuchao0@huawei.com> --- fs/f2fs/compress.c | 18 +++++++++++++++--- fs/f2fs/data.c | 12 ++++++++++++ fs/f2fs/segment.c | 11 ----------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index 36b51795b0c3..3ff6c0305ec6 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1096,8 +1096,16 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc, loff_t psize; int i, err; - if (!IS_NOQUOTA(inode) && !f2fs_trylock_op(sbi)) + if (IS_NOQUOTA(inode)) { + /* + * We need to wait for node_write to avoid block allocation during + * checkpoint. This can only happen to quota writes which can cause + * the below discard race condition. + */ + down_read(&sbi->node_write); + } else if (!f2fs_trylock_op(sbi)) { return -EAGAIN; + } set_new_dnode(&dn, cc->inode, NULL, NULL, 0); @@ -1203,7 +1211,9 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc, set_inode_flag(inode, FI_FIRST_BLOCK_WRITTEN); f2fs_put_dnode(&dn); - if (!IS_NOQUOTA(inode)) + if (IS_NOQUOTA(inode)) + up_read(&sbi->node_write); + else f2fs_unlock_op(sbi); spin_lock(&fi->i_size_lock); @@ -1230,7 +1240,9 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc, out_put_dnode: f2fs_put_dnode(&dn); out_unlock_op: - if (!IS_NOQUOTA(inode)) + if (IS_NOQUOTA(inode)) + up_read(&sbi->node_write); + else f2fs_unlock_op(sbi); return -EAGAIN; } diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index c78ce08f6400..cbdf062d3562 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2719,8 +2719,20 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, /* Dentry/quota blocks are controlled by checkpoint */ if (S_ISDIR(inode->i_mode) || IS_NOQUOTA(inode)) { + /* + * We need to wait for node_write to avoid block allocation during + * checkpoint. This can only happen to quota writes which can cause + * the below discard race condition. + */ + if (IS_NOQUOTA(inode)) + down_read(&sbi->node_write); + fio.need_lock = LOCK_DONE; err = f2fs_do_write_data_page(&fio); + + if (IS_NOQUOTA(inode)) + up_read(&sbi->node_write); + goto done; } diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 5b2a6f865a6d..cb861ed98ee3 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -3107,14 +3107,6 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, type = CURSEG_COLD_DATA; } - /* - * We need to wait for node_write to avoid block allocation during - * checkpoint. This can only happen to quota writes which can cause - * the below discard race condition. - */ - if (IS_DATASEG(type)) - down_write(&sbi->node_write); - down_read(&SM_I(sbi)->curseg_lock); mutex_lock(&curseg->curseg_mutex); @@ -3180,9 +3172,6 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, up_read(&SM_I(sbi)->curseg_lock); - if (IS_DATASEG(type)) - up_write(&sbi->node_write); - if (put_pin_sem) up_read(&sbi->pin_sem); } -- 2.18.0.rc1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next prev parent reply other threads:[~2020-06-18 6:37 UTC|newest] Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-18 6:36 [PATCH 1/5] f2fs: fix to wait page writeback before update Chao Yu 2020-06-18 6:36 ` [f2fs-dev] " Chao Yu 2020-06-18 6:36 ` [PATCH 2/5] f2fs: add prefix for exported symbols Chao Yu 2020-06-18 6:36 ` [f2fs-dev] " Chao Yu 2020-06-18 6:36 ` Chao Yu [this message] 2020-06-18 6:36 ` [f2fs-dev] [PATCH 3/5] f2fs: shrink node_write lock coverage Chao Yu 2020-06-19 5:56 ` Jaegeuk Kim 2020-06-19 5:56 ` [f2fs-dev] " Jaegeuk Kim 2020-06-18 6:36 ` [PATCH 4/5] f2fs: clean up parameter of f2fs_allocate_data_block() Chao Yu 2020-06-18 6:36 ` [f2fs-dev] " Chao Yu 2020-06-18 6:36 ` [PATCH 5/5] f2fs: show more debug info for per-temperature log Chao Yu 2020-06-18 6:36 ` [f2fs-dev] " Chao Yu 2020-06-24 22:31 ` Jaegeuk Kim 2020-06-24 22:31 ` [f2fs-dev] " Jaegeuk Kim 2020-06-28 1:35 ` Chao Yu 2020-06-28 1:35 ` [f2fs-dev] " Chao Yu 2020-06-18 23:59 ` [PATCH 1/5] f2fs: fix to wait page writeback before update Jaegeuk Kim 2020-06-18 23:59 ` [f2fs-dev] " Jaegeuk Kim 2020-06-19 1:44 ` Chao Yu 2020-06-19 1:44 ` [f2fs-dev] " Chao Yu 2020-06-19 5:49 ` Jaegeuk Kim 2020-06-19 5:49 ` [f2fs-dev] " Jaegeuk Kim 2020-06-19 6:44 ` Chao Yu 2020-06-19 6:44 ` [f2fs-dev] " Chao Yu 2020-06-19 22:47 ` Jaegeuk Kim 2020-06-19 22:47 ` [f2fs-dev] " Jaegeuk Kim 2020-06-20 0:52 ` Chao Yu 2020-06-20 0:52 ` [f2fs-dev] " Chao Yu 2020-06-21 16:38 ` Jaegeuk Kim 2020-06-21 16:38 ` [f2fs-dev] " Jaegeuk Kim 2020-06-22 0:51 ` Chao Yu 2020-06-22 0:51 ` [f2fs-dev] " Chao Yu 2020-06-24 15:55 ` Jaegeuk Kim 2020-06-24 15:55 ` [f2fs-dev] " Jaegeuk Kim 2020-06-28 1:26 ` Chao Yu 2020-06-28 1:26 ` [f2fs-dev] " Chao Yu 2024-03-08 6:20 ` Chao Yu 2024-03-08 6:20 ` Chao Yu
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200618063625.110273-3-yuchao0@huawei.com \ --to=yuchao0@huawei.com \ --cc=chao@kernel.org \ --cc=jaegeuk@kernel.org \ --cc=linux-f2fs-devel@lists.sourceforge.net \ --cc=linux-kernel@vger.kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.