From: Nick Piggin Subject: Re: [PATCH 05/43] FS-Cache: Release page->private after failed readahead [ver #46] Date: Fri, 3 Apr 2009 00:51:09 +1100 Message-ID: <200904030051.10644.nickpiggin@yahoo.com.au> References: <20090401230321.28177.12010.stgit@warthog.procyon.org.uk> <20090401230347.28177.28093.stgit@warthog.procyon.org.uk> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0916127323==" Cc: linux-fsdevel@vger.kernel.org, nfsv4@linux-nfs.org, viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org To: David Howells Return-path: In-Reply-To: <20090401230347.28177.28093.stgit@warthog.procyon.org.uk> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Mime-version: 1.0 Sender: nfsv4-bounces@linux-nfs.org Errors-To: nfsv4-bounces@linux-nfs.org List-Id: linux-fsdevel.vger.kernel.org --===============0916127323== Content-Type: multipart/alternative; boundary="Boundary-00=_OLM1JJH+NsPwDpc" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-00=_OLM1JJH+NsPwDpc Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit On Thursday 02 April 2009 10:03:47 David Howells wrote: > The attached patch causes read_cache_pages() to release page-private data > on a page for which add_to_page_cache() fails or the filler function fails. > This permits pages with caching references associated with them to be > cleaned up. > > The invalidatepage() address space op is called (indirectly) to do the > honours. This does not release the page for which the filler function fails. It releases for all pages that do not get put on the LRU. I guess that's just a changelog bug. I don't have a problem with this if it is significantly easier to do here than the caller -- it should be a slowpath. > > Signed-off-by: David Howells > Acked-by: Steve Dickson > Acked-by: Trond Myklebust > --- > > include/linux/page-flags.h | 2 +- > mm/readahead.c | 39 +++++++++++++++++++++++++++++++++++++-- > 2 files changed, 38 insertions(+), 3 deletions(-) > > > diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h > index 61df177..9d99e74 100644 > --- a/include/linux/page-flags.h > +++ b/include/linux/page-flags.h > @@ -182,7 +182,7 @@ static inline int TestClearPage##uname(struct page > *page) { return 0; } > > struct page; /* forward declaration */ > > -TESTPAGEFLAG(Locked, locked) > +TESTPAGEFLAG(Locked, locked) TESTSETFLAG(Locked, locked) > PAGEFLAG(Error, error) > PAGEFLAG(Referenced, referenced) TESTCLEARFLAG(Referenced, referenced) > PAGEFLAG(Dirty, dirty) TESTSCFLAG(Dirty, dirty) __CLEARPAGEFLAG(Dirty, > dirty) diff --git a/mm/readahead.c b/mm/readahead.c > index 9ce303d..6be9275 100644 > --- a/mm/readahead.c > +++ b/mm/readahead.c > @@ -31,6 +31,41 @@ EXPORT_SYMBOL_GPL(file_ra_state_init); > > #define list_to_page(head) (list_entry((head)->prev, struct page, lru)) > > +/* > + * see if a page needs releasing upon read_cache_pages() failure > + * - the caller of read_cache_pages() may have set PG_private before > calling, + * such as the NFS fs marking pages that are cached locally on > disk, thus we + * need to give the fs a chance to clean up in the event > of an error + */ > +static void read_cache_pages_invalidate_page(struct address_space > *mapping, + struct page *page) > +{ > + if (PagePrivate(page)) { > + if (!trylock_page(page)) > + BUG(); > + page->mapping = mapping; > + do_invalidatepage(page, 0); > + page->mapping = NULL; > + unlock_page(page); > + } > + page_cache_release(page); > +} > + > +/* > + * release a list of pages, invalidating them first if need be > + */ > +static void read_cache_pages_invalidate_pages(struct address_space > *mapping, + struct list_head *pages) > +{ > + struct page *victim; > + > + while (!list_empty(pages)) { > + victim = list_to_page(pages); > + list_del(&victim->lru); > + read_cache_pages_invalidate_page(mapping, victim); > + } > +} > + > /** > * read_cache_pages - populate an address space with some pages & start > reads against them * @mapping: the address_space > @@ -52,14 +87,14 @@ int read_cache_pages(struct address_space *mapping, > struct list_head *pages, list_del(&page->lru); > if (add_to_page_cache_lru(page, mapping, > page->index, GFP_KERNEL)) { > - page_cache_release(page); > + read_cache_pages_invalidate_page(mapping, page); > continue; > } > page_cache_release(page); > > ret = filler(data, page); > if (unlikely(ret)) { --Boundary-00=_OLM1JJH+NsPwDpc Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: 7bit

On Thursday 02 April 2009 10:03:47 David Howells wrote:

> The attached patch causes read_cache_pages() to release page-private data

> on a page for which add_to_page_cache() fails or the filler function fails.

> This permits pages with caching references associated with them to be

> cleaned up.

>

> The invalidatepage() address space op is called (indirectly) to do the

> honours.

This does not release the page for which the filler function fails.

It releases for all pages that do not get put on the LRU.

I guess that's just a changelog bug.

I don't have a problem with this if it is significantly easier to do

here than the caller -- it should be a slowpath.

>

> Signed-off-by: David Howells <dhowells@redhat.com>

> Acked-by: Steve Dickson <steved@redhat.com>

> Acked-by: Trond Myklebust <Trond.Myklebust@netapp.com>

> ---

>

> include/linux/page-flags.h | 2 +-

> mm/readahead.c | 39 +++++++++++++++++++++++++++++++++++++--

> 2 files changed, 38 insertions(+), 3 deletions(-)

>

>

> diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h

> index 61df177..9d99e74 100644

> --- a/include/linux/page-flags.h

> +++ b/include/linux/page-flags.h

> @@ -182,7 +182,7 @@ static inline int TestClearPage##uname(struct page

> *page) { return 0; }

