Linux Headquarters
[ Register ]
[ About us ] [ Home Page ]

[ Kernel ] [ Documentation ] [ Links ] [ Books ]

Kernel v2.1.132 /mm/page_alloc.c

Filename:/mm/page_alloc.c
Lines Added:37
Lines Deleted:3
Also changed in: (Previous) 2.1.130  2.1.129  2.1.127  2.1.126  2.1.123  2.1.121 
(Following)

Location
[  2.1.132
  [  mm
     o  page_alloc.c

Patch

diff -u --recursive --new-file v2.1.131/linux/mm/page_alloc.c linux/mm/page_alloc.c
--- v2.1.131/linux/mm/page_alloc.c   Fri Nov 27 13:09:30 1998
+++ linux/mm/page_alloc.c   Sun Dec 20 05:51:07 1998
@@ -359,6 +359,38 @@
    return start_mem;
 }
 
+/* 
+ * Primitive swap readahead code. We simply read an aligned block of
+ * (1 << page_cluster) entries in the swap area. This method is chosen
+ * because it doesn't cost us any seek time.  We also make sure to queue
+ * the 'original' request together with the readahead ones...  
+ */
+void swapin_readahead(unsigned long entry)
+{
+   int i;
+   struct page *new_page;
+   unsigned long offset = SWP_OFFSET(entry);
+   struct swap_info_struct *swapdev = SWP_TYPE(entry) + swap_info;
+   
+   offset = (offset >> page_cluster) << page_cluster;
+   
+   for (i = 1 << page_cluster; i > 0; i--) {
+         if (offset >= swapdev->max
+               || nr_free_pages - atomic_read(&nr_async_pages) <
+               (freepages.high + freepages.low)/2)
+            return;
+         if (!swapdev->swap_map[offset] ||
+        swapdev->swap_map[offset] == SWAP_MAP_BAD ||
+        test_bit(offset, swapdev->swap_lockmap))
+            continue;
+         new_page = read_swap_cache_async(SWP_ENTRY(SWP_TYPE(entry), offset), 0);
+         if (new_page != NULL)
+            __free_page(new_page);
+         offset++;
+   }
+   return;
+}
+
 /*
  * The tests may look silly, but it essentially makes sure that
  * no other process did a swap-in on us just as we were waiting.
@@ -370,10 +402,12 @@
    pte_t * page_table, unsigned long entry, int write_access)
 {
    unsigned long page;
-   struct page *page_map;
-   
-   page_map = read_swap_cache(entry);
+   struct page *page_map = lookup_swap_cache(entry);
 
+   if (!page_map) {
+      swapin_readahead(entry);
+      page_map = read_swap_cache(entry);
+   }
    if (pte_val(*page_table) != entry) {
       if (page_map)
          free_page_and_swap_cache(page_address(page_map));


Comments: webmaster (at) linuxhq.com.
Advertising: banners (at) linuxhq.com.
Compilation ©1998-2008 Linux Headquarters, Inc.