From: Jens Axboe <axboe@kernel.dk>
To: Amir Goldstein <amir73il@gmail.com>,
Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>, Miklos Szeredi <miklos@szeredi.hu>,
David Howells <dhowells@redhat.com>,
Al Viro <viro@zeniv.linux.org.uk>,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH v2] fs: create kiocb_{start,end}_write() helpers
Date: Wed, 16 Aug 2023 09:28:46 -0600 [thread overview]
Message-ID: <7725feff-8d9d-4b54-9910-951b79f67596@kernel.dk> (raw)
In-Reply-To: <20230816085439.894112-1-amir73il@gmail.com>
On 8/16/23 2:54 AM, Amir Goldstein wrote:
> aio, io_uring, cachefiles and overlayfs, all open code an ugly variant
> of file_{start,end}_write() to silence lockdep warnings.
>
> Create helpers for this lockdep dance and use the helpers in all the
> callers.
>
> Use a new iocb flag IOCB_WRITE_STARTED to indicate if sb_start_write()
> was called.
Looks better now, but I think you should split this into a prep patch
that adds the helpers, and then one for each conversion. We've had bugs
with this accounting before which causes fs freeze issues, would be
prudent to have it split because of that.
> diff --git a/fs/aio.c b/fs/aio.c
> index 77e33619de40..16fb3ac2093b 100644
> --- a/fs/aio.c
> +++ b/fs/aio.c
> @@ -1444,17 +1444,8 @@ static void aio_complete_rw(struct kiocb *kiocb, long res)
> if (!list_empty_careful(&iocb->ki_list))
> aio_remove_iocb(iocb);
>
> - if (kiocb->ki_flags & IOCB_WRITE) {
> - struct inode *inode = file_inode(kiocb->ki_filp);
> -
> - /*
> - * Tell lockdep we inherited freeze protection from submission
> - * thread.
> - */
> - if (S_ISREG(inode->i_mode))
> - __sb_writers_acquired(inode->i_sb, SB_FREEZE_WRITE);
> - file_end_write(kiocb->ki_filp);
> - }
> + if (kiocb->ki_flags & IOCB_WRITE)
> + kiocb_end_write(kiocb);
Can't we just call kiocb_end_write() here, it checks WRITE_STARTED
anyway? Not a big deal, and honestly I'd rather just get rid of
WRITE_STARTED if we're not using it like that. It doesn't serve much of
a purpose, if we're gating this one IOCB_WRITE anyway (which I do like
better than WRITE_STARTED). And it avoids writing to the kiocb at the
end too, which is a nice win.
> index b2adee67f9b2..8e5d410a1be5 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -338,6 +338,8 @@ enum rw_hint {
> #define IOCB_NOIO (1 << 20)
> /* can use bio alloc cache */
> #define IOCB_ALLOC_CACHE (1 << 21)
> +/* file_start_write() was called */
> +#define IOCB_WRITE_STARTED (1 << 22)
>
> /* for use in trace events */
> #define TRACE_IOCB_STRINGS \
> @@ -351,7 +353,8 @@ enum rw_hint {
> { IOCB_WRITE, "WRITE" }, \
> { IOCB_WAITQ, "WAITQ" }, \
> { IOCB_NOIO, "NOIO" }, \
> - { IOCB_ALLOC_CACHE, "ALLOC_CACHE" }
> + { IOCB_ALLOC_CACHE, "ALLOC_CACHE" }, \
> + { IOCB_WRITE_STARTED, "WRITE_STARTED" }
>
> struct kiocb {
> struct file *ki_filp;
These changes will conflict with other changes in linux-next that are
going upstream. I'd prefer to stage this one after those changes, once
we get to a version that looks good to everybody.
--
Jens Axboe
next prev parent reply other threads:[~2023-08-16 15:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-16 8:54 [PATCH v2] fs: create kiocb_{start,end}_write() helpers Amir Goldstein
2023-08-16 15:01 ` Jan Kara
2023-08-16 15:28 ` Jens Axboe [this message]
2023-08-16 18:58 ` Amir Goldstein
2023-08-16 19:13 ` Jens Axboe
2023-08-17 13:18 ` Amir Goldstein
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=7725feff-8d9d-4b54-9910-951b79f67596@kernel.dk \
--to=axboe@kernel.dk \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=dhowells@redhat.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=viro@zeniv.linux.org.uk \
/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).