mm: page_counter: pull "-1" handling out of page_counter_memparse()
authorJohannes Weiner <hannes@cmpxchg.org>
Wed, 11 Feb 2015 23:26:03 +0000 (15:26 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 12 Feb 2015 01:06:02 +0000 (17:06 -0800)
The unified hierarchy interface for memory cgroups will no longer use "-1"
to mean maximum possible resource value.  In preparation for this, make
the string an argument and let the caller supply it.

Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Michal Hocko <mhocko@suse.cz>
Cc: Vladimir Davydov <vdavydov@parallels.com>
Cc: Greg Thelen <gthelen@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/page_counter.h
mm/hugetlb_cgroup.c
mm/memcontrol.c
mm/page_counter.c
net/ipv4/tcp_memcontrol.c

index 955421575d16aa60ec425bfd28d458804c3d4113..17fa4f8de3a6791271780c0e489f5462492e030b 100644 (file)
@@ -41,7 +41,8 @@ int page_counter_try_charge(struct page_counter *counter,
                            struct page_counter **fail);
 void page_counter_uncharge(struct page_counter *counter, unsigned long nr_pages);
 int page_counter_limit(struct page_counter *counter, unsigned long limit);
-int page_counter_memparse(const char *buf, unsigned long *nr_pages);
+int page_counter_memparse(const char *buf, const char *max,
+                         unsigned long *nr_pages);
 
 static inline void page_counter_reset_watermark(struct page_counter *counter)
 {
index 037e1c00a5b7a8550f7e021eaf0af390ad5b625f..6e0057439a469b2cf38e9e9aee1f40a17dd08d59 100644 (file)
@@ -279,7 +279,7 @@ static ssize_t hugetlb_cgroup_write(struct kernfs_open_file *of,
                return -EINVAL;
 
        buf = strstrip(buf);
-       ret = page_counter_memparse(buf, &nr_pages);
+       ret = page_counter_memparse(buf, "-1", &nr_pages);
        if (ret)
                return ret;
 
index dc5c4cd0afdf60adcb4d05c5229fc6d2dbd1d99f..6453ea5a27aace38b9a38814a77455fadf1c105b 100644 (file)
@@ -3414,7 +3414,7 @@ static ssize_t mem_cgroup_write(struct kernfs_open_file *of,
        int ret;
 
        buf = strstrip(buf);
-       ret = page_counter_memparse(buf, &nr_pages);
+       ret = page_counter_memparse(buf, "-1", &nr_pages);
        if (ret)
                return ret;
 
@@ -3786,7 +3786,7 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg,
        unsigned long usage;
        int i, size, ret;
 
-       ret = page_counter_memparse(args, &threshold);
+       ret = page_counter_memparse(args, "-1", &threshold);
        if (ret)
                return ret;
 
index a009574fbba9976bce5cdb05c096a008055388a4..11b4beda14ba9963f5799c6b6638d8a170bd8878 100644 (file)
@@ -166,18 +166,19 @@ int page_counter_limit(struct page_counter *counter, unsigned long limit)
 /**
  * page_counter_memparse - memparse() for page counter limits
  * @buf: string to parse
+ * @max: string meaning maximum possible value
  * @nr_pages: returns the result in number of pages
  *
  * Returns -EINVAL, or 0 and @nr_pages on success.  @nr_pages will be
  * limited to %PAGE_COUNTER_MAX.
  */
-int page_counter_memparse(const char *buf, unsigned long *nr_pages)
+int page_counter_memparse(const char *buf, const char *max,
+                         unsigned long *nr_pages)
 {
-       char unlimited[] = "-1";
        char *end;
        u64 bytes;
 
-       if (!strncmp(buf, unlimited, sizeof(unlimited))) {
+       if (!strcmp(buf, max)) {
                *nr_pages = PAGE_COUNTER_MAX;
                return 0;
        }
index 272327134a1b45d9b78f5d4c49d1bf94133780a6..c2a75c6957a183867327229f738c842b9093de46 100644 (file)
@@ -120,7 +120,7 @@ static ssize_t tcp_cgroup_write(struct kernfs_open_file *of,
        switch (of_cft(of)->private) {
        case RES_LIMIT:
                /* see memcontrol.c */
-               ret = page_counter_memparse(buf, &nr_pages);
+               ret = page_counter_memparse(buf, "-1", &nr_pages);
                if (ret)
                        break;
                mutex_lock(&tcp_limit_mutex);