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

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

Advertisement

Kernel v2.4.13-ac6 /mm/swapfile.c

Filename:/mm/swapfile.c
Lines Added:45
Lines Deleted:16
Also changed in: (Previous) 2.4.13-ac5  2.4.13-ac4  2.4.13-ac3  2.4.13-ac1  2.4.13-ac2  2.4.13 
(Following) 2.4.13-ac7  2.4.13-ac8  2.4.14-pre7  2.4.14-pre8  2.4.14  2.4.17-rc2 

Location
[  2.4.13-ac6
  [  mm
     o  swapfile.c

Patch

diff -u --new-file --recursive --exclude-from /usr/src/exclude linux.vanilla/mm/swapfile.c linux.ac/mm/swapfile.c
--- linux.vanilla/mm/swapfile.c   Thu Oct 25 16:26:39 2001
+++ linux.ac/mm/swapfile.c   Fri Oct 26 22:29:37 2001
@@ -14,7 +14,6 @@
 #include <linux/vmalloc.h>
 #include <linux/pagemap.h>
 #include <linux/shm.h>
-#include <linux/compiler.h>
 
 #include <asm/pgtable.h>
 
@@ -32,6 +31,25 @@
 
 struct swap_info_struct swap_info[MAX_SWAPFILES];
 
+/*
+ * When swap space gets filled up, we will set this flag.
+ * This will make do_swap_page(), in the page fault path,
+ * free swap entries on swapin so we'll reclaim swap space
+ * in order to be able to swap something out.
+ *
+ * At the moment we start reclaiming when swap usage goes
+ * over 80% of swap space.
+ *
+ * XXX: Random numbers, fixme.
+ */
+#define SWAP_FULL_PCT 80
+int vm_swap_full (void)
+{
+   int swap_used = total_swap_pages - nr_swap_pages;
+
+   return swap_used * 100 > total_swap_pages * SWAP_FULL_PCT;
+}
+
 #define SWAPFILE_CLUSTER 256
 
 static inline int scan_swap_map(struct swap_info_struct *si)
@@ -215,9 +233,9 @@
 {
    pte_t pte = *dir;
 
-   if (likely(pte_to_swp_entry(pte).val != entry.val))
+   if (pte_to_swp_entry(pte).val != entry.val)
       return;
-   if (unlikely(pte_none(pte) || pte_present(pte)))
+   if (pte_none(pte) || pte_present(pte))
       return;
    get_page(page);
    set_pte(dir, pte_mkold(mk_pte(page, vma->vm_page_prot)));
@@ -576,8 +594,14 @@
    for (type = swap_list.head; type >= 0; type = swap_info[type].next) {
       p = swap_info + type;
       if ((p->flags & SWP_WRITEOK) == SWP_WRITEOK) {
-         if (p->swap_file == nd.dentry)
-           break;
+         if (p->swap_file) {
+            if (p->swap_file == nd.dentry)
+              break;
+         } else {
+            if (S_ISBLK(nd.dentry->d_inode->i_mode)
+                && (p->swap_device == nd.dentry->d_inode->i_rdev))
+              break;
+         }
       }
       prev = type;
    }
@@ -781,23 +805,28 @@
       if (!dev || (blk_size[MAJOR(dev)] &&
            !blk_size[MAJOR(dev)][MINOR(dev)]))
          goto bad_swap;
+      error = -EBUSY;
+      for (i = 0 ; i < nr_swapfiles ; i++) {
+         if (i == type)
+            continue;
+         if (dev == swap_info[i].swap_device)
+            goto bad_swap;
+      }
       swapfilesize = 0;
       if (blk_size[MAJOR(dev)])
          swapfilesize = blk_size[MAJOR(dev)][MINOR(dev)]
             >> (PAGE_SHIFT - 10);
-   } else if (S_ISREG(swap_inode->i_mode))
+   } else if (S_ISREG(swap_inode->i_mode)) {
+      error = -EBUSY;
+      for (i = 0 ; i < nr_swapfiles ; i++) {
+         if (i == type || !swap_info[i].swap_file)
+            continue;
+         if (swap_inode == swap_info[i].swap_file->d_inode)
+            goto bad_swap;
+      }
       swapfilesize = swap_inode->i_size >> PAGE_SHIFT;
-   else
+   } else
       goto bad_swap;
-
-   error = -EBUSY;
-   for (i = 0 ; i < nr_swapfiles ; i++) {
-      struct swap_info_struct *q = &swap_info[i];
-      if (i == type || !q->swap_file)
-         continue;
-      if (swap_inode->i_mapping == q->swap_file->d_inode->i_mapping)
-         goto bad_swap;
-   }
 
    swap_header = (void *) __get_free_page(GFP_USER);
    if (!swap_header) {


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