xfs
[Top] [All Lists]

Re: [PATCH v3 3/7] mm: add find_get_entries_tag()

To: Ross Zwisler <ross.zwisler@xxxxxxxxxxxxxxx>
Subject: Re: [PATCH v3 3/7] mm: add find_get_entries_tag()
From: Dan Williams <dan.j.williams@xxxxxxxxx>
Date: Wed, 9 Dec 2015 11:44:16 -0800
Cc: Linux Kernel Mailing List <linux-kernel@xxxxxxxxxxxxxxx>, Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>, Dave Chinner <david@xxxxxxxxxxxxx>, "J. Bruce Fields" <bfields@xxxxxxxxxxxx>, linux-mm <linux-mm@xxxxxxxxx>, Andreas Dilger <adilger.kernel@xxxxxxxxx>, "H. Peter Anvin" <hpa@xxxxxxxxx>, Jeff Layton <jlayton@xxxxxxxxxxxxxxx>, "linux-nvdimm@xxxxxxxxxxxx" <linux-nvdimm@xxxxxxxxxxxx>, "the arch/x86 maintainers" <x86@xxxxxxxxxx>, Ingo Molnar <mingo@xxxxxxxxxx>, ext4 hackers <linux-ext4@xxxxxxxxxxxxxxx>, xfs@xxxxxxxxxxx, Alexander Viro <viro@xxxxxxxxxxxxxxxxxx>, Thomas Gleixner <tglx@xxxxxxxxxxxxx>, "Theodore Ts'o" <tytso@xxxxxxx>, Jan Kara <jack@xxxxxxxx>, linux-fsdevel <linux-fsdevel@xxxxxxxxxxxxxxx>, Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>, Matthew Wilcox <matthew.r.wilcox@xxxxxxxxx>
Delivered-to: xfs@xxxxxxxxxxx
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=3cwlM3jhr3VUbba9v9sFxgsXF9ZFg/TcbT9kxPnxcIQ=; b=rIVaHVCuzqD8P3kUhyAEgpUswA72Fv0uY8NZfgPkb9dERdtohd8XIlJwtTkKJu3d+Q zEpNoRL62TPMDlwC2opwN0AAcfZ1kVjW3BjUTX2GSTIHxCr1p0Vcrw8Yy4qIb3T4tqRW beAxadRpvOYLShlZh0gi5pGV2fKe/TCNvtJUdu16Ihu6fFW57xEL5TXb8us4Y2w2pmSW EYj0V5igY/KgS/V3vXaGXFRL2lmddO363mBV9qzwYFyPNw2rfeOoXF9nmeJkAdce8ANv gmd8QOCk31pwVs7OCS4RGilyecjcMsf5/TJ1/t1He6jSSBJRPMSYDYtxW+UXsMlOIdJk VVRA==
In-reply-to: <1449602325-20572-4-git-send-email-ross.zwisler@xxxxxxxxxxxxxxx>
References: <1449602325-20572-1-git-send-email-ross.zwisler@xxxxxxxxxxxxxxx> <1449602325-20572-4-git-send-email-ross.zwisler@xxxxxxxxxxxxxxx>
On Tue, Dec 8, 2015 at 11:18 AM, Ross Zwisler
<ross.zwisler@xxxxxxxxxxxxxxx> wrote:
> Add find_get_entries_tag() to the family of functions that include
> find_get_entries(), find_get_pages() and find_get_pages_tag().  This is
> needed for DAX dirty page handling because we need a list of both page
> offsets and radix tree entries ('indices' and 'entries' in this function)
> that are marked with the PAGECACHE_TAG_TOWRITE tag.
>
> Signed-off-by: Ross Zwisler <ross.zwisler@xxxxxxxxxxxxxxx>
> ---
>  include/linux/pagemap.h |  3 +++
>  mm/filemap.c            | 68 
> +++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 71 insertions(+)
>
> diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
> index 26eabf5..4db0425 100644
> --- a/include/linux/pagemap.h
> +++ b/include/linux/pagemap.h
> @@ -361,6 +361,9 @@ unsigned find_get_pages_contig(struct address_space 
> *mapping, pgoff_t start,
>                                unsigned int nr_pages, struct page **pages);
>  unsigned find_get_pages_tag(struct address_space *mapping, pgoff_t *index,
>                         int tag, unsigned int nr_pages, struct page **pages);
> +unsigned find_get_entries_tag(struct address_space *mapping, pgoff_t start,
> +                       int tag, unsigned int nr_entries,
> +                       struct page **entries, pgoff_t *indices);
>
>  struct page *grab_cache_page_write_begin(struct address_space *mapping,
>                         pgoff_t index, unsigned flags);
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 167a4d9..99dfbc9 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -1498,6 +1498,74 @@ repeat:
>  }
>  EXPORT_SYMBOL(find_get_pages_tag);
>
> +/**
> + * find_get_entries_tag - find and return entries that match @tag
> + * @mapping:   the address_space to search
> + * @start:     the starting page cache index
> + * @tag:       the tag index
> + * @nr_entries:        the maximum number of entries
> + * @entries:   where the resulting entries are placed
> + * @indices:   the cache indices corresponding to the entries in @entries
> + *
> + * Like find_get_entries, except we only return entries which are tagged with
> + * @tag.
> + */
> +unsigned find_get_entries_tag(struct address_space *mapping, pgoff_t start,
> +                       int tag, unsigned int nr_entries,
> +                       struct page **entries, pgoff_t *indices)
> +{
> +       void **slot;
> +       unsigned int ret = 0;
> +       struct radix_tree_iter iter;
> +
> +       if (!nr_entries)
> +               return 0;
> +
> +       rcu_read_lock();
> +restart:
> +       radix_tree_for_each_tagged(slot, &mapping->page_tree,
> +                                  &iter, start, tag) {
> +               struct page *page;
> +repeat:
> +               page = radix_tree_deref_slot(slot);
> +               if (unlikely(!page))
> +                       continue;
> +               if (radix_tree_exception(page)) {
> +                       if (radix_tree_deref_retry(page)) {
> +                               /*
> +                                * Transient condition which can only trigger
> +                                * when entry at index 0 moves out of or back
> +                                * to root: none yet gotten, safe to restart.
> +                                */
> +                               goto restart;
> +                       }
> +
> +                       /*
> +                        * A shadow entry of a recently evicted page, a swap
> +                        * entry from shmem/tmpfs or a DAX entry.  Return it
> +                        * without attempting to raise page count.
> +                        */
> +                       goto export;
> +               }
> +               if (!page_cache_get_speculative(page))
> +                       goto repeat;
> +
> +               /* Has the page moved? */
> +               if (unlikely(page != *slot)) {
> +                       page_cache_release(page);
> +                       goto repeat;
> +               }
> +export:
> +               indices[ret] = iter.index;
> +               entries[ret] = page;
> +               if (++ret == nr_entries)
> +                       break;
> +       }
> +       rcu_read_unlock();
> +       return ret;
> +}
> +EXPORT_SYMBOL(find_get_entries_tag);
> +

Why does this mostly duplicate find_get_entries()?

Surely find_get_entries() can be implemented as a special case of
find_get_entries_tag().

<Prev in Thread] Current Thread [Next in Thread>