mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: stable-review@kernel.org, torvalds@linux-foundation.org,
	akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
	David Howells <dhowells@redhat.com>
Subject: [091/107] FS-Cache: Add a helper to bulk uncache pages on an inode
Date: Thu, 07 Jul 2011 17:17:03 -0700	[thread overview]
Message-ID: <20110708001701.587052450@clark.kroah.org> (raw)
In-Reply-To: <20110708001740.GA14031@kroah.com>

2.6.39-stable review patch.  If anyone has any objections, please let us know.

------------------

From: David Howells <dhowells@redhat.com>

commit c902ce1bfb40d8b049bd2319b388b4b68b04bc27 upstream.

Add an FS-Cache helper to bulk uncache pages on an inode.  This will
only work for the circumstance where the pages in the cache correspond
1:1 with the pages attached to an inode's page cache.

This is required for CIFS and NFS: When disabling inode cookie, we were
returning the cookie and setting cifsi->fscache to NULL but failed to
invalidate any previously mapped pages.  This resulted in "Bad page
state" errors and manifested in other kind of errors when running
fsstress.  Fix it by uncaching mapped pages when we disable the inode
cookie.

This patch should fix the following oops and "Bad page state" errors
seen during fsstress testing.

  ------------[ cut here ]------------
  kernel BUG at fs/cachefiles/namei.c:201!
  invalid opcode: 0000 [#1] SMP
  Pid: 5, comm: kworker/u:0 Not tainted 2.6.38.7-30.fc15.x86_64 #1 Bochs Bochs
  RIP: 0010: cachefiles_walk_to_object+0x436/0x745 [cachefiles]
  RSP: 0018:ffff88002ce6dd00  EFLAGS: 00010282
  RAX: ffff88002ef165f0 RBX: ffff88001811f500 RCX: 0000000000000000
  RDX: 0000000000000000 RSI: 0000000000000100 RDI: 0000000000000282
  RBP: ffff88002ce6dda0 R08: 0000000000000100 R09: ffffffff81b3a300
  R10: 0000ffff00066c0a R11: 0000000000000003 R12: ffff88002ae54840
  R13: ffff88002ae54840 R14: ffff880029c29c00 R15: ffff88001811f4b0
  FS:  00007f394dd32720(0000) GS:ffff88002ef00000(0000) knlGS:0000000000000000
  CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
  CR2: 00007fffcb62ddf8 CR3: 000000001825f000 CR4: 00000000000006e0
  DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
  DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
  Process kworker/u:0 (pid: 5, threadinfo ffff88002ce6c000, task ffff88002ce55cc0)
  Stack:
   0000000000000246 ffff88002ce55cc0 ffff88002ce6dd58 ffff88001815dc00
   ffff8800185246c0 ffff88001811f618 ffff880029c29d18 ffff88001811f380
   ffff88002ce6dd50 ffffffff814757e4 ffff88002ce6dda0 ffffffff8106ac56
  Call Trace:
   cachefiles_lookup_object+0x78/0xd4 [cachefiles]
   fscache_lookup_object+0x131/0x16d [fscache]
   fscache_object_work_func+0x1bc/0x669 [fscache]
   process_one_work+0x186/0x298
   worker_thread+0xda/0x15d
   kthread+0x84/0x8c
   kernel_thread_helper+0x4/0x10
  RIP  cachefiles_walk_to_object+0x436/0x745 [cachefiles]
  ---[ end trace 1d481c9af1804caa ]---

I tested the uncaching by the following means:

 (1) Create a big file on my NFS server (104857600 bytes).

 (2) Read the file into the cache with md5sum on the NFS client.  Look in
     /proc/fs/fscache/stats:

	Pages  : mrk=25601 unc=0

 (3) Open the file for read/write ("bash 5<>/warthog/bigfile").  Look in proc
     again:

	Pages  : mrk=25601 unc=25601

Reported-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-and-Tested-by: Suresh Jayaraman <sjayaraman@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 Documentation/filesystems/caching/netfs-api.txt |   16 ++++++++
 fs/cifs/fscache.c                               |    1 
 fs/fscache/page.c                               |   44 ++++++++++++++++++++++++
 fs/nfs/fscache.c                                |    8 +---
 include/linux/fscache.h                         |   21 +++++++++++
 5 files changed, 85 insertions(+), 5 deletions(-)

--- a/Documentation/filesystems/caching/netfs-api.txt
+++ b/Documentation/filesystems/caching/netfs-api.txt
@@ -673,6 +673,22 @@ storage request to complete, or it may a
 in which case the page will not be stored in the cache this time.
 
 
+BULK INODE PAGE UNCACHE
+-----------------------
+
+A convenience routine is provided to perform an uncache on all the pages
+attached to an inode.  This assumes that the pages on the inode correspond on a
+1:1 basis with the pages in the cache.
+
+	void fscache_uncache_all_inode_pages(struct fscache_cookie *cookie,
+					     struct inode *inode);
+
+This takes the netfs cookie that the pages were cached with and the inode that
+the pages are attached to.  This function will wait for pages to finish being
+written to the cache and for the cache to finish with the page generally.  No
+error is returned.
+
+
 ==========================
 INDEX AND DATA FILE UPDATE
 ==========================
--- a/fs/cifs/fscache.c
+++ b/fs/cifs/fscache.c
@@ -94,6 +94,7 @@ static void cifs_fscache_disable_inode_c
 	if (cifsi->fscache) {
 		cFYI(1, "CIFS disabling inode cookie (0x%p)",
 				cifsi->fscache);
+		fscache_uncache_all_inode_pages(cifsi->fscache, inode);
 		fscache_relinquish_cookie(cifsi->fscache, 1);
 		cifsi->fscache = NULL;
 	}
--- a/fs/fscache/page.c
+++ b/fs/fscache/page.c
@@ -967,3 +967,47 @@ void fscache_mark_pages_cached(struct fs
 	pagevec_reinit(pagevec);
 }
 EXPORT_SYMBOL(fscache_mark_pages_cached);
+
+/*
+ * Uncache all the pages in an inode that are marked PG_fscache, assuming them
+ * to be associated with the given cookie.
+ */
+void __fscache_uncache_all_inode_pages(struct fscache_cookie *cookie,
+				       struct inode *inode)
+{
+	struct address_space *mapping = inode->i_mapping;
+	struct pagevec pvec;
+	pgoff_t next;
+	int i;
+
+	_enter("%p,%p", cookie, inode);
+
+	if (!mapping || mapping->nrpages == 0) {
+		_leave(" [no pages]");
+		return;
+	}
+
+	pagevec_init(&pvec, 0);
+	next = 0;
+	while (next <= (loff_t)-1 &&
+	       pagevec_lookup(&pvec, mapping, next, PAGEVEC_SIZE)
+	       ) {
+		for (i = 0; i < pagevec_count(&pvec); i++) {
+			struct page *page = pvec.pages[i];
+			pgoff_t page_index = page->index;
+
+			ASSERTCMP(page_index, >=, next);
+			next = page_index + 1;
+
+			if (PageFsCache(page)) {
+				__fscache_wait_on_page_write(cookie, page);
+				__fscache_uncache_page(cookie, page);
+			}
+		}
+		pagevec_release(&pvec);
+		cond_resched();
+	}
+
+	_leave("");
+}
+EXPORT_SYMBOL(__fscache_uncache_all_inode_pages);
--- a/fs/nfs/fscache.c
+++ b/fs/nfs/fscache.c
@@ -259,12 +259,10 @@ static void nfs_fscache_disable_inode_co
 		dfprintk(FSCACHE,
 			 "NFS: nfsi 0x%p turning cache off\n", NFS_I(inode));
 
-		/* Need to invalidate any mapped pages that were read in before
-		 * turning off the cache.
+		/* Need to uncache any pages attached to this inode that
+		 * fscache knows about before turning off the cache.
 		 */
-		if (inode->i_mapping && inode->i_mapping->nrpages)
-			invalidate_inode_pages2(inode->i_mapping);
-
+		fscache_uncache_all_inode_pages(NFS_I(inode)->fscache, inode);
 		nfs_fscache_zap_inode_cookie(inode);
 	}
 }
