+/*
+ * Populate a set of pages with data for the Linux page cache. This
+ * function will only be called for read ahead and never for demand
+ * paging. For simplicity, the code relies on read_cache_pages() to
+ * correctly lock each page for IO and call zpl_readpage().
+ */
+static int
+zpl_readpages(struct file *filp, struct address_space *mapping,
+ struct list_head *pages, unsigned nr_pages)
+{
+ return (read_cache_pages(mapping, pages,
+ (filler_t *)zpl_readpage, filp));
+}
+
+int
+zpl_putpage(struct page *pp, struct writeback_control *wbc, void *data)
+{
+ struct address_space *mapping = data;
+
+ ASSERT(PageLocked(pp));
+ ASSERT(!PageWriteback(pp));
+
+ /*
+ * Disable the normal reclaim path for zpl_putpage(). This
+ * ensures that all memory allocations under this call path
+ * will never enter direct reclaim. If this were to happen
+ * the VM might try to write out additional pages by calling
+ * zpl_putpage() again resulting in a deadlock.
+ */
+ if (current->flags & PF_MEMALLOC) {
+ (void) zfs_putpage(mapping->host, pp, wbc);
+ } else {
+ current->flags |= PF_MEMALLOC;
+ (void) zfs_putpage(mapping->host, pp, wbc);
+ current->flags &= ~PF_MEMALLOC;
+ }
+
+ return (0);
+}
+
+static int
+zpl_writepages(struct address_space *mapping, struct writeback_control *wbc)
+{
+ return write_cache_pages(mapping, wbc, zpl_putpage, mapping);