Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / mm / thrash.c
index 7183937..f4c560b 100644 (file)
 #include <linux/sched.h>
 #include <linux/swap.h>
 
-static spinlock_t swap_token_lock = SPIN_LOCK_UNLOCKED;
+static DEFINE_SPINLOCK(swap_token_lock);
 static unsigned long swap_token_timeout;
-unsigned long swap_token_check;
+static unsigned long swap_token_check;
 struct mm_struct * swap_token_mm = &init_mm;
 
 #define SWAP_TOKEN_CHECK_INTERVAL (HZ * 2)
-#define SWAP_TOKEN_TIMEOUT (HZ * 300)
+#define SWAP_TOKEN_TIMEOUT     (300 * HZ)
+/*
+ * Currently disabled; Needs further code to work at HZ * 300.
+ */
+unsigned long swap_token_default_timeout = SWAP_TOKEN_TIMEOUT;
 
 /*
  * Take the token away if the process had no page faults
@@ -53,14 +57,17 @@ void grab_swap_token(void)
        /* We have the token. Let others know we still need it. */
        if (has_swap_token(current->mm)) {
                current->mm->recent_pagein = 1;
+               if (unlikely(!swap_token_default_timeout))
+                       disable_swap_token();
                return;
        }
 
        if (time_after(jiffies, swap_token_check)) {
 
-               /* Can't get swapout protection if we exceed our RSS limit. */
-               // if (current->mm->rss > current->mm->rlimit_rss)
-               //      return;
+               if (!swap_token_default_timeout) {
+                       swap_token_check = jiffies + SWAP_TOKEN_CHECK_INTERVAL;
+                       return;
+               }
 
                /* ... or if we recently held the token. */
                if (time_before(jiffies, current->mm->swap_token_time))
@@ -75,10 +82,10 @@ void grab_swap_token(void)
                if ((reason = should_release_swap_token(mm))) {
                        unsigned long eligible = jiffies;
                        if (reason == SWAP_TOKEN_TIMED_OUT) {
-                               eligible += SWAP_TOKEN_TIMEOUT;
+                               eligible += swap_token_default_timeout;
                        }
                        mm->swap_token_time = eligible;
-                       swap_token_timeout = jiffies + SWAP_TOKEN_TIMEOUT;
+                       swap_token_timeout = jiffies + swap_token_default_timeout;
                        swap_token_mm = current->mm;
                }
                spin_unlock(&swap_token_lock);
@@ -91,6 +98,7 @@ void __put_swap_token(struct mm_struct *mm)
 {
        spin_lock(&swap_token_lock);
        if (likely(mm == swap_token_mm)) {
+               mm->swap_token_time = jiffies + SWAP_TOKEN_CHECK_INTERVAL;
                swap_token_mm = &init_mm;
                swap_token_check = jiffies;
        }