From: Josef Bacik <jbacik@fb.com>
To: <fdmanana@kernel.org>, <linux-btrfs@vger.kernel.org>
Cc: Filipe Manana <fdmanana@suse.com>
Subject: Re: [PATCH] Btrfs: add semaphore to synchronize direct IO writes with fsync
Date: Thu, 12 May 2016 10:36:03 -0700 [thread overview]
Message-ID: <3d087d8d-9e8e-ad55-8b7e-b95af09a206e@fb.com> (raw)
In-Reply-To: <1463073972-8225-1-git-send-email-fdmanana@kernel.org>
On 05/12/2016 10:26 AM, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> Due to the optimization of lockless direct IO writes (the inode's i_mutex
> is not held) introduced in commit 38851cc19adb ("Btrfs: implement unlocked
> dio write"), we started having races between such writes with concurrent
> fsync operations that use the fast fsync path. These races were addressed
> in the patches titled "Btrfs: fix race between fsync and lockless direct
> IO writes" and "Btrfs: fix race between fsync and direct IO writes for
> prealloc extents". The races happened because the direct IO path, like
> every other write path, does create extent maps followed by the
> corresponding ordered extents while the fast fsync path collected first
> ordered extents and then it collected extent maps. This made it possible
> to log file extent items (based on the collected extent maps) without
> waiting for the corresponding ordered extents to complete (get their IO
> done). The two fixes mentioned before added a solution that consists of
> making the direct IO path create first the ordered extents and then the
> extent maps, while the fsync path attempts to collect any new ordered
> extents once it collects the extent maps. This was simple and did not
> require adding any synchonization primitive to any data structure (struct
> btrfs_inode for example) but it makes things more fragile for future
> development endeavours and adds an exceptional approach compared to the
> other write paths.
>
> This change adds a read-write semaphore to the btrfs inode structure and
> makes the direct IO path create the extent maps and the ordered extents
> while holding read access on that semaphore, while the fast fsync path
> collects extent maps and ordered extents while holding write access on
> that semaphore. The logic for direct IO write path is encapsulated in a
> new helper function that is used both for cow and nocow direct IO writes.
>
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
Looks good, thanks Filipe,
Reviewed-by: Josef Bacik <jbacik@fb.com>
Thanks,
Josef
prev parent reply other threads:[~2016-05-12 17:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-12 17:26 [PATCH] Btrfs: add semaphore to synchronize direct IO writes with fsync fdmanana
2016-05-12 17:36 ` Josef Bacik [this message]
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=3d087d8d-9e8e-ad55-8b7e-b95af09a206e@fb.com \
--to=jbacik@fb.com \
--cc=fdmanana@kernel.org \
--cc=fdmanana@suse.com \
--cc=linux-btrfs@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: 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).