>

> struct page; /* forward declaration */

>

> -TESTPAGEFLAG(Locked, locked)

> +TESTPAGEFLAG(Locked, locked) TESTSETFLAG(Locked, locked)

> PAGEFLAG(Error, error)

> PAGEFLAG(Referenced, referenced) TESTCLEARFLAG(Referenced, referenced)

> PAGEFLAG(Dirty, dirty) TESTSCFLAG(Dirty, dirty) __CLEARPAGEFLAG(Dirty,

> dirty) diff --git a/mm/readahead.c b/mm/readahead.c

> index 9ce303d..6be9275 100644

> --- a/mm/readahead.c

> +++ b/mm/readahead.c

> @@ -31,6 +31,41 @@ EXPORT_SYMBOL_GPL(file_ra_state_init);

>

> #define list_to_page(head) (list_entry((head)->prev, struct page, lru))

>

> +/*

> + * see if a page needs releasing upon read_cache_pages() failure

> + * - the caller of read_cache_pages() may have set PG_private before

> calling, + * such as the NFS fs marking pages that are cached locally on

> disk, thus we + * need to give the fs a chance to clean up in the event

> of an error + */

> +static void read_cache_pages_invalidate_page(struct address_space

> *mapping, + struct page *page)

> +{

> + if (PagePrivate(page)) {

> + if (!trylock_page(page))

> + BUG();

> + page->mapping = mapping;

> + do_invalidatepage(page, 0);

> + page->mapping = NULL;

> + unlock_page(page);

> + }

> + page_cache_release(page);

> +}

> +

> +/*

> + * release a list of pages, invalidating them first if need be

> + */

> +static void read_cache_pages_invalidate_pages(struct address_space

> *mapping, + struct list_head *pages)

> +{

> + struct page *victim;

> +

> + while (!list_empty(pages)) {

> + victim = list_to_page(pages);

> + list_del(&victim->lru);

> + read_cache_pages_invalidate_page(mapping, victim);

> + }

> +}

> +

> /**

> * read_cache_pages - populate an address space with some pages & start

> reads against them * @mapping: the address_space

> @@ -52,14 +87,14 @@ int read_cache_pages(struct address_space *mapping,

> struct list_head *pages, list_del(&page->lru);

> if (add_to_page_cache_lru(page, mapping,

> page->index, GFP_KERNEL)) {

> - page_cache_release(page);

> + read_cache_pages_invalidate_page(mapping, page);

> continue;

> }

> page_cache_release(page);

>

> ret = filler(data, page);

> if (unlikely(ret)) {

> - put_pages_list(pages);

> + read_cache_pages_invalidate_pages(mapping, pages);

> break;

> }

> task_io_account_read(PAGE_CACHE_SIZE);

>

--Boundary-00=_OLM1JJH+NsPwDpc-- --===============0916127323== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ NFSv4 mailing list NFSv4@linux-nfs.org http://linux-nfs.org/cgi-bin/mailman/listinfo/nfsv4 --===============0916127323==--