scsi: hpsa: correct device resets
[linux-2.6-microblaze.git] / mm / page_counter.c
index a5ff4cb..de31470 100644 (file)
 #include <linux/bug.h>
 #include <asm/page.h>
 
-static void propagate_low_usage(struct page_counter *c, unsigned long usage)
+static void propagate_protected_usage(struct page_counter *c,
+                                     unsigned long usage)
 {
-       unsigned long low_usage, old;
+       unsigned long protected, old_protected;
        long delta;
 
        if (!c->parent)
                return;
 
-       if (!c->low && !atomic_long_read(&c->low_usage))
-               return;
+       if (c->min || atomic_long_read(&c->min_usage)) {
+               if (usage <= c->min)
+                       protected = usage;
+               else
+                       protected = 0;
+
+               old_protected = atomic_long_xchg(&c->min_usage, protected);
+               delta = protected - old_protected;
+               if (delta)
+                       atomic_long_add(delta, &c->parent->children_min_usage);
+       }
 
-       if (usage <= c->low)
-               low_usage = usage;
-       else
-               low_usage = 0;
+       if (c->low || atomic_long_read(&c->low_usage)) {
+               if (usage <= c->low)
+                       protected = usage;
+               else
+                       protected = 0;
 
-       old = atomic_long_xchg(&c->low_usage, low_usage);
-       delta = low_usage - old;
-       if (delta)
-               atomic_long_add(delta, &c->parent->children_low_usage);
+               old_protected = atomic_long_xchg(&c->low_usage, protected);
+               delta = protected - old_protected;
+               if (delta)
+                       atomic_long_add(delta, &c->parent->children_low_usage);
+       }
 }
 
 /**
@@ -45,7 +57,7 @@ void page_counter_cancel(struct page_counter *counter, unsigned long nr_pages)
        long new;
 
        new = atomic_long_sub_return(nr_pages, &counter->usage);
-       propagate_low_usage(counter, new);
+       propagate_protected_usage(counter, new);
        /* More uncharges than charges? */
        WARN_ON_ONCE(new < 0);
 }
@@ -65,7 +77,7 @@ void page_counter_charge(struct page_counter *counter, unsigned long nr_pages)
                long new;
 
                new = atomic_long_add_return(nr_pages, &c->usage);
-               propagate_low_usage(counter, new);
+               propagate_protected_usage(counter, new);
                /*
                 * This is indeed racy, but we can live with some
                 * inaccuracy in the watermark.
@@ -109,7 +121,7 @@ bool page_counter_try_charge(struct page_counter *counter,
                new = atomic_long_add_return(nr_pages, &c->usage);
                if (new > c->max) {
                        atomic_long_sub(nr_pages, &c->usage);
-                       propagate_low_usage(counter, new);
+                       propagate_protected_usage(counter, new);
                        /*
                         * This is racy, but we can live with some
                         * inaccuracy in the failcnt.
@@ -118,7 +130,7 @@ bool page_counter_try_charge(struct page_counter *counter,
                        *fail = c;
                        goto failed;
                }
-               propagate_low_usage(counter, new);
+               propagate_protected_usage(counter, new);
                /*
                 * Just like with failcnt, we can live with some
                 * inaccuracy in the watermark.
@@ -190,6 +202,23 @@ int page_counter_set_max(struct page_counter *counter, unsigned long nr_pages)
        }
 }
 
+/**
+ * page_counter_set_min - set the amount of protected memory
+ * @counter: counter
+ * @nr_pages: value to set
+ *
+ * The caller must serialize invocations on the same counter.
+ */
+void page_counter_set_min(struct page_counter *counter, unsigned long nr_pages)
+{
+       struct page_counter *c;
+
+       counter->min = nr_pages;
+
+       for (c = counter; c; c = c->parent)
+               propagate_protected_usage(c, atomic_long_read(&c->usage));
+}
+
 /**
  * page_counter_set_low - set the amount of protected memory
  * @counter: counter
@@ -204,7 +233,7 @@ void page_counter_set_low(struct page_counter *counter, unsigned long nr_pages)
        counter->low = nr_pages;
 
        for (c = counter; c; c = c->parent)
-               propagate_low_usage(c, atomic_long_read(&c->usage));
+               propagate_protected_usage(c, atomic_long_read(&c->usage));
 }
 
 /**