CHROMIUM: low-mem: add "on" command and fix error case
authorLuigi Semenzato <semenzato@chromium.org>
Wed, 25 Apr 2012 00:28:42 +0000 (17:28 -0700)
committerGrant Grundler <grundler@google.com>
Thu, 24 May 2012 22:14:50 +0000 (15:14 -0700)
Stephan noticed that the code was not behaving correctly on invalid input,
and requested an "on" command to undo the effect of the "off" command.
Thanks Stephan!

BUG=chromium-os:29645
TEST=played around with "on", "off", valid and invalid input.

Change-Id: I73f9cf62e2571af250aa88340fc3186b0672a26d
Signed-off-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/21004
Reviewed-by: Stephan Uphoff <ups@chromium.org>
mm/low-mem-notify.c

index af0134c..c6729b2 100644 (file)
@@ -135,17 +135,22 @@ static ssize_t low_mem_margin_store(struct kobject *kobj,
                low_mem_margin_enabled = false;
                return count;
        }
+       if (strncmp("on", buf, 2) == 0) {
+               printk(KERN_INFO "low_mem: enabling notifier\n");
+               low_mem_margin_enabled = true;
+               return count;
+       }
 
        err = strict_strtoul(buf, 10, &margin);
        if (err)
                return -EINVAL;
+       if (margin * ((1024 * 1024) / PAGE_SIZE) > totalram_pages)
+               return -EINVAL;
        /* Notify when the "free" memory is below margin megabytes. */
        low_mem_margin_enabled = true;
        low_mem_margin_mb = (unsigned int) margin;
        /* Convert to pages outside the allocator fast path. */
        low_mem_minfree = low_mem_margin_to_minfree(low_mem_margin_mb);
-       if (low_mem_minfree < 0 || low_mem_minfree > totalram_pages)
-               return -EINVAL;
        printk(KERN_INFO "low_mem: setting minfree to %lu kB\n",
               low_mem_minfree * (PAGE_SIZE / 1024));
        return count;