[PATCH 05/22] FS-Cache: Release page->private after failed readahead

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <viro@...>, <hch@...>, <Trond.Myklebust@...>, <sds@...>, <casey@...>
Cc: <linux-kernel@...>, <selinux@...>, <linux-security-module@...>, <dhowells@...>
Date: Friday, September 21, 2007 - 10:47 am

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.

Signed-Off-By: David Howells <dhowells@redhat.com>
---

 mm/readahead.c |   40 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/mm/readahead.c b/mm/readahead.c
index 39bf45d..12d1378 100644
--- a/mm/readahead.c
+++ b/mm/readahead.c
@@ -15,6 +15,7 @@
 #include <linux/backing-dev.h>
 #include <linux/task_io_accounting_ops.h>
 #include <linux/pagevec.h>
+#include <linux/buffer_head.h>
 
 void default_unplug_io_fn(struct backing_dev_info *bdi, struct page *page)
 {
@@ -51,6 +52,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 (TestSetPageLocked(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
@@ -74,14 +110,14 @@ int read_cache_pages(struct address_space *mapping, struct list_head *pages,
 		page = list_to_page(pages);
 		list_del(&page->lru);
 		if (add_to_page_cache(page, mapping, page->index, GFP_KERNEL)) {
-			page_cache_release(page);
+			read_cache_pages_invalidate_page(mapping, page);
 			continue;
 		}
 		ret = filler(data, page);
 		if (!pagevec_add(&lru_pvec, page))
 			__pagevec_lru_add(&lru_pvec);
 		if (ret) {
-			put_pages_list(pages);
+			read_cache_pages_invalidate_pages(mapping, pages);
 			break;
 		}
 		task_io_account_read(PAGE_CACHE_SIZE);

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/22] Introduce credential record, David Howells, (Fri Sep 21, 10:47 am)
[PATCH 01/22] CRED: Introduce a COW credentials record, David Howells, (Fri Sep 21, 10:47 am)
[PATCH 05/22] FS-Cache: Release page->private after faile..., David Howells, (Fri Sep 21, 10:47 am)
Re: [PATCH 00/22] Introduce credential record, David Howells, (Fri Sep 21, 10:58 am)
Re: [PATCH 00/22] Introduce credential record, Casey Schaufler, (Fri Sep 21, 11:36 am)
Re: [PATCH 00/22] Introduce credential record, David Howells, (Fri Sep 21, 11:40 am)
Re: [PATCH 00/22] Introduce credential record, Casey Schaufler, (Fri Sep 21, 12:04 pm)
Re: [PATCH 00/22] Introduce credential record, David Howells, (Fri Sep 21, 7:18 pm)
[PATCH 22/22] FS-Cache: Make kAFS use FS-Cache, David Howells, (Fri Sep 21, 10:48 am)
[PATCH 20/22] AFS: Implement shared-writable mmap, David Howells, (Fri Sep 21, 10:48 am)
[PATCH 17/22] AFS: Add TestSetPageError(), David Howells, (Fri Sep 21, 10:48 am)
[PATCH 16/22] NFS: Display local caching state, David Howells, (Fri Sep 21, 10:48 am)
[PATCH 14/22] NFS: Use local caching, David Howells, (Fri Sep 21, 10:48 am)
Re: [PATCH 14/22] NFS: Use local caching, Peter Staubach, (Fri Sep 21, 1:00 pm)
Re: [PATCH 14/22] NFS: Use local caching, David Howells, (Fri Sep 21, 7:22 pm)
Re: [PATCH 14/22] NFS: Use local caching, David Howells, (Fri Sep 21, 7:37 pm)
Re: [PATCH 14/22] NFS: Use local caching, Peter Staubach, (Mon Sep 24, 9:31 am)
[PATCH 12/22] CacheFiles: Export things for CacheFiles, David Howells, (Fri Sep 21, 10:48 am)