linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hugh Dickins <hughd@google.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Christoph Hellwig <hch@infradead.org>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH 4/14] tmpfs: add shmem_read_mapping_page_gfp
Date: Sun, 5 Jun 2011 21:27:35 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LSU.2.00.1106052126170.17116@sister.anvils> (raw)
In-Reply-To: <alpine.LSU.2.00.1106052116350.17116@sister.anvils>

Although it is used (by i915) on nothing but tmpfs, read_cache_page_gfp()
is unsuited to tmpfs, because it inserts a page into pagecache before
calling the filesystem's ->readpage: tmpfs may have pages in swapcache
which only it knows how to locate and switch to filecache.

At present tmpfs provides a ->readpage method, and copes with this by
copying pages; but soon we can simplify it by removing its ->readpage.
Provide shmem_read_mapping_page_gfp() now, ready for that transition,

Export shmem_read_mapping_page_gfp() and add it to list in shmem_fs.h,
with shmem_read_mapping_page() inline for the common mapping_gfp case.

(shmem_read_mapping_page_gfp or shmem_read_cache_page_gfp?  Generally
the read_mapping_page functions use the mapping's ->readpage, and the
read_cache_page functions use the supplied filler, so I think
read_cache_page_gfp was slightly misnamed.)

Signed-off-by: Hugh Dickins <hughd@google.com>
Cc: Christoph Hellwig <hch@infradead.org>
---
 include/linux/shmem_fs.h |   17 ++++++++++-------
 mm/shmem.c               |   23 +++++++++++++++++++++++
 2 files changed, 33 insertions(+), 7 deletions(-)

--- linux.orig/mm/shmem.c	2011-06-05 17:44:02.293916853 -0700
+++ linux/mm/shmem.c	2011-06-05 17:53:42.948796800 -0700
@@ -3035,3 +3035,26 @@ int shmem_zero_setup(struct vm_area_stru
 	vma->vm_flags |= VM_CAN_NONLINEAR;
 	return 0;
 }
+
+/**
+ * shmem_read_mapping_page_gfp - read into page cache, using specified page allocation flags.
+ * @mapping:	the page's address_space
+ * @index:	the page index
+ * @gfp:	the page allocator flags to use if allocating
+ *
+ * This behaves as a tmpfs "read_cache_page_gfp(mapping, index, gfp)",
+ * with any new page allocations done using the specified allocation flags.
+ * But read_cache_page_gfp() uses the ->readpage() method: which does not
+ * suit tmpfs, since it may have pages in swapcache, and needs to find those
+ * for itself; although drivers/gpu/drm i915 and ttm rely upon this support.
+ *
+ * Provide a stub for those callers to start using now, then later
+ * flesh it out to call shmem_getpage() with additional gfp mask, when
+ * shmem_file_splice_read() is added and shmem_readpage() is removed.
+ */
+struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,
+					 pgoff_t index, gfp_t gfp)
+{
+	return read_cache_page_gfp(mapping, index, gfp);
+}
+EXPORT_SYMBOL_GPL(shmem_read_mapping_page_gfp);
--- linux.orig/include/linux/shmem_fs.h	2011-06-05 17:50:02.000000000 -0700
+++ linux/include/linux/shmem_fs.h	2011-06-05 18:11:16.426020691 -0700
@@ -3,15 +3,9 @@
 
 #include <linux/swap.h>
 #include <linux/mempolicy.h>
+#include <linux/pagemap.h>
 #include <linux/percpu_counter.h>
 
-struct page;
-struct file;
-struct inode;
-struct super_block;
-struct user_struct;
-struct vm_area_struct;
-
 /* inode in-kernel data */
 
 #define SHMEM_NR_DIRECT 16
@@ -61,9 +55,18 @@ extern struct file *shmem_file_setup(con
 					loff_t size, unsigned long flags);
 extern int shmem_zero_setup(struct vm_area_struct *);
 extern int shmem_lock(struct file *file, int lock, struct user_struct *user);
+extern struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,
+					pgoff_t index, gfp_t gfp_mask);
 extern void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end);
 extern int shmem_unuse(swp_entry_t entry, struct page *page);
 extern void mem_cgroup_get_shmem_target(struct inode *inode, pgoff_t pgoff,
 					struct page **pagep, swp_entry_t *ent);
 
+static inline struct page *shmem_read_mapping_page(
+				struct address_space *mapping, pgoff_t index)
+{
+	return shmem_read_mapping_page_gfp(mapping, index,
+					mapping_gfp_mask(mapping));
+}
+
 #endif

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2011-06-06  4:27 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-06  4:21 [PATCH 0/14] mm: tmpfs and trunc changes, affecting drm Hugh Dickins
2011-06-06  4:23 ` [PATCH 1/14] mm: move vmtruncate_range to truncate.c Hugh Dickins
2011-06-06  4:24 ` [PATCH 2/14] mm: move shmem prototypes to shmem_fs.h Hugh Dickins
2011-06-06  4:26 ` [PATCH 3/14] tmpfs: take control of its truncate_range Hugh Dickins
2011-06-06  4:27 ` Hugh Dickins [this message]
2011-06-06  4:29 ` [PATCH 5/14] drm/ttm: use shmem_read_mapping_page Hugh Dickins
2011-06-06  4:31 ` [PATCH 6/14] drm/i915: " Hugh Dickins
2011-06-06  4:32 ` [PATCH 7/14] drm/i915: use shmem_truncate_range Hugh Dickins
2011-06-06  4:34 ` [PATCH 8/14] drm/i915: more struct_mutex locking Hugh Dickins
2011-06-06  4:35 ` [PATCH 9/14] mm: cleanup descriptions of filler arg Hugh Dickins
2011-06-06  4:36 ` [PATCH 10/14] mm: truncate functions are in truncate.c Hugh Dickins
2011-06-06  4:38 ` [PATCH 11/14] mm: tidy vmtruncate_range and related functions Hugh Dickins
2011-06-06  4:39 ` [PATCH 12/14] mm: consistent truncate and invalidate loops Hugh Dickins
2011-06-06  4:40 ` [PATCH 13/14] mm: pincer in truncate_inode_pages_range Hugh Dickins
2011-06-06  4:42 ` [PATCH 14/14] tmpfs: no need to use i_lock Hugh Dickins
  -- strict thread matches above, loose matches on Subject: below --
2011-05-31  0:33 [PATCH 0/14] mm: tmpfs and trunc changes, affecting drm Hugh Dickins
2011-05-31  0:40 ` [PATCH 4/14] tmpfs: add shmem_read_mapping_page_gfp Hugh Dickins
2011-06-01  0:42   ` Christoph Hellwig
2011-06-01 17:02     ` Hugh Dickins

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=alpine.LSU.2.00.1106052126170.17116@sister.anvils \
    --to=hughd@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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