Linux 6.9-rc1
[linux-2.6-microblaze.git] / mm / page_counter.c
index eb156ff..db20d64 100644 (file)
@@ -17,24 +17,23 @@ static void propagate_protected_usage(struct page_counter *c,
                                      unsigned long usage)
 {
        unsigned long protected, old_protected;
-       unsigned long low, min;
        long delta;
 
        if (!c->parent)
                return;
 
-       min = READ_ONCE(c->min);
-       if (min || atomic_long_read(&c->min_usage)) {
-               protected = min(usage, min);
+       protected = min(usage, READ_ONCE(c->min));
+       old_protected = atomic_long_read(&c->min_usage);
+       if (protected != old_protected) {
                old_protected = atomic_long_xchg(&c->min_usage, protected);
                delta = protected - old_protected;
                if (delta)
                        atomic_long_add(delta, &c->parent->children_min_usage);
        }
 
-       low = READ_ONCE(c->low);
-       if (low || atomic_long_read(&c->low_usage)) {
-               protected = min(usage, low);
+       protected = min(usage, READ_ONCE(c->low));
+       old_protected = atomic_long_read(&c->low_usage);
+       if (protected != old_protected) {
                old_protected = atomic_long_xchg(&c->low_usage, protected);
                delta = protected - old_protected;
                if (delta)
@@ -193,7 +192,7 @@ int page_counter_set_max(struct page_counter *counter, unsigned long nr_pages)
 
                old = xchg(&counter->max, nr_pages);
 
-               if (page_counter_read(counter) <= usage)
+               if (page_counter_read(counter) <= usage || nr_pages >= old)
                        return 0;
 
                counter->max = old;