--- a/include/linux/fscache.h
+++ b/include/linux/fscache.h
@@ -204,6 +204,8 @@ extern bool __fscache_check_page_write(s
 extern void __fscache_wait_on_page_write(struct fscache_cookie *, struct page *);
 extern bool __fscache_maybe_release_page(struct fscache_cookie *, struct page *,
 					 gfp_t);
+extern void __fscache_uncache_all_inode_pages(struct fscache_cookie *,
+					      struct inode *);
 
 /**
  * fscache_register_netfs - Register a filesystem as desiring caching services
@@ -643,4 +645,23 @@ bool fscache_maybe_release_page(struct f
 	return false;
 }
 
+/**
+ * fscache_uncache_all_inode_pages - Uncache all an inode's pages
+ * @cookie: The cookie representing the inode's cache object.
+ * @inode: The inode to uncache pages from.
+ *
+ * Uncache all the pages in an inode that are marked PG_fscache, assuming them
+ * to be associated with the given cookie.
+ *
+ * This function may sleep.  It will wait for pages that are being written out
+ * and will wait whilst the PG_fscache mark is removed by the cache.
+ */
+static inline
+void fscache_uncache_all_inode_pages(struct fscache_cookie *cookie,
+				     struct inode *inode)
+{
+	if (fscache_cookie_valid(cookie))
+		__fscache_uncache_all_inode_pages(cookie, inode);
+}
+
 #endif /* _LINUX_FSCACHE_H */



  parent reply	other threads:[~2011-07-08  5:05 UTC|newest]

Thread overview: 117+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-08  0:17 [000/107] 2.6.39.3 review Greg KH
2011-07-08  0:15 ` [001/107] netfilter: ipset: Use proper timeout value to jiffies conversion Greg KH
2011-07-08  0:15 ` [002/107] net: fix ETHTOOL_SFEATURES compatibility with old ethtool_ops.set_flags Greg KH
2011-07-08  0:15 ` [003/107] netfilter: ipset: remove unused variable from type_pf_tdel() Greg KH
2011-07-08  0:15 ` [004/107] netfilter: ipset: fix ip_set_flush return code Greg KH
2011-07-08  0:15 ` [005/107] bug.h: Add WARN_RATELIMIT Greg KH
2011-07-08  0:15 ` [006/107] net: filter: Use WARN_RATELIMIT Greg KH
2011-07-08  0:15 ` [007/107] bug.h: Fix build with CONFIG_PRINTK disabled Greg KH
2011-07-08  0:15 ` [008/107] bug.h: Move ratelimit warn interfaces to ratelimit.h Greg KH
2011-07-08  0:15 ` [009/107] IPVS: bug in ip_vs_ftp, same list heaad used in all netns Greg KH
2011-07-08  0:15 ` [010/107] inetpeer: fix race in unused_list manipulations Greg KH
2011-07-08  0:15 ` [011/107] bridge: provide a cow_metrics method for fake_ops Greg KH
2011-07-08  0:15 ` [012/107] af_packet: prevent information leak Greg KH
2011-07-08  0:15 ` [013/107] inet_diag: fix inet_diag_bc_audit() Greg KH
2011-07-08  0:15 ` [014/107] net/ipv4: Check for mistakenly passed in non-IPv4 address Greg KH
2011-07-08  0:15 ` [015/107] ipv6/udp: Use the correct variable to determine non-blocking condition Greg KH
2011-07-08  0:15 ` [016/107] udp/recvmsg: Clear MSG_TRUNC flag when starting over for a new packet Greg KH
2011-07-08  0:15 ` [017/107] ksm: fix NULL pointer dereference in scan_get_next_rmap_item() Greg KH
2011-07-08  0:15 ` [018/107] drivers/tty/serial/pch_uart.c: dont oops if dmi_get_system_info returns NULL Greg KH
2011-07-08  0:15 ` [019/107] migrate: dont account swapcache as shmem Greg KH
2011-07-08  0:15 ` [020/107] hwmon: (ibmaem) Initialize sysfs attributes Greg KH
2011-07-08  0:15 ` [021/107] hwmon: (s3c) " Greg KH
2011-07-08  0:15 ` [022/107] hwmon: (ibmpex) " Greg KH
2011-07-08  0:15 ` [023/107] Revert "drm/i915: Enable GMBUS for post-gen2 chipsets" Greg KH
2011-07-08  0:15 ` [024/107] drm/radeon/kms/atom: fix duallink on some early DCE3.2 cards Greg KH
2011-07-08  0:15 ` [025/107] drm/radeon/kms: Fix chremap setup on RV770 CE Greg KH
2011-07-08  0:15 ` [026/107] drm/i915: Fix gen6 (SNB) missed BLT ring interrupts Greg KH
2011-07-08  6:13   ` Keith Packard
2011-07-08 14:45     ` Greg KH
2011-07-08  0:15 ` [027/107] drm: populate irq_by_busid-member for pci Greg KH
2011-07-08  0:16 ` [028/107] xen: support CONFIG_MAXSMP Greg KH
2011-07-08  0:16 ` [029/107] xen: partially revert "xen: set max_pfn_mapped to the last pfn mapped" Greg KH
2011-07-08  0:16 ` [030/107] xen/pci: Use the INT_SRC_OVR IRQ (instead of GSI) to preset the ACPI SCI IRQ Greg KH
2011-07-08  0:16 ` [031/107] xen/mmu: Fix for linker errors when CONFIG_SMP is not defined Greg KH
2011-07-08  0:16 ` [032/107] xen/pci: Move check for acpi_sci_override_gsi to xen_setup_acpi_sci Greg KH
2011-07-08  0:16 ` [033/107] clocksource: Make watchdog robust vs. interruption Greg KH
2011-07-08  0:16 ` [034/107] ARM: SAMSUNG: serial: Fix on handling of one clock source for UART Greg KH
2011-07-08  0:16 ` [035/107] TTY: ldisc, do not close until there are readers Greg KH
2011-07-08  0:16 ` [036/107] Connector: Set the CN_NETLINK_USERS correctly Greg KH
2011-07-08  0:16 ` [037/107] Connector: Correctly set the error code in case of success when dispatching receive callbacks Greg KH
2011-07-08  0:16 ` [038/107] xhci: Reject double add of active endpoints Greg KH
2011-07-08  0:16 ` [039/107] xhci: Add reset on resume quirk for asrock p67 host Greg KH
2011-07-08  0:16 ` [040/107] xhci: Always set urb->status to zero for isoc endpoints Greg KH
2011-07-08  0:16 ` [041/107] USB: Free bandwidth when usb_disable_device is called Greg KH
2011-07-08  0:16 ` [042/107] USB: Add new FT232H chip to drivers/usb/serial/ftdi_sio.c Greg KH
2011-07-08  0:16 ` [043/107] mm/memory-failure.c: fix page isolated count mismatch Greg KH
2011-07-08  0:16 ` [044/107] PM: Free memory bitmaps if opening /dev/snapshot fails Greg KH
2011-07-08  0:16 ` [045/107] ath5k: fix memory leak when fewer than N_PD_CURVES are in use Greg KH
2011-07-08  0:16 ` [046/107] ath5k: Disable fast channel switching by default Greg KH
2011-07-08  0:16 ` [047/107] pxa168_eth: fix race in transmit path Greg KH
2011-07-08  6:20   ` Sachin Sanap
2011-07-08 14:43     ` Greg KH
2011-07-08  0:16 ` [048/107] ath9k: Fix suspend/resume when no interface is UP Greg KH
2011-07-08  0:16 ` [049/107] x86, suspend: Restore MISC_ENABLE MSR in realmode wakeup Greg KH
2011-07-08  0:16 ` [050/107] oprofile, x86: Fix race in nmi handler while starting counters Greg KH
2011-07-08  0:16 ` [051/107] mmc: tmio: fix regression in TMIO_MMC_WRPROTECT_DISABLE handling Greg KH
2011-07-08  0:16 ` [052/107] mmc: Add PCI fixup quirks for Ricoh 1180:e823 reader Greg KH
2011-07-08  0:16 ` [053/107] mm: fix negative commitlimit when gigantic hugepages are allocated Greg KH
2011-07-08  0:16 ` [054/107] block: add REQ_SECURE to REQ_COMMON_MASK Greg KH
2011-07-08  0:16 ` [055/107] NFS41: do not update isize if inode needs layoutcommit Greg KH
2011-07-08  0:16 ` [056/107] mm, hotplug: fix error handling in mem_online_node() Greg KH
2011-07-08  0:16 ` [057/107] ALSA: HDA: Remove quirk for an HP device Greg KH
2011-07-08  0:16 ` [058/107] ALSA: HDA: Add a new Conexant codec ID (506c) Greg KH
2011-07-08  0:16 ` [059/107] [media] rc: fix ghost keypresses with certain hw Greg KH
2011-07-08  0:16 ` [060/107] [media] lirc_zilog: fix spinning rx thread Greg KH
2011-07-08  0:16 ` [061/107] [media] keymaps: fix table for pinnacle pctv hd devices Greg KH
2011-07-08  0:16 ` [062/107] [media] uvcvideo: Remove buffers from the queues when freeing Greg KH
2011-07-08  0:16 ` [063/107] [media] ite-cir: 8709 needs to use pnp resource 2 Greg KH
2011-07-08  0:16 ` [064/107] watchdog: mtx1-wdt: request gpio before using it Greg KH
2011-07-08  0:16 ` [065/107] nfsd: v4 support requires CRYPTO Greg KH
2011-07-08  0:16 ` [066/107] nfsd: fix dependency of nfsd on auth_rpcgss Greg KH
2011-07-08  0:16 ` [067/107] nfsd: link returns nfserr_delay when breaking lease Greg KH
2011-07-08  0:16 ` [068/107] nfsd4: fix break_lease flags on nfsd open Greg KH
2011-07-08  0:16 ` [069/107] NFSv4.1: allow nfs_fhget to succeed with mounted on fileid Greg KH
2011-07-08  0:16 ` [070/107] NFSv4.1: allow zero fh array in filelayout decode layout Greg KH
2011-07-08  0:16 ` [071/107] NFSv4: Fix a readdir regression Greg KH
2011-07-08  0:16 ` [072/107] Input: properly assign return value of clamp() macro Greg KH
2011-07-08  0:16 ` [073/107] debugobjects: Fix boot crash when kmemleak and debugobjects enabled Greg KH
2011-07-08  0:16 ` [074/107] cfq-iosched: fix locking around ioc->ioc_data assignment Greg KH
2011-07-08  0:16 ` [075/107] cfq-iosched: fix a rcu warning Greg KH
2011-07-08  0:16 ` [076/107] cfq-iosched: make code consistent Greg KH
2011-07-08  0:16 ` [077/107] block: use the passed in @bdev when claiming if partno is zero Greg KH
2011-07-08  0:16 ` [078/107] PCI / PM: Block races between runtime PM and system sleep Greg KH
2011-07-08  0:16 ` [079/107] PM: Rename dev_pm_info.in_suspend to is_prepared Greg KH
2011-07-08  0:16 ` [080/107] PM: Fix async resume following suspend failure Greg KH
2011-07-08  0:16 ` [081/107] PM / Hibernate: Fix free_unnecessary_pages() Greg KH
2011-07-08  0:16 ` [082/107] KEYS: Fix error handling in construct_key_and_link() Greg KH
2011-07-08  0:16 ` [083/107] i2c-taos-evm: Fix log messages Greg KH
2011-07-08  0:16 ` [084/107] i2c/pca954x: Initialize the mux to disconnected state Greg KH
2011-07-08  0:16 ` [085/107] hfsplus: add missing call to bio_put() Greg KH
2011-07-08  0:16 ` [086/107] md: avoid endless recovery loop when waiting for fail device to complete Greg KH
2011-07-08  0:16 ` [087/107] SUNRPC: Ensure the RPC client only quits on fatal signals Greg KH
2011-07-08  0:17 ` [088/107] ASoC: pxa-ssp: Correct check for stream presence Greg KH
2011-07-08  0:17 ` [089/107] drivers/base/platform.c: dont mark platform_device_register_resndata() as __init_or_module Greg KH
2011-07-08  6:47   ` Uwe Kleine-König
2011-07-08 14:43     ` Greg KH
2011-07-08  0:17 ` [090/107] fs: fix lock initialization Greg KH
2011-07-08  0:17 ` Greg KH [this message]
2011-07-08  0:17 ` [092/107] 6pack,mkiss: fix lock inconsistency Greg KH
2011-07-08  0:17 ` [093/107] iwlagn: fix change_interface for P2P types Greg KH
2011-07-08  0:17 ` [094/107] drivers/misc/lkdtm.c: fix race when crashpoint is hit multiple times before checking count Greg KH
2011-07-08  0:17 ` [095/107] taskstats: dont allow duplicate entries in listener mode Greg KH
2011-07-08  0:17 ` [096/107] Fix CPU spinlock lockups on secondary CPU bringup Greg KH
2011-07-08  0:17 ` [097/107] NLM: Dont hang forever on NLM unlock requests Greg KH
2011-07-08  0:17 ` [098/107] USB: dont let errors prevent system sleep Greg KH
2011-07-08  0:17 ` [099/107] USB: dont let the hub driver " Greg KH
2011-07-08  0:17 ` [100/107] USB: fix regression occurring during device removal Greg KH
2011-07-08  0:17 ` [101/107] ipv4: fix multicast losses Greg KH
2011-07-08  0:17 ` [102/107] netfilter: Fix ip_route_me_harder triggering ip_rt_bug Greg KH
2011-07-08  0:17 ` [103/107] vlan: fix typo in vlan_dev_hard_start_xmit() Greg KH
2011-07-08  0:17 ` [104/107] xfrm: Fix off by one in the replay advance functions Greg KH
2011-07-08  0:17 ` [105/107] Revert "KVM: Save/restore state of assigned PCI device" Greg KH
2011-07-08  0:17 ` [106/107] KVM: Fix register corruption in pvclock_scale_delta Greg KH
2011-07-08  0:17 ` [107/107] IPVS netns exit causes crash in conntrack Greg KH
2011-07-08  2:06 ` [000/107] 2.6.39.3 review Stefan Lippers-Hollmann
2011-07-08  2:49   ` Greg KH
2011-07-08  2:53   ` Greg KH

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=20110708001701.587052450@clark.kroah.org \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=dhowells@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable-review@kernel.org \
    --cc=stable@kernel.org \
    --cc=torvalds@linux-foundation.org \
    /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

all inboxes | Powered by JetHome®