From: Zhang Yi <yi.zhang@huawei.com>
To: <linux-ext4@vger.kernel.org>
Cc: <linux-fsdevel@vger.kernel.org>, <tytso@mit.edu>,
<adilger.kernel@dilger.ca>, <jack@suse.cz>, <yi.zhang@huawei.com>,
<yukuai3@huawei.com>
Subject: [RFC PATCH v2 4/7] jbd2: do not free buffers in jbd2_journal_try_to_free_buffers()
Date: Wed, 14 Apr 2021 21:47:34 +0800 [thread overview]
Message-ID: <20210414134737.2366971-5-yi.zhang@huawei.com> (raw)
In-Reply-To: <20210414134737.2366971-1-yi.zhang@huawei.com>
This patch move try_to_free_buffers() out from
jbd2_journal_try_to_free_buffers() to the caller function, it just check
the buffers are JBD2 journal busy or not, and the caller should invoke
try_to_free_buffers() if it want to release page.
Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
---
fs/block_dev.c | 8 +++++---
fs/ext4/inode.c | 6 ++++--
fs/ext4/super.c | 5 +++--
fs/jbd2/transaction.c | 17 ++++++++---------
4 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 09d6f7229db9..5ed79a9063f6 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1735,11 +1735,13 @@ EXPORT_SYMBOL_GPL(blkdev_read_iter);
static int blkdev_releasepage(struct page *page, gfp_t wait)
{
struct super_block *super = BDEV_I(page->mapping->host)->bdev.bd_super;
+ int ret = 0;
if (super && super->s_op->bdev_try_to_free_page)
- return super->s_op->bdev_try_to_free_page(super, page, wait);
-
- return try_to_free_buffers(page);
+ ret = super->s_op->bdev_try_to_free_page(super, page, wait);
+ if (!ret)
+ return try_to_free_buffers(page);
+ return 0;
}
static int blkdev_writepages(struct address_space *mapping,
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 0948a43f1b3d..3211af9c969f 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3301,6 +3301,7 @@ static void ext4_journalled_invalidatepage(struct page *page,
static int ext4_releasepage(struct page *page, gfp_t wait)
{
journal_t *journal = EXT4_JOURNAL(page->mapping->host);
+ int ret = 0;
trace_ext4_releasepage(page);
@@ -3308,9 +3309,10 @@ static int ext4_releasepage(struct page *page, gfp_t wait)
if (PageChecked(page))
return 0;
if (journal)
- return jbd2_journal_try_to_free_buffers(journal, page);
- else
+ ret = jbd2_journal_try_to_free_buffers(journal, page);
+ if (!ret)
return try_to_free_buffers(page);
+ return 0;
}
static bool ext4_inode_datasync_dirty(struct inode *inode)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index b9693680463a..55c7a0d8d77d 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1444,7 +1444,8 @@ static int ext4_nfs_commit_metadata(struct inode *inode)
* Try to release metadata pages (indirect blocks, directories) which are
* mapped via the block device. Since these pages could have journal heads
* which would prevent try_to_free_buffers() from freeing them, we must use
- * jbd2 layer's try_to_free_buffers() function to release them.
+ * jbd2 layer's try_to_free_buffers() function to check and we could
+ * release them if it return 0.
*/
static int bdev_try_to_free_page(struct super_block *sb, struct page *page,
gfp_t wait)
@@ -1457,7 +1458,7 @@ static int bdev_try_to_free_page(struct super_block *sb, struct page *page,
if (journal)
return jbd2_journal_try_to_free_buffers(journal, page);
- return try_to_free_buffers(page);
+ return 0;
}
#ifdef CONFIG_FS_ENCRYPTION
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index 3e0db4953fe4..451798051fde 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -2089,10 +2089,9 @@ __journal_try_to_free_buffer(journal_t *journal, struct buffer_head *bh)
* if they are fully written out ordered data, move them onto BUF_CLEAN
* so try_to_free_buffers() can reap them.
*
- * This function returns non-zero if we wish try_to_free_buffers()
- * to be called. We do this if the page is releasable by try_to_free_buffers().
- * We also do it if the page has locked or dirty buffers and the caller wants
- * us to perform sync or async writeout.
+ * This function returns zero if all the buffers on this page are
+ * journal cleaned and the caller should invoke try_to_free_buffers() and
+ * could release page if the page is releasable by try_to_free_buffers().
*
* This complicates JBD locking somewhat. We aren't protected by the
* BKL here. We wish to remove the buffer from its committing or
@@ -2112,7 +2111,7 @@ __journal_try_to_free_buffer(journal_t *journal, struct buffer_head *bh)
* cannot happen because we never reallocate freed data as metadata
* while the data is part of a transaction. Yes?
*
- * Return 0 on failure, 1 on success
+ * Return 0 on success, -EBUSY if any buffer is still journal busy.
*/
int jbd2_journal_try_to_free_buffers(journal_t *journal, struct page *page)
{
@@ -2140,12 +2139,12 @@ int jbd2_journal_try_to_free_buffers(journal_t *journal, struct page *page)
__journal_try_to_free_buffer(journal, bh);
spin_unlock(&jh->b_state_lock);
jbd2_journal_put_journal_head(jh);
- if (buffer_jbd(bh))
- goto busy;
+ if (buffer_jbd(bh)) {
+ ret = -EBUSY;
+ break;
+ }
} while ((bh = bh->b_this_page) != head);
- ret = try_to_free_buffers(page);
-busy:
return ret;
}
--
2.25.4
next prev parent reply other threads:[~2021-04-14 13:39 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-14 13:47 [RFC PATCH v2 0/7] ext4, jbd2: fix 3 issues about bdev_try_to_free_page() Zhang Yi
2021-04-14 13:47 ` [RFC PATCH v2 1/7] jbd2: remove the out label in __jbd2_journal_remove_checkpoint() Zhang Yi
2021-04-21 10:01 ` Jan Kara
2021-04-14 13:47 ` [RFC PATCH v2 2/7] jbd2: ensure abort the journal if detect IO error when writing original buffer back Zhang Yi
2021-04-21 13:20 ` Jan Kara
2021-04-14 13:47 ` [RFC PATCH v2 3/7] jbd2: don't abort the journal when freeing buffers Zhang Yi
2021-04-21 13:23 ` Jan Kara
2021-04-14 13:47 ` Zhang Yi [this message]
2021-04-15 14:46 ` [RFC PATCH v2 4/7] jbd2: do not free buffers in jbd2_journal_try_to_free_buffers() Christoph Hellwig
2021-04-14 13:47 ` [RFC PATCH v2 5/7] ext4: use RCU to protect accessing superblock in blkdev_releasepage() Zhang Yi
2021-04-15 14:48 ` Christoph Hellwig
2021-04-14 13:47 ` [RFC PATCH v2 6/7] fs: introduce a usage count into the superblock Zhang Yi
2021-04-15 14:40 ` Christoph Hellwig
2021-04-16 8:00 ` Zhang Yi
2021-04-14 13:47 ` [RFC PATCH v2 7/7] ext4: fix race between blkdev_releasepage() and ext4_put_super() Zhang Yi
2021-04-15 14:52 ` Christoph Hellwig
2021-04-16 8:00 ` Zhang Yi
2021-04-20 13:08 ` Christoph Hellwig
2021-04-21 13:46 ` Jan Kara
2021-04-21 16:57 ` Theodore Ts'o
2021-04-22 9:04 ` Jan Kara
2021-04-23 11:39 ` Zhang Yi
2021-04-23 16:06 ` Jan Kara
2021-04-23 14:40 ` Theodore Ts'o
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=20210414134737.2366971-5-yi.zhang@huawei.com \
--to=yi.zhang@huawei.com \
--cc=adilger.kernel@dilger.ca \
--cc=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=yukuai3@huawei.com \
/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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).