Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 165667
b: refs/heads/master
c: f64c3f5
h: refs/heads/master
i:
  165665: ed327e2
  165663: 543aa28
v: v3
  • Loading branch information
Balbir Singh authored and Linus Torvalds committed Sep 24, 2009
1 parent 19e93aa commit c8bfdc3
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 48 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 296c81d89f4f14269f7346f81442910158c0a83a
refs/heads/master: f64c3f54940d6929a2b6dcffaab942bd62be2e66
6 changes: 4 additions & 2 deletions trunk/include/linux/res_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ void res_counter_init(struct res_counter *counter, struct res_counter *parent);
int __must_check res_counter_charge_locked(struct res_counter *counter,
unsigned long val);
int __must_check res_counter_charge(struct res_counter *counter,
unsigned long val, struct res_counter **limit_fail_at);
unsigned long val, struct res_counter **limit_fail_at,
struct res_counter **soft_limit_at);

/*
* uncharge - tell that some portion of the resource is released
Expand All @@ -127,7 +128,8 @@ int __must_check res_counter_charge(struct res_counter *counter,
*/

void res_counter_uncharge_locked(struct res_counter *counter, unsigned long val);
void res_counter_uncharge(struct res_counter *counter, unsigned long val);
void res_counter_uncharge(struct res_counter *counter, unsigned long val,
bool *was_soft_limit_excess);

static inline bool res_counter_limit_check_locked(struct res_counter *cnt)
{
Expand Down
18 changes: 16 additions & 2 deletions trunk/kernel/res_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,27 @@ int res_counter_charge_locked(struct res_counter *counter, unsigned long val)
}

int res_counter_charge(struct res_counter *counter, unsigned long val,
struct res_counter **limit_fail_at)
struct res_counter **limit_fail_at,
struct res_counter **soft_limit_fail_at)
{
int ret;
unsigned long flags;
struct res_counter *c, *u;

*limit_fail_at = NULL;
if (soft_limit_fail_at)
*soft_limit_fail_at = NULL;
local_irq_save(flags);
for (c = counter; c != NULL; c = c->parent) {
spin_lock(&c->lock);
ret = res_counter_charge_locked(c, val);
/*
* With soft limits, we return the highest ancestor
* that exceeds its soft limit
*/
if (soft_limit_fail_at &&
!res_counter_soft_limit_check_locked(c))
*soft_limit_fail_at = c;
spin_unlock(&c->lock);
if (ret < 0) {
*limit_fail_at = c;
Expand Down Expand Up @@ -75,14 +85,18 @@ void res_counter_uncharge_locked(struct res_counter *counter, unsigned long val)
counter->usage -= val;
}

void res_counter_uncharge(struct res_counter *counter, unsigned long val)
void res_counter_uncharge(struct res_counter *counter, unsigned long val,
bool *was_soft_limit_excess)
{
unsigned long flags;
struct res_counter *c;

local_irq_save(flags);
for (c = counter; c != NULL; c = c->parent) {
spin_lock(&c->lock);
if (was_soft_limit_excess)
*was_soft_limit_excess =
!res_counter_soft_limit_check_locked(c);
res_counter_uncharge_locked(c, val);
spin_unlock(&c->lock);
}
Expand Down
Loading

0 comments on commit c8bfdc3

Please sign in to comment.