From: "Darrick J. Wong" <djwong@kernel.org>
To: Shiyang Ruan <ruansy.fnst@fujitsu.com>
Cc: linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org,
nvdimm@lists.linux.dev, linux-mm@kvack.org,
linux-fsdevel@vger.kernel.org, dan.j.williams@intel.com,
david@fromorbit.com, akpm@linux-foundation.org,
allison.henderson@oracle.com
Subject: Re: [PATCH v2.2 1/8] fsdax: introduce page->share for fsdax in reflink mode
Date: Wed, 7 Dec 2022 17:26:42 -0800 [thread overview]
Message-ID: <Y5E9UgUyidulL2yp@magnolia> (raw)
In-Reply-To: <1670381359-53-1-git-send-email-ruansy.fnst@fujitsu.com>
On Wed, Dec 07, 2022 at 02:49:19AM +0000, Shiyang Ruan wrote:
> fsdax page is used not only when CoW, but also mapread. To make the it
> easily understood, use 'share' to indicate that the dax page is shared
> by more than one extent. And add helper functions to use it.
>
> Also, the flag needs to be renamed to PAGE_MAPPING_DAX_SHARED.
>
> Signed-off-by: Shiyang Ruan <ruansy.fnst@fujitsu.com>
> Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Looks fine to me,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
--D
> ---
> fs/dax.c | 38 ++++++++++++++++++++++----------------
> include/linux/mm_types.h | 5 ++++-
> include/linux/page-flags.h | 2 +-
> 3 files changed, 27 insertions(+), 18 deletions(-)
>
> diff --git a/fs/dax.c b/fs/dax.c
> index 1c6867810cbd..84fadea08705 100644
> --- a/fs/dax.c
> +++ b/fs/dax.c
> @@ -334,35 +334,41 @@ static unsigned long dax_end_pfn(void *entry)
> for (pfn = dax_to_pfn(entry); \
> pfn < dax_end_pfn(entry); pfn++)
>
> -static inline bool dax_mapping_is_cow(struct address_space *mapping)
> +static inline bool dax_page_is_shared(struct page *page)
> {
> - return (unsigned long)mapping == PAGE_MAPPING_DAX_COW;
> + return page->mapping == PAGE_MAPPING_DAX_SHARED;
> }
>
> /*
> - * Set the page->mapping with FS_DAX_MAPPING_COW flag, increase the refcount.
> + * Set the page->mapping with PAGE_MAPPING_DAX_SHARED flag, increase the
> + * refcount.
> */
> -static inline void dax_mapping_set_cow(struct page *page)
> +static inline void dax_page_share_get(struct page *page)
> {
> - if ((uintptr_t)page->mapping != PAGE_MAPPING_DAX_COW) {
> + if (page->mapping != PAGE_MAPPING_DAX_SHARED) {
> /*
> * Reset the index if the page was already mapped
> * regularly before.
> */
> if (page->mapping)
> - page->index = 1;
> - page->mapping = (void *)PAGE_MAPPING_DAX_COW;
> + page->share = 1;
> + page->mapping = PAGE_MAPPING_DAX_SHARED;
> }
> - page->index++;
> + page->share++;
> +}
> +
> +static inline unsigned long dax_page_share_put(struct page *page)
> +{
> + return --page->share;
> }
>
> /*
> - * When it is called in dax_insert_entry(), the cow flag will indicate that
> + * When it is called in dax_insert_entry(), the shared flag will indicate that
> * whether this entry is shared by multiple files. If so, set the page->mapping
> - * FS_DAX_MAPPING_COW, and use page->index as refcount.
> + * PAGE_MAPPING_DAX_SHARED, and use page->share as refcount.
> */
> static void dax_associate_entry(void *entry, struct address_space *mapping,
> - struct vm_area_struct *vma, unsigned long address, bool cow)
> + struct vm_area_struct *vma, unsigned long address, bool shared)
> {
> unsigned long size = dax_entry_size(entry), pfn, index;
> int i = 0;
> @@ -374,8 +380,8 @@ static void dax_associate_entry(void *entry, struct address_space *mapping,
> for_each_mapped_pfn(entry, pfn) {
> struct page *page = pfn_to_page(pfn);
>
> - if (cow) {
> - dax_mapping_set_cow(page);
> + if (shared) {
> + dax_page_share_get(page);
> } else {
> WARN_ON_ONCE(page->mapping);
> page->mapping = mapping;
> @@ -396,9 +402,9 @@ static void dax_disassociate_entry(void *entry, struct address_space *mapping,
> struct page *page = pfn_to_page(pfn);
>
> WARN_ON_ONCE(trunc && page_ref_count(page) > 1);
> - if (dax_mapping_is_cow(page->mapping)) {
> - /* keep the CoW flag if this page is still shared */
> - if (page->index-- > 0)
> + if (dax_page_is_shared(page)) {
> + /* keep the shared flag if this page is still shared */
> + if (dax_page_share_put(page) > 0)
> continue;
> } else
> WARN_ON_ONCE(page->mapping && page->mapping != mapping);
> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> index 500e536796ca..f46cac3657ad 100644
> --- a/include/linux/mm_types.h
> +++ b/include/linux/mm_types.h
> @@ -103,7 +103,10 @@ struct page {
> };
> /* See page-flags.h for PAGE_MAPPING_FLAGS */
> struct address_space *mapping;
> - pgoff_t index; /* Our offset within mapping. */
> + union {
> + pgoff_t index; /* Our offset within mapping. */
> + unsigned long share; /* share count for fsdax */
> + };
> /**
> * @private: Mapping-private opaque data.
> * Usually used for buffer_heads if PagePrivate.
> diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
> index 0b0ae5084e60..d8e94f2f704a 100644
> --- a/include/linux/page-flags.h
> +++ b/include/linux/page-flags.h
> @@ -641,7 +641,7 @@ PAGEFLAG_FALSE(VmemmapSelfHosted, vmemmap_self_hosted)
> * Different with flags above, this flag is used only for fsdax mode. It
> * indicates that this page->mapping is now under reflink case.
> */
> -#define PAGE_MAPPING_DAX_COW 0x1
> +#define PAGE_MAPPING_DAX_SHARED ((void *)0x1)
>
> static __always_inline bool folio_mapping_flags(struct folio *folio)
> {
> --
> 2.38.1
>
next prev parent reply other threads:[~2022-12-08 1:26 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 [this message]
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 ` [PATCH v2 4/8] fsdax,xfs: set the shared flag when file extent is shared Shiyang Ruan
2022-12-02 0:05 ` 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=Y5E9UgUyidulL2yp@magnolia \
--to=djwong@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=allison.henderson@oracle.com \
--cc=dan.j.williams@intel.com \
--cc=david@fromorbit.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-xfs@vger.kernel.org \
--cc=nvdimm@lists.linux.dev \
--cc=ruansy.fnst@fujitsu.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;
as well as URLs for NNTP newsgroup(s).