Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 165666
b: refs/heads/master
c: 296c81d
h: refs/heads/master
v: v3
  • Loading branch information
Balbir Singh authored and Linus Torvalds committed Sep 24, 2009
1 parent ed327e2 commit 19e93aa
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: a6df63615b943dbef22df04c19f4506330fe835e
refs/heads/master: 296c81d89f4f14269f7346f81442910158c0a83a
58 changes: 58 additions & 0 deletions trunk/include/linux/res_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ struct res_counter {
* the limit that usage cannot exceed
*/
unsigned long long limit;
/*
* the limit that usage can be exceed
*/
unsigned long long soft_limit;
/*
* the number of unsuccessful attempts to consume the resource
*/
Expand Down Expand Up @@ -87,6 +91,7 @@ enum {
RES_MAX_USAGE,
RES_LIMIT,
RES_FAILCNT,
RES_SOFT_LIMIT,
};

/*
Expand Down Expand Up @@ -132,6 +137,36 @@ static inline bool res_counter_limit_check_locked(struct res_counter *cnt)
return false;
}

static inline bool res_counter_soft_limit_check_locked(struct res_counter *cnt)
{
if (cnt->usage < cnt->soft_limit)
return true;

return false;
}

/**
* Get the difference between the usage and the soft limit
* @cnt: The counter
*
* Returns 0 if usage is less than or equal to soft limit
* The difference between usage and soft limit, otherwise.
*/
static inline unsigned long long
res_counter_soft_limit_excess(struct res_counter *cnt)
{
unsigned long long excess;
unsigned long flags;

spin_lock_irqsave(&cnt->lock, flags);
if (cnt->usage <= cnt->soft_limit)
excess = 0;
else
excess = cnt->usage - cnt->soft_limit;
spin_unlock_irqrestore(&cnt->lock, flags);
return excess;
}

/*
* Helper function to detect if the cgroup is within it's limit or
* not. It's currently called from cgroup_rss_prepare()
Expand All @@ -147,6 +182,17 @@ static inline bool res_counter_check_under_limit(struct res_counter *cnt)
return ret;
}

static inline bool res_counter_check_under_soft_limit(struct res_counter *cnt)
{
bool ret;
unsigned long flags;

spin_lock_irqsave(&cnt->lock, flags);
ret = res_counter_soft_limit_check_locked(cnt);
spin_unlock_irqrestore(&cnt->lock, flags);
return ret;
}

static inline void res_counter_reset_max(struct res_counter *cnt)
{
unsigned long flags;
Expand Down Expand Up @@ -180,4 +226,16 @@ static inline int res_counter_set_limit(struct res_counter *cnt,
return ret;
}

static inline int
res_counter_set_soft_limit(struct res_counter *cnt,
unsigned long long soft_limit)
{
unsigned long flags;

spin_lock_irqsave(&cnt->lock, flags);
cnt->soft_limit = soft_limit;
spin_unlock_irqrestore(&cnt->lock, flags);
return 0;
}

#endif
3 changes: 3 additions & 0 deletions trunk/kernel/res_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void res_counter_init(struct res_counter *counter, struct res_counter *parent)
{
spin_lock_init(&counter->lock);
counter->limit = RESOURCE_MAX;
counter->soft_limit = RESOURCE_MAX;
counter->parent = parent;
}

Expand Down Expand Up @@ -101,6 +102,8 @@ res_counter_member(struct res_counter *counter, int member)
return &counter->limit;
case RES_FAILCNT:
return &counter->failcnt;
case RES_SOFT_LIMIT:
return &counter->soft_limit;
};

BUG();
Expand Down
20 changes: 20 additions & 0 deletions trunk/mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -2123,6 +2123,20 @@ static int mem_cgroup_write(struct cgroup *cont, struct cftype *cft,
else
ret = mem_cgroup_resize_memsw_limit(memcg, val);
break;
case RES_SOFT_LIMIT:
ret = res_counter_memparse_write_strategy(buffer, &val);
if (ret)
break;
/*
* For memsw, soft limits are hard to implement in terms
* of semantics, for now, we support soft limits for
* control without swap
*/
if (type == _MEM)
ret = res_counter_set_soft_limit(&memcg->res, val);
else
ret = -EINVAL;
break;
default:
ret = -EINVAL; /* should be BUG() ? */
break;
Expand Down Expand Up @@ -2375,6 +2389,12 @@ static struct cftype mem_cgroup_files[] = {
.write_string = mem_cgroup_write,
.read_u64 = mem_cgroup_read,
},
{
.name = "soft_limit_in_bytes",
.private = MEMFILE_PRIVATE(_MEM, RES_SOFT_LIMIT),
.write_string = mem_cgroup_write,
.read_u64 = mem_cgroup_read,
},
{
.name = "failcnt",
.private = MEMFILE_PRIVATE(_MEM, RES_FAILCNT),
Expand Down

0 comments on commit 19e93aa

Please sign in to comment.