public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Shiyang Ruan <ruansy.fnst@fujitsu.com>
To: <linux-kernel@vger.kernel.org>, <linux-xfs@vger.kernel.org>,
	<nvdimm@lists.linux.dev>, <linux-fsdevel@vger.kernel.org>
Cc: <djwong@kernel.org>, <david@fromorbit.com>,
	<dan.j.williams@intel.com>, <akpm@linux-foundation.org>
Subject: [PATCH v2 4/8] fsdax,xfs: set the shared flag when file extent is shared
Date: Thu, 1 Dec 2022 15:28:54 +0000	[thread overview]
Message-ID: <1669908538-55-5-git-send-email-ruansy.fnst@fujitsu.com> (raw)
In-Reply-To: <1669908538-55-1-git-send-email-ruansy.fnst@fujitsu.com>

If a dax page is shared, mapread at different offsets can also trigger
page fault on same dax page.  So, change the flag from "cow" to
"shared".  And get the shared flag from filesystem when read.

Signed-off-by: Shiyang Ruan <ruansy.fnst@fujitsu.com>
---
 fs/dax.c           | 19 +++++++------------
 fs/xfs/xfs_iomap.c |  2 +-
 2 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/fs/dax.c b/fs/dax.c
index 6b6e07ad8d80..f1eb59bee0b5 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -846,12 +846,6 @@ static bool dax_fault_is_synchronous(const struct iomap_iter *iter,
 		(iter->iomap.flags & IOMAP_F_DIRTY);
 }
 
-static bool dax_fault_is_cow(const struct iomap_iter *iter)
-{
-	return (iter->flags & IOMAP_WRITE) &&
-		(iter->iomap.flags & IOMAP_F_SHARED);
-}
-
 /*
  * By this point grab_mapping_entry() has ensured that we have a locked entry
  * of the appropriate size so we don't have to worry about downgrading PMDs to
@@ -865,13 +859,14 @@ static void *dax_insert_entry(struct xa_state *xas, struct vm_fault *vmf,
 {
 	struct address_space *mapping = vmf->vma->vm_file->f_mapping;
 	void *new_entry = dax_make_entry(pfn, flags);
-	bool dirty = !dax_fault_is_synchronous(iter, vmf->vma);
-	bool cow = dax_fault_is_cow(iter);
+	bool write = iter->flags & IOMAP_WRITE;
+	bool dirty = write && !dax_fault_is_synchronous(iter, vmf->vma);
+	bool shared = iter->iomap.flags & IOMAP_F_SHARED;
 
 	if (dirty)
 		__mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
 
-	if (cow || (dax_is_zero_entry(entry) && !(flags & DAX_ZERO_PAGE))) {
+	if (shared || (dax_is_zero_entry(entry) && !(flags & DAX_ZERO_PAGE))) {
 		unsigned long index = xas->xa_index;
 		/* we are replacing a zero page with block mapping */
 		if (dax_is_pmd_entry(entry))
@@ -883,12 +878,12 @@ static void *dax_insert_entry(struct xa_state *xas, struct vm_fault *vmf,
 
 	xas_reset(xas);
 	xas_lock_irq(xas);
-	if (cow || dax_is_zero_entry(entry) || dax_is_empty_entry(entry)) {
+	if (shared || dax_is_zero_entry(entry) || dax_is_empty_entry(entry)) {
 		void *old;
 
 		dax_disassociate_entry(entry, mapping, false);
 		dax_associate_entry(new_entry, mapping, vmf->vma, vmf->address,
-				cow);
+				shared);
 		/*
 		 * Only swap our new entry into the page cache if the current
 		 * entry is a zero page or an empty entry.  If a normal PTE or
@@ -908,7 +903,7 @@ static void *dax_insert_entry(struct xa_state *xas, struct vm_fault *vmf,
 	if (dirty)
 		xas_set_mark(xas, PAGECACHE_TAG_DIRTY);
 
-	if (cow)
+	if (write && shared)
 		xas_set_mark(xas, PAGECACHE_TAG_TOWRITE);
 
 	xas_unlock_irq(xas);
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index 07da03976ec1..881de99766ca 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -1215,7 +1215,7 @@ xfs_read_iomap_begin(
 		return error;
 	error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb, &imap,
 			       &nimaps, 0);
-	if (!error && (flags & IOMAP_REPORT))
+	if (!error && ((flags & IOMAP_REPORT) || IS_DAX(inode)))
 		error = xfs_reflink_trim_around_shared(ip, &imap, &shared);
 	xfs_iunlock(ip, lockmode);
 
-- 
2.38.1


  parent reply	other threads:[~2022-12-01 15:29 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-01 15:28 [PATCH v2 0/8] fsdax,xfs: fix warning messages Shiyang Ruan
2022-12-01 15:28 ` [PATCH v2 1/8] fsdax: introduce page->share for fsdax in reflink mode Shiyang Ruan
2022-12-01 16:14   ` Darrick J. Wong
2022-12-02  9:23   ` [PATCH v2.1 " Shiyang Ruan
2022-12-02 20:18     ` Andrew Morton
2022-12-03  0:19     ` Allison Henderson
2022-12-03  2:07     ` Dan Williams
2022-12-05  5:56       ` Shiyang Ruan
2022-12-05  7:01         ` Darrick J. Wong
2022-12-07  2:49   ` [PATCH v2.2 " Shiyang Ruan
2022-12-08  1:26     ` Darrick J. Wong
2022-12-01 15:28 ` [PATCH v2 2/8] fsdax: invalidate pages when CoW Shiyang Ruan
2022-12-01 16:17   ` Darrick J. Wong
2022-12-01 15:28 ` [PATCH v2 3/8] fsdax: zero the edges if source is HOLE or UNWRITTEN Shiyang Ruan
2022-12-01 23:58   ` Darrick J. Wong
2022-12-02  0:39     ` Andrew Morton
2022-12-02  9:25   ` [PATCH v2.1 " Shiyang Ruan
2022-12-03  0:19     ` Allison Henderson
2022-12-01 15:28 ` Shiyang Ruan [this message]
2022-12-02  0:05   ` [PATCH v2 4/8] fsdax,xfs: set the shared flag when file extent is shared Darrick J. Wong
2022-12-01 15:31 ` [PATCH v2 5/8] fsdax: dedupe: iter two files at the same time Shiyang Ruan
2022-12-02  0:05   ` Darrick J. Wong
2022-12-01 15:32 ` [PATCH v2 6/8] xfs: use dax ops for zero and truncate in fsdax mode Shiyang Ruan
2022-12-02  0:05   ` Darrick J. Wong
2022-12-01 15:32 ` [PATCH v2 7/8] fsdax,xfs: port unshare to fsdax Shiyang Ruan
2022-12-01 15:32 ` [PATCH v2 8/8] xfs: remove restrictions for fsdax and reflink Shiyang Ruan
2022-12-02  0:06   ` Darrick J. Wong
2022-12-03  1:21 ` [PATCH v2 0/8] fsdax,xfs: fix warning messages Dan Williams
2022-12-29  8:23   ` Shiyang Ruan

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=1669908538-55-5-git-send-email-ruansy.fnst@fujitsu.com \
    --to=ruansy.fnst@fujitsu.com \
    --cc=akpm@linux-foundation.org \
    --cc=dan.j.williams@intel.com \
    --cc=david@fromorbit.com \
    --cc=djwong@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    /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