From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
patches@lists.linux.dev,
Catherine Hoang <catherine.hoang@oracle.com>,
"Darrick J. Wong" <djwong@kernel.org>,
Dave Chinner <dchinner@redhat.com>,
Christoph Hellwig <hch@lst.de>,
Chandan Babu R <chandanbabu@kernel.org>,
Leah Rumancik <leah.rumancik@gmail.com>
Subject: [PATCH 6.1 20/49] xfs: allow read IO and FICLONE to run concurrently
Date: Thu, 30 Jan 2025 15:01:56 +0100 [thread overview]
Message-ID: <20250130140134.651541857@linuxfoundation.org> (raw)
In-Reply-To: <20250130140133.825446496@linuxfoundation.org>
6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Catherine Hoang <catherine.hoang@oracle.com>
[ Upstream commit 14a537983b228cb050ceca3a5b743d01315dc4aa ]
One of our VM cluster management products needs to snapshot KVM image
files so that they can be restored in case of failure. Snapshotting is
done by redirecting VM disk writes to a sidecar file and using reflink
on the disk image, specifically the FICLONE ioctl as used by
"cp --reflink". Reflink locks the source and destination files while it
operates, which means that reads from the main vm disk image are blocked,
causing the vm to stall. When an image file is heavily fragmented, the
copy process could take several minutes. Some of the vm image files have
50-100 million extent records, and duplicating that much metadata locks
the file for 30 minutes or more. Having activities suspended for such
a long time in a cluster node could result in node eviction.
Clone operations and read IO do not change any data in the source file,
so they should be able to run concurrently. Demote the exclusive locks
taken by FICLONE to shared locks to allow reads while cloning. While a
clone is in progress, writes will take the IOLOCK_EXCL, so they block
until the clone completes.
Link: https://lore.kernel.org/linux-xfs/8911B94D-DD29-4D6E-B5BC-32EAF1866245@oracle.com/
Signed-off-by: Catherine Hoang <catherine.hoang@oracle.com>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
Signed-off-by: Leah Rumancik <leah.rumancik@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
fs/xfs/xfs_file.c | 63 ++++++++++++++++++++++++++++++++++++++++-----------
fs/xfs/xfs_inode.c | 17 +++++++++++++
fs/xfs/xfs_inode.h | 9 +++++++
fs/xfs/xfs_reflink.c | 4 +++
4 files changed, 80 insertions(+), 13 deletions(-)
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -214,6 +214,43 @@ xfs_ilock_iocb(
return 0;
}
+static int
+xfs_ilock_iocb_for_write(
+ struct kiocb *iocb,
+ unsigned int *lock_mode)
+{
+ ssize_t ret;
+ struct xfs_inode *ip = XFS_I(file_inode(iocb->ki_filp));
+
+ ret = xfs_ilock_iocb(iocb, *lock_mode);
+ if (ret)
+ return ret;
+
+ if (*lock_mode == XFS_IOLOCK_EXCL)
+ return 0;
+ if (!xfs_iflags_test(ip, XFS_IREMAPPING))
+ return 0;
+
+ xfs_iunlock(ip, *lock_mode);
+ *lock_mode = XFS_IOLOCK_EXCL;
+ return xfs_ilock_iocb(iocb, *lock_mode);
+}
+
+static unsigned int
+xfs_ilock_for_write_fault(
+ struct xfs_inode *ip)
+{
+ /* get a shared lock if no remapping in progress */
+ xfs_ilock(ip, XFS_MMAPLOCK_SHARED);
+ if (!xfs_iflags_test(ip, XFS_IREMAPPING))
+ return XFS_MMAPLOCK_SHARED;
+
+ /* wait for remapping to complete */
+ xfs_iunlock(ip, XFS_MMAPLOCK_SHARED);
+ xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
+ return XFS_MMAPLOCK_EXCL;
+}
+
STATIC ssize_t
xfs_file_dio_read(
struct kiocb *iocb,
@@ -523,7 +560,7 @@ xfs_file_dio_write_aligned(
unsigned int iolock = XFS_IOLOCK_SHARED;
ssize_t ret;
- ret = xfs_ilock_iocb(iocb, iolock);
+ ret = xfs_ilock_iocb_for_write(iocb, &iolock);
if (ret)
return ret;
ret = xfs_file_write_checks(iocb, from, &iolock);
@@ -590,7 +627,7 @@ retry_exclusive:
flags = IOMAP_DIO_FORCE_WAIT;
}
- ret = xfs_ilock_iocb(iocb, iolock);
+ ret = xfs_ilock_iocb_for_write(iocb, &iolock);
if (ret)
return ret;
@@ -1158,7 +1195,7 @@ xfs_file_remap_range(
if (xfs_file_sync_writes(file_in) || xfs_file_sync_writes(file_out))
xfs_log_force_inode(dest);
out_unlock:
- xfs_iunlock2_io_mmap(src, dest);
+ xfs_iunlock2_remapping(src, dest);
if (ret)
trace_xfs_reflink_remap_range_error(dest, ret, _RET_IP_);
/*
@@ -1313,6 +1350,7 @@ __xfs_filemap_fault(
struct inode *inode = file_inode(vmf->vma->vm_file);
struct xfs_inode *ip = XFS_I(inode);
vm_fault_t ret;
+ unsigned int lock_mode = 0;
trace_xfs_filemap_fault(ip, pe_size, write_fault);
@@ -1321,25 +1359,24 @@ __xfs_filemap_fault(
file_update_time(vmf->vma->vm_file);
}
+ if (IS_DAX(inode) || write_fault)
+ lock_mode = xfs_ilock_for_write_fault(XFS_I(inode));
+
if (IS_DAX(inode)) {
pfn_t pfn;
- xfs_ilock(XFS_I(inode), XFS_MMAPLOCK_SHARED);
ret = xfs_dax_fault(vmf, pe_size, write_fault, &pfn);
if (ret & VM_FAULT_NEEDDSYNC)
ret = dax_finish_sync_fault(vmf, pe_size, pfn);
- xfs_iunlock(XFS_I(inode), XFS_MMAPLOCK_SHARED);
+ } else if (write_fault) {
+ ret = iomap_page_mkwrite(vmf, &xfs_page_mkwrite_iomap_ops);
} else {
- if (write_fault) {
- xfs_ilock(XFS_I(inode), XFS_MMAPLOCK_SHARED);
- ret = iomap_page_mkwrite(vmf,
- &xfs_page_mkwrite_iomap_ops);
- xfs_iunlock(XFS_I(inode), XFS_MMAPLOCK_SHARED);
- } else {
- ret = filemap_fault(vmf);
- }
+ ret = filemap_fault(vmf);
}
+ if (lock_mode)
+ xfs_iunlock(XFS_I(inode), lock_mode);
+
if (write_fault)
sb_end_pagefault(inode->i_sb);
return ret;
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -3644,6 +3644,23 @@ xfs_iunlock2_io_mmap(
inode_unlock(VFS_I(ip1));
}
+/* Drop the MMAPLOCK and the IOLOCK after a remap completes. */
+void
+xfs_iunlock2_remapping(
+ struct xfs_inode *ip1,
+ struct xfs_inode *ip2)
+{
+ xfs_iflags_clear(ip1, XFS_IREMAPPING);
+
+ if (ip1 != ip2)
+ xfs_iunlock(ip1, XFS_MMAPLOCK_SHARED);
+ xfs_iunlock(ip2, XFS_MMAPLOCK_EXCL);
+
+ if (ip1 != ip2)
+ inode_unlock_shared(VFS_I(ip1));
+ inode_unlock(VFS_I(ip2));
+}
+
/*
* Reload the incore inode list for this inode. Caller should ensure that
* the link count cannot change, either by taking ILOCK_SHARED or otherwise
--- a/fs/xfs/xfs_inode.h
+++ b/fs/xfs/xfs_inode.h
@@ -347,6 +347,14 @@ static inline bool xfs_inode_has_large_e
/* Quotacheck is running but inode has not been added to quota counts. */
#define XFS_IQUOTAUNCHECKED (1 << 14)
+/*
+ * Remap in progress. Callers that wish to update file data while
+ * holding a shared IOLOCK or MMAPLOCK must drop the lock and retake
+ * the lock in exclusive mode. Relocking the file will block until
+ * IREMAPPING is cleared.
+ */
+#define XFS_IREMAPPING (1U << 15)
+
/* All inode state flags related to inode reclaim. */
#define XFS_ALL_IRECLAIM_FLAGS (XFS_IRECLAIMABLE | \
XFS_IRECLAIM | \
@@ -595,6 +603,7 @@ void xfs_end_io(struct work_struct *work
int xfs_ilock2_io_mmap(struct xfs_inode *ip1, struct xfs_inode *ip2);
void xfs_iunlock2_io_mmap(struct xfs_inode *ip1, struct xfs_inode *ip2);
+void xfs_iunlock2_remapping(struct xfs_inode *ip1, struct xfs_inode *ip2);
static inline bool
xfs_inode_unlinked_incomplete(
--- a/fs/xfs/xfs_reflink.c
+++ b/fs/xfs/xfs_reflink.c
@@ -1539,6 +1539,10 @@ xfs_reflink_remap_prep(
if (ret)
goto out_unlock;
+ xfs_iflags_set(src, XFS_IREMAPPING);
+ if (inode_in != inode_out)
+ xfs_ilock_demote(src, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL);
+
return 0;
out_unlock:
xfs_iunlock2_io_mmap(src, dest);
next prev parent reply other threads:[~2025-01-30 14:31 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-30 14:01 [PATCH 6.1 00/49] 6.1.128-rc1 review Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 01/49] ASoC: wm8994: Add depends on MFD core Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 02/49] ASoC: samsung: Add missing selects for MFD_WM8994 Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 03/49] seccomp: Stub for !CONFIG_SECCOMP Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 04/49] scsi: iscsi: Fix redundant response for ISCSI_UEVENT_GET_HOST_STATS request Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 05/49] drm/amd/display: Use HW lock mgr for PSR1 Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 06/49] irqchip/sunxi-nmi: Add missing SKIP_WAKE flag Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 07/49] ASoC: samsung: midas_wm1811: Map missing jack kcontrols Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 08/49] ASoC: samsung: Add missing depends on I2C Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 09/49] regmap: detach regmap from dev on regmap_exit Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 10/49] ipv6: Fix soft lockups in fib6_select_path under high next hop churn Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 11/49] softirq: Allow raising SCHED_SOFTIRQ from SMP-call-function on RT kernel Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 12/49] xfs: bump max fsgeom struct version Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 13/49] xfs: hoist freeing of rt data fork extent mappings Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 14/49] xfs: prevent rt growfs when quota is enabled Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 15/49] xfs: rt stubs should return negative errnos when rt disabled Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 16/49] xfs: fix units conversion error in xfs_bmap_del_extent_delay Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 17/49] xfs: make sure maxlen is still congruent with prod when rounding down Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 18/49] xfs: introduce protection for drop nlink Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 19/49] xfs: handle nimaps=0 from xfs_bmapi_write in xfs_alloc_file_space Greg Kroah-Hartman
2025-01-30 14:01 ` Greg Kroah-Hartman [this message]
2025-01-30 14:01 ` [PATCH 6.1 21/49] xfs: factor out xfs_defer_pending_abort Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 22/49] xfs: abort intent items when recovery intents fail Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 6.1 23/49] xfs: only remap the written blocks in xfs_reflink_end_cow_extent Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 24/49] xfs: up(ic_sema) if flushing data device fails Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 25/49] xfs: fix internal error from AGFL exhaustion Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 26/49] xfs: inode recovery does not validate the recovered inode Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 27/49] xfs: clean up dqblk extraction Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 28/49] xfs: dquot recovery does not validate the recovered dquot Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 29/49] xfs: clean up FS_XFLAG_REALTIME handling in xfs_ioctl_setattr_xflags Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 30/49] xfs: respect the stable writes flag on the RT device Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 31/49] gfs2: Truncate address space when flipping GFS2_DIF_JDATA flag Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 32/49] io_uring: fix waiters missing wake ups Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 33/49] net: sched: fix ets qdisc OOB Indexing Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 34/49] block: fix integer overflow in BLKSECDISCARD Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 35/49] Revert "HID: multitouch: Add support for lenovo Y9000P Touchpad" Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 36/49] vfio/platform: check the bounds of read/write syscalls Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 37/49] ext4: fix access to uninitialised lock in fc replay path Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 38/49] ipv4: ip_tunnel: Fix suspicious RCU usage warning in ip_tunnel_find() Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 39/49] scsi: storvsc: Ratelimit warning logs to prevent VM denial of service Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 40/49] wifi: iwlwifi: add a few rate index validity checks Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 41/49] smb: client: fix UAF in async decryption Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 42/49] USB: serial: quatech2: fix null-ptr-deref in qt2_process_read_urb() Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 43/49] Revert "usb: gadget: u_serial: Disable ep before setting port to null to fix the crash caused by port being null" Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 44/49] ALSA: usb-audio: Add delay quirk for USB Audio Device Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 45/49] Input: atkbd - map F23 key to support default copilot shortcut Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 46/49] Input: xpad - add unofficial Xbox 360 wireless receiver clone Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 47/49] Input: xpad - add support for wooting two he (arm) Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 48/49] smb: client: fix NULL ptr deref in crypto_aead_setkey() Greg Kroah-Hartman
2025-01-30 14:02 ` [PATCH 6.1 49/49] ASoC: samsung: midas_wm1811: Fix Headphone Switch control creation Greg Kroah-Hartman
2025-01-30 17:58 ` [PATCH 6.1 00/49] 6.1.128-rc1 review Mark Brown
2025-01-30 21:31 ` Florian Fainelli
2025-01-31 5:38 ` Jon Hunter
2025-01-31 12:57 ` Pavel Machek
2025-01-31 13:57 ` Ron Economos
2025-01-31 15:26 ` Naresh Kamboju
2025-01-31 16:58 ` Muhammad Usama Anjum
2025-02-01 8:15 ` [PATCH 6.1] " Hardik Garg
2025-02-01 12:19 ` [PATCH 6.1 00/49] " Peter Schneider
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=20250130140134.651541857@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=catherine.hoang@oracle.com \
--cc=chandanbabu@kernel.org \
--cc=dchinner@redhat.com \
--cc=djwong@kernel.org \
--cc=hch@lst.de \
--cc=leah.rumancik@gmail.com \
--cc=patches@lists.linux.dev \
--cc=stable@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 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.