Skip to content

Commit

Permalink
mm: page_counter: pull "-1" handling out of page_counter_memparse()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Cc: Vladimir Davydov <[email protected]>
Cc: Greg Thelen <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
hnaz authored and torvalds committed Feb 12, 2015
1 parent 8d29e18 commit 650c5e5
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion include/linux/page_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion mm/hugetlb_cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
7 changes: 4 additions & 3 deletions mm/page_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/tcp_memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 650c5e5

Please sign in to comment.