]> err.no Git - linux-2.6/blobdiff - mm/readahead.c
remove ZERO_PAGE
[linux-2.6] / mm / readahead.c
index be20c9d699d3111f0f75d346deec70d8878fd54d..fc52f9f1b80cb08695c2379ed8faf5d761021293 100644 (file)
@@ -22,16 +22,8 @@ void default_unplug_io_fn(struct backing_dev_info *bdi, struct page *page)
 }
 EXPORT_SYMBOL(default_unplug_io_fn);
 
-/*
- * Convienent macros for min/max read-ahead pages.
- * Note that MAX_RA_PAGES is rounded down, while MIN_RA_PAGES is rounded up.
- * The latter is necessary for systems with large page size(i.e. 64k).
- */
-#define MAX_RA_PAGES   (VM_MAX_READAHEAD*1024 / PAGE_CACHE_SIZE)
-#define MIN_RA_PAGES   DIV_ROUND_UP(VM_MIN_READAHEAD*1024, PAGE_CACHE_SIZE)
-
 struct backing_dev_info default_backing_dev_info = {
-       .ra_pages       = MAX_RA_PAGES,
+       .ra_pages       = VM_MAX_READAHEAD * 1024 / PAGE_CACHE_SIZE,
        .state          = 0,
        .capabilities   = BDI_CAP_MAP_COPY,
        .unplug_io_fn   = default_unplug_io_fn,
@@ -46,7 +38,7 @@ void
 file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping)
 {
        ra->ra_pages = mapping->backing_dev_info->ra_pages;
-       ra->prev_index = -1;
+       ra->prev_pos = -1;
 }
 EXPORT_SYMBOL_GPL(file_ra_state_init);
 
@@ -327,7 +319,7 @@ static unsigned long get_next_ra_size(struct file_ra_state *ra,
  * indicator. The flag won't be set on already cached pages, to avoid the
  * readahead-for-nothing fuss, saving pointless page cache lookups.
  *
- * prev_index tracks the last visited page in the _previous_ read request.
+ * prev_pos tracks the last visited byte in the _previous_ read request.
  * It should be maintained by the caller, and will be used for detecting
  * small random reads. Note that the readahead algorithm checks loosely
  * for sequential patterns. Hence interleaved reads might be served as
@@ -351,11 +343,9 @@ ondemand_readahead(struct address_space *mapping,
                   bool hit_readahead_marker, pgoff_t offset,
                   unsigned long req_size)
 {
-       unsigned long max;      /* max readahead pages */
-       int sequential;
-
-       max = ra->ra_pages;
-       sequential = (offset - ra->prev_index <= 1UL) || (req_size > max);
+       int     max = ra->ra_pages;     /* max readahead pages */
+       pgoff_t prev_offset;
+       int     sequential;
 
        /*
         * It's the expected callback offset, assume sequential access.
@@ -369,6 +359,9 @@ ondemand_readahead(struct address_space *mapping,
                goto readit;
        }
 
+       prev_offset = ra->prev_pos >> PAGE_CACHE_SHIFT;
+       sequential = offset - prev_offset <= 1UL || req_size > max;
+
        /*
         * Standalone, small read.
         * Read as is, and do not pollute the readahead state.
@@ -378,6 +371,29 @@ ondemand_readahead(struct address_space *mapping,
                                                offset, req_size, 0);
        }
 
+       /*
+        * Hit a marked page without valid readahead state.
+        * E.g. interleaved reads.
+        * Query the pagecache for async_size, which normally equals to
+        * readahead size. Ramp it up and use it as the new readahead size.
+        */
+       if (hit_readahead_marker) {
+               pgoff_t start;
+
+               read_lock_irq(&mapping->tree_lock);
+               start = radix_tree_next_hole(&mapping->page_tree, offset, max+1);
+               read_unlock_irq(&mapping->tree_lock);
+
+               if (!start || start - offset > max)
+                       return 0;
+
+               ra->start = start;
+               ra->size = start - offset;      /* old async_size */
+               ra->size = get_next_ra_size(ra, max);
+               ra->async_size = ra->size;
+               goto readit;
+       }
+
        /*
         * It may be one of
         *      - first read on start of file
@@ -389,16 +405,6 @@ ondemand_readahead(struct address_space *mapping,
        ra->size = get_init_ra_size(req_size, max);
        ra->async_size = ra->size > req_size ? ra->size - req_size : ra->size;
 
-       /*
-        * Hit on a marked page without valid readahead state.
-        * E.g. interleaved reads.
-        * Not knowing its readahead pos/size, bet on the minimal possible one.
-        */
-       if (hit_readahead_marker) {
-               ra->start++;
-               ra->size = get_next_ra_size(ra, max);
-       }
-
 readit:
        return ra_submit(ra, mapping, filp);
 }