From: Zhang Yi <yizhang089@gmail.com>
To: Ojaswin Mujoo <ojaswin@linux.ibm.com>,
Zhang Yi <yi.zhang@huaweicloud.com>
Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, tytso@mit.edu,
adilger.kernel@dilger.ca, libaokun@linux.alibaba.com,
jack@suse.cz, ritesh.list@gmail.com, djwong@kernel.org,
hch@infradead.org, yi.zhang@huawei.com, yangerkun@huawei.com,
yukuai@fnnas.com
Subject: Re: [PATCH v4 04/23] ext4: add iomap address space operations for buffered I/O
Date: Wed, 20 May 2026 10:49:50 +0800 [thread overview]
Message-ID: <51b3f8d5-b90f-49fe-b93e-171268db9ff8@gmail.com> (raw)
In-Reply-To: <agyVb1U0US8PVgqo@li-dc0c254c-257c-11b2-a85c-98b6c1322444.ibm.com>
On 5/20/2026 12:53 AM, Ojaswin Mujoo wrote:
> On Tue, May 19, 2026 at 08:35:51PM +0800, Zhang Yi wrote:
>> On 5/19/2026 5:28 PM, Ojaswin Mujoo wrote:
>>> On Mon, May 11, 2026 at 03:23:24PM +0800, Zhang Yi wrote:
>>>> From: Zhang Yi <yi.zhang@huawei.com>
>>>>
>>>> Introduce initial support for iomap in the buffered I/O path for regular
>>>> files on ext4.
>>>>
>>>> - Add a new inode state flag EXT4_STATE_BUFFERED_IOMAP to indicate the
>>>> inode uses iomap instead of buffer_head for buffered I/O
>>>> - Add helper ext4_inode_buffered_iomap() to check the flag
>>>> - Add new address space operations ext4_iomap_aops with callbacks that
>>>> will use generic iomap implementations
>>>> - Add ext4_iomap_aops to ext4_set_aops() when the flag is set
>>>>
>>>> The following callbacks(read_folio(), readahead(), writepages()) are
>>>> provided as placeholders and will be implemented in later patches.
>>>>
>>>> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
>>>> Reviewed-by: Jan Kara <jack@suse.cz>
>>>
>>> Hi Zhang, looks good to me. Just a questions below:
>>
>> Hi, Ojaswin! Thank you for the review of this series.
>>
>>>> ---
>>>> fs/ext4/ext4.h | 7 +++++++
>>>> fs/ext4/inode.c | 32 ++++++++++++++++++++++++++++++++
>>>> 2 files changed, 39 insertions(+)
>>>>
>>>> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
>>>> index 94283a991e5c..1e27d73d7427 100644
>>>> --- a/fs/ext4/ext4.h
>>>> +++ b/fs/ext4/ext4.h
>>>> @@ -1972,6 +1972,7 @@ enum {
>>>> EXT4_STATE_FC_COMMITTING, /* Fast commit ongoing */
>>>> EXT4_STATE_FC_FLUSHING_DATA, /* Fast commit flushing data */
>>>> EXT4_STATE_ORPHAN_FILE, /* Inode orphaned in orphan file */
>>>> + EXT4_STATE_BUFFERED_IOMAP, /* Inode use iomap for buffered IO */
>>>> };
>>>>
>>>> #define EXT4_INODE_BIT_FNS(name, field, offset) \
>>>> @@ -2040,6 +2041,12 @@ static inline bool ext4_inode_orphan_tracked(struct inode *inode)
>>>> !list_empty(&EXT4_I(inode)->i_orphan);
>>>> }
>>>>
>>>> +/* Whether the inode pass through the iomap infrastructure for buffered I/O */
>>>> +static inline bool ext4_inode_buffered_iomap(struct inode *inode)
>>>> +{
>>>> + return ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP);
>>>> +}
>>>> +
>>>> /*
>>>> * Codes for operating systems
>>>> */
>>>> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
>>>> index b1ef706987c3..178ac2be37b7 100644
>>>> --- a/fs/ext4/inode.c
>>>> +++ b/fs/ext4/inode.c
>>>> @@ -3908,6 +3908,22 @@ const struct iomap_ops ext4_iomap_report_ops = {
>>>> .iomap_begin = ext4_iomap_begin_report,
>>>> };
>>>>
>>>> +static int ext4_iomap_read_folio(struct file *file, struct folio *folio)
>>>> +{
>>>> + return 0;
>>>> +}
>>>> +
>>>> +static void ext4_iomap_readahead(struct readahead_control *rac)
>>>> +{
>>>> +
>>>> +}
>>>> +
>>>> +static int ext4_iomap_writepages(struct address_space *mapping,
>>>> + struct writeback_control *wbc)
>>>> +{
>>>> + return 0;
>>>> +}
>>>> +
>>>> /*
>>>> * For data=journal mode, folio should be marked dirty only when it was
>>>> * writeably mapped. When that happens, it was already attached to the
>>>> @@ -3994,6 +4010,20 @@ static const struct address_space_operations ext4_da_aops = {
>>>> .swap_activate = ext4_iomap_swap_activate,
>>>> };
>>>>
>>>> +static const struct address_space_operations ext4_iomap_aops = {
>>>> + .read_folio = ext4_iomap_read_folio,
>>>> + .readahead = ext4_iomap_readahead,
>>>> + .writepages = ext4_iomap_writepages,
>>>> + .dirty_folio = iomap_dirty_folio,
>>>> + .bmap = ext4_bmap,
>>>> + .invalidate_folio = iomap_invalidate_folio,
>>>> + .release_folio = iomap_release_folio,
>>>> + .migrate_folio = filemap_migrate_folio,
>>>> + .is_partially_uptodate = iomap_is_partially_uptodate,
>>>> + .error_remove_folio = generic_error_remove_folio,
>>>> + .swap_activate = ext4_iomap_swap_activate,
>>>> +};
>>>
>>> So one question, for ->release_folio() we are using
>>> iomap_release_folio() instead of ext4_release_folio() here which doesnt
>>> make the jbd2_journal_try_to_free_bufferes() call. IIUC this function
>>> seems to be trying to clean up already checkpointed buffers.
>>>
>>> I wanted to check if ->release_folio() can be called for folios with
>>> ext4 metadata buffers? (from my limited understanding of
>>> shrink_folio_list() -> filemap_release_folio() it seems we can) And if
>>> it can be called, is it okay to skip the
>>> jbd2_journal_try_to_free_buffers call?
>>
>> Here, in ->release_folio(), folio->mapping points to inode->i_data (the
>> file's pagecache), not the block device's pagecache. ext4 metadata
>> resides in the block device's pagecache, which is at a different layer
>> than this release_folio callback. So we don't need to call
>> jbd2_journal_try_to_free_buffers() in the iomap path here.
>
> Hi Yi,
>
> Thanks for clarify and yes, thats what I was missing! So this
> ->release_folio() is only for data folios. So I guess the
> jbd2_journal_try_to_free_buffers() is mostly to handle data=journal
> case?
Yes, that's my understanding as well. Meanwhile, the comment for the
jbd2_journal_try_to_free_buffers() function looks quite outdated and
needs to be updated.
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index 4885903bbd10..239bcf88ed1c 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -2139,38 +2139,23 @@ static void __jbd2_journal_unfile_buffer(struct
journal_head *jh)
}
/**
- * jbd2_journal_try_to_free_buffers() - try to free page buffers.
+ * jbd2_journal_try_to_free_buffers() - try to free folio buffers.
* @journal: journal for operation
* @folio: Folio to detach data from.
*
- * For all the buffers on this page,
- * if they are fully written out ordered data, move them onto BUF_CLEAN
- * so try_to_free_buffers() can reap them.
+ * For each buffer_head on @folio, if the buffer has a journal_head but
+ * is not attached to a running or committing transaction, try to remove
+ * it from the checkpoint list. This is needed for data=journal mode
+ * where data buffers are journaled: once they are checkpointed, the
+ * journal_head can be detached and the buffer freed. If any buffer is
+ * still attached to a transaction, the folio cannot be released and we
+ * bail out. Otherwise we call try_to_free_buffers() to detach all
+ * buffer_heads from the folio.
*
- * 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.
+ * For data=ordered and writeback modes, data buffers never have
+ * journal_heads, so this degenerates to a plain 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
- * running transaction's ->t_datalist via __jbd2_journal_unfile_buffer.
- *
- * This may *change* the value of transaction_t->t_datalist, so anyone
- * who looks at t_datalist needs to lock against this function.
- *
- * Even worse, someone may be doing a jbd2_journal_dirty_data on this
- * buffer. So we need to lock against that. jbd2_journal_dirty_data()
- * will come out of the lock with the buffer dirty, which makes it
- * ineligible for release here.
- *
- * Who else is affected by this? hmm... Really the only contender
- * is do_get_write_access() - it could be looking at the buffer while
- * journal_try_to_free_buffer() is changing its state. But that
- * cannot happen because we never reallocate freed data as metadata
- * while the data is part of a transaction. Yes?
- *
- * Return false on failure, true on success
+ * Return: true if the folio's buffers were freed, false otherwise
*/
bool jbd2_journal_try_to_free_buffers(journal_t *journal, struct folio
*folio)
{
Thanks,
Yi.
next prev parent reply other threads:[~2026-05-20 2:50 UTC|newest]
Thread overview: 85+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-11 7:23 [PATCH v4 00/23] ext4: use iomap for regular file's buffered I/O path Zhang Yi
2026-05-11 7:23 ` [PATCH v4 01/23] ext4: simplify size updating in ext4_setattr() Zhang Yi
2026-05-19 5:24 ` Ojaswin Mujoo
2026-05-11 7:23 ` [PATCH v4 02/23] ext4: factor out ext4_truncate_[up|down]() Zhang Yi
2026-05-19 6:05 ` Ojaswin Mujoo
2026-06-16 9:31 ` Jan Kara
2026-05-11 7:23 ` [PATCH v4 03/23] ext4: simplify error handling in ext4_setattr() Zhang Yi
2026-05-19 6:08 ` Ojaswin Mujoo
2026-06-16 9:36 ` Jan Kara
2026-05-11 7:23 ` [PATCH v4 04/23] ext4: add iomap address space operations for buffered I/O Zhang Yi
2026-05-19 9:28 ` Ojaswin Mujoo
2026-05-19 12:35 ` Zhang Yi
2026-05-19 16:53 ` Ojaswin Mujoo
2026-05-20 2:49 ` Zhang Yi [this message]
2026-05-26 17:11 ` Ojaswin Mujoo
2026-05-11 7:23 ` [PATCH v4 05/23] ext4: implement buffered read path using iomap Zhang Yi
2026-05-19 10:00 ` Ojaswin Mujoo
2026-05-11 7:23 ` [PATCH v4 06/23] ext4: pass out extent seq counter when mapping da blocks Zhang Yi
2026-05-19 10:02 ` Ojaswin Mujoo
2026-06-16 10:04 ` Jan Kara
2026-06-16 12:37 ` Zhang Yi
2026-05-11 7:23 ` [PATCH v4 07/23] ext4: do not use data=ordered mode for inodes using buffered iomap path Zhang Yi
2026-05-19 10:41 ` Ojaswin Mujoo
2026-05-19 13:31 ` Ojaswin Mujoo
2026-05-20 8:18 ` Zhang Yi
2026-05-20 13:17 ` Ojaswin Mujoo
2026-06-16 10:01 ` Jan Kara
2026-05-11 7:23 ` [PATCH v4 08/23] ext4: implement buffered write path using iomap Zhang Yi
2026-05-26 17:10 ` Ojaswin Mujoo
2026-05-28 15:40 ` Darrick J. Wong
2026-06-02 7:02 ` Ojaswin Mujoo
2026-05-29 9:13 ` Zhang Yi
2026-06-02 10:05 ` Ojaswin Mujoo
2026-06-03 1:44 ` Zhang Yi
2026-06-02 10:26 ` Ojaswin Mujoo
2026-06-03 2:56 ` Zhang Yi
2026-06-03 11:08 ` Ojaswin Mujoo
2026-06-16 10:45 ` Jan Kara
2026-06-16 14:42 ` Zhang Yi
2026-05-11 7:23 ` [PATCH v4 09/23] ext4: implement writeback " Zhang Yi
2026-05-27 12:49 ` Ojaswin Mujoo
2026-05-29 14:12 ` Zhang Yi
2026-05-29 15:32 ` Ojaswin Mujoo
2026-05-30 1:21 ` Zhang Yi
2026-06-01 6:26 ` Ojaswin Mujoo
2026-06-16 11:47 ` Jan Kara
2026-05-11 7:23 ` [PATCH v4 10/23] ext4: implement mmap " Zhang Yi
2026-05-27 12:56 ` Ojaswin Mujoo
2026-06-16 11:56 ` Jan Kara
2026-05-11 7:23 ` [PATCH v4 11/23] iomap: correct the range of a partial dirty clear Zhang Yi
2026-05-11 7:46 ` Christoph Hellwig
2026-05-11 8:57 ` Zhang Yi
2026-05-11 7:23 ` [PATCH v4 12/23] iomap: support invalidating partial folios Zhang Yi
2026-05-11 7:23 ` [PATCH v4 13/23] iomap: fix incorrect did_zero setting in iomap_zero_iter() Zhang Yi
2026-05-11 7:23 ` [PATCH v4 14/23] ext4: implement partial block zero range path using iomap Zhang Yi
2026-05-27 13:13 ` Ojaswin Mujoo
2026-06-16 12:28 ` Jan Kara
2026-05-11 7:23 ` [PATCH v4 15/23] ext4: add block mapping tracepoints for iomap buffered I/O path Zhang Yi
2026-05-27 13:14 ` Ojaswin Mujoo
2026-06-16 12:29 ` Jan Kara
2026-05-11 7:23 ` [PATCH v4 16/23] ext4: disable online defrag when inode using " Zhang Yi
2026-05-27 13:14 ` Ojaswin Mujoo
2026-06-16 12:30 ` Jan Kara
2026-05-11 7:23 ` [PATCH v4 17/23] ext4: submit zeroed post-EOF data immediately in the " Zhang Yi
2026-05-27 13:41 ` Ojaswin Mujoo
2026-05-30 2:53 ` Zhang Yi
2026-06-01 9:08 ` Ojaswin Mujoo
2026-06-01 12:22 ` Zhang Yi
2026-06-01 18:15 ` Ojaswin Mujoo
2026-06-02 3:36 ` Zhang Yi
2026-05-11 7:23 ` [PATCH v4 18/23] ext4: wait for ordered I/O " Zhang Yi
2026-05-27 15:58 ` Ojaswin Mujoo
2026-05-28 13:34 ` Ojaswin Mujoo
2026-05-30 9:32 ` Zhang Yi
2026-06-02 5:56 ` Ojaswin Mujoo
2026-05-30 7:22 ` Zhang Yi
2026-05-30 8:24 ` Zhang Yi
2026-06-01 18:33 ` Ojaswin Mujoo
2026-06-02 3:22 ` Zhang Yi
2026-06-02 5:35 ` Ojaswin Mujoo
2026-05-11 7:23 ` [PATCH v4 19/23] ext4: update i_disksize to i_size on ordered I/O completion Zhang Yi
2026-05-11 7:23 ` [PATCH v4 20/23] ext4: wait for ordered I/O to complete during insert and collapse range Zhang Yi
2026-05-11 7:23 ` [PATCH v4 21/23] ext4: add tracepoints for ordered I/O in the iomap buffered I/O path Zhang Yi
2026-05-11 7:23 ` [PATCH v4 22/23] ext4: partially enable iomap for the buffered I/O path of regular files Zhang Yi
2026-05-11 7:23 ` [PATCH v4 23/23] ext4: introduce a mount option for iomap buffered I/O path Zhang Yi
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=51b3f8d5-b90f-49fe-b93e-171268db9ff8@gmail.com \
--to=yizhang089@gmail.com \
--cc=adilger.kernel@dilger.ca \
--cc=djwong@kernel.org \
--cc=hch@infradead.org \
--cc=jack@suse.cz \
--cc=libaokun@linux.alibaba.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ojaswin@linux.ibm.com \
--cc=ritesh.list@gmail.com \
--cc=tytso@mit.edu \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.com \
--cc=yi.zhang@huaweicloud.com \
--cc=yukuai@fnnas.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