mm: introduce and use mapping_empty()
[linux-2.6-block.git] / include / linux / pagemap.h
index 4c1ffe1d5dac93d0765ab79b903c9cb960118083..a4bd41128bf318eb4ae536c56ccda93e6e29b436 100644 (file)
 
 struct pagevec;
 
+static inline bool mapping_empty(struct address_space *mapping)
+{
+       return xa_empty(&mapping->i_pages);
+}
+
 /*
  * Bits in mapping->flags.
  */
@@ -157,6 +162,16 @@ static inline void filemap_nr_thps_dec(struct address_space *mapping)
 
 void release_pages(struct page **pages, int nr);
 
+/*
+ * For file cache pages, return the address_space, otherwise return NULL
+ */
+static inline struct address_space *page_mapping_file(struct page *page)
+{
+       if (unlikely(PageSwapCache(page)))
+               return NULL;
+       return page_mapping(page);
+}
+
 /*
  * speculatively take a reference to a page.
  * If the page is free (_refcount == 0), then _refcount is untouched, and 0
@@ -688,6 +703,26 @@ void wait_for_stable_page(struct page *page);
 
 void page_endio(struct page *page, bool is_write, int err);
 
+/**
+ * set_page_private_2 - Set PG_private_2 on a page and take a ref
+ * @page: The page.
+ *
+ * Set the PG_private_2 flag on a page and take the reference needed for the VM
+ * to handle its lifetime correctly.  This sets the flag and takes the
+ * reference unconditionally, so care must be taken not to set the flag again
+ * if it's already set.
+ */
+static inline void set_page_private_2(struct page *page)
+{
+       page = compound_head(page);
+       get_page(page);
+       SetPagePrivate2(page);
+}
+
+void end_page_private_2(struct page *page);
+void wait_on_page_private_2(struct page *page);
+int wait_on_page_private_2_killable(struct page *page);
+
 /*
  * Add an arbitrary waiter to a page's wait queue
  */
@@ -792,20 +827,23 @@ static inline int add_to_page_cache(struct page *page,
  * @file: The file, used primarily by network filesystems for authentication.
  *       May be NULL if invoked internally by the filesystem.
  * @mapping: Readahead this filesystem object.
+ * @ra: File readahead state.  May be NULL.
  */
 struct readahead_control {
        struct file *file;
        struct address_space *mapping;
+       struct file_ra_state *ra;
 /* private: use the readahead_* accessors instead */
        pgoff_t _index;
        unsigned int _nr_pages;
        unsigned int _batch_count;
 };
 
-#define DEFINE_READAHEAD(rac, f, m, i)                                 \
-       struct readahead_control rac = {                                \
+#define DEFINE_READAHEAD(ractl, f, r, m, i)                            \
+       struct readahead_control ractl = {                              \
                .file = f,                                              \
                .mapping = m,                                           \
+               .ra = r,                                                \
                ._index = i,                                            \
        }
 
@@ -813,10 +851,11 @@ struct readahead_control {
 
 void page_cache_ra_unbounded(struct readahead_control *,
                unsigned long nr_to_read, unsigned long lookahead_count);
-void page_cache_sync_ra(struct readahead_control *, struct file_ra_state *,
+void page_cache_sync_ra(struct readahead_control *, unsigned long req_count);
+void page_cache_async_ra(struct readahead_control *, struct page *,
                unsigned long req_count);
-void page_cache_async_ra(struct readahead_control *, struct file_ra_state *,
-               struct page *, unsigned long req_count);
+void readahead_expand(struct readahead_control *ractl,
+                     loff_t new_start, size_t new_len);
 
 /**
  * page_cache_sync_readahead - generic file readahead
@@ -836,8 +875,8 @@ void page_cache_sync_readahead(struct address_space *mapping,
                struct file_ra_state *ra, struct file *file, pgoff_t index,
                unsigned long req_count)
 {
-       DEFINE_READAHEAD(ractl, file, mapping, index);
-       page_cache_sync_ra(&ractl, ra, req_count);
+       DEFINE_READAHEAD(ractl, file, ra, mapping, index);
+       page_cache_sync_ra(&ractl, req_count);
 }
 
 /**
@@ -859,8 +898,8 @@ void page_cache_async_readahead(struct address_space *mapping,
                struct file_ra_state *ra, struct file *file,
                struct page *page, pgoff_t index, unsigned long req_count)
 {
-       DEFINE_READAHEAD(ractl, file, mapping, index);
-       page_cache_async_ra(&ractl, ra, page, req_count);
+       DEFINE_READAHEAD(ractl, file, ra, mapping, index);
+       page_cache_async_ra(&ractl, page, req_count);
 }
 
 /**