Skip to contentSkip to conversation

res_counter: fix off-by-one bug in setting limit

PATCH In review Li Zefan 4 participants 6 messages Sep 1, 2008

lore
Share & tools
lore

Li Zefan

author
#0 lore raw

PATCH 1/1 res_counter: fix off-by-one bug in setting limit

I found we can no longer set limit to 0 with 2.6.27-rcX:

 # mount -t cgroup -omemory xxx /mnt
 # mkdir /mnt/0
 # echo 0 > /mnt/0/memory.limit_in_bytes
 bash: echo: write error: Device or resource busy

It turned out 'limit' can't be set to 'usage', which is wrong IMO.

---
 include/linux/res_counter.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/res_counter.h +1 -1
index fdeadd9..271c1c2 100644
@@ -166,7 +166,7 @@ static inline int res_counter_set_limit(struct res_counter *cnt,
 	int ret = -EBUSY;
 
 	spin_lock_irqsave(&cnt->lock, flags);
-	if (cnt->usage < limit) {
+	if (cnt->usage <= limit) {
 		cnt->limit = limit;
 		ret = 0;
 	}

-- 1.5.4.rc3

#1 lore raw
Quoted 9 lines · On Mon, 01 Sep 2008 13:08:55 +0800 Li Zefan <[email protected]> wrote:

I found we can no longer set limit to 0 with 2.6.27-rcX:

 # mount -t cgroup -omemory xxx /mnt
 # mkdir /mnt/0
 # echo 0 > /mnt/0/memory.limit_in_bytes
 bash: echo: write error: Device or resource busy

It turned out 'limit' can't be set to 'usage', which is wrong IMO.

But setting limit to 0(usage) in memcg is buggy operation unless you want to see OOM.. Hmm..

Thanks,
-Kame

Quoted 19 lines
---
 include/linux/res_counter.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/res_counter.h +1 -2
index fdeadd9..271c1c2 100644
@@ -166,7 +166,7 @@ static inline int res_counter_set_limit(struct res_counter *cnt,
 	int ret = -EBUSY;
 
 	spin_lock_irqsave(&cnt->lock, flags);
-	if (cnt->usage < limit) {
+	if (cnt->usage <= limit) {
 		cnt->limit = limit;
 		ret = 0;
 	}
-- 1.5.4.rc3 
author
#2 lore raw
Quoted 9 lines · KAMEZAWA Hiroyuki
Quoted 6 lines · On Mon, 01 Sep 2008 13:08:55 +0800 Li Zefan <[email protected]> wrote:

I found we can no longer set limit to 0 with 2.6.27-rcX:

 # mount -t cgroup -omemory xxx /mnt
 # mkdir /mnt/0
 # echo 0 > /mnt/0/memory.limit_in_bytes
 bash: echo: write error: Device or resource busy
Quoted 7 lines
Quoted 3 lines

It turned out 'limit' can't be set to 'usage', which is wrong IMO.

But setting limit to 0(usage) in memcg is buggy operation unless you want to see OOM.. Hmm..

I used to set 0 limit to test OOM in memcg. I don't think 0 limit is buggy, there's no much difference with 0 limit and a very low limit.

And the real issue is, now we can set limit to > usage, but not >= usage. It's odd that usage can reach to limit but limit can't be shrinked to usage.

#3 lore raw
Quoted 18 lines · On Mon, 01 Sep 2008 13:43:57 +0800 Li Zefan <[email protected]> wrote:
Quoted 9 lines · KAMEZAWA Hiroyuki
Quoted 6 lines · On Mon, 01 Sep 2008 13:08:55 +0800 Li Zefan <[email protected]> wrote:

I found we can no longer set limit to 0 with 2.6.27-rcX:

 # mount -t cgroup -omemory xxx /mnt
 # mkdir /mnt/0
 # echo 0 > /mnt/0/memory.limit_in_bytes
 bash: echo: write error: Device or resource busy
Quoted 7 lines
Quoted 3 lines

It turned out 'limit' can't be set to 'usage', which is wrong IMO.

But setting limit to 0(usage) in memcg is buggy operation unless you want to see OOM.. Hmm..

Quoted 6 lines

I used to set 0 limit to test OOM in memcg. I don't think 0 limit is buggy, there's no much difference with 0 limit and a very low limit.

And the real issue is, now we can set limit to > usage, but not >= usage. It's odd that usage can reach to limit but limit can't be shrinked to usage.

ok.

Acked-by on v1 1/1
#4 lore raw
In reply to Li Zefan
Quoted 9 lines · Li Zefan

I found we can no longer set limit to 0 with 2.6.27-rcX:

 # mount -t cgroup -omemory xxx /mnt
 # mkdir /mnt/0
 # echo 0 > /mnt/0/memory.limit_in_bytes
 bash: echo: write error: Device or resource busy

It turned out 'limit' can't be set to 'usage', which is wrong IMO.

OK, based on Kamezawa's feedback and looking at the patch

Signature · 1 line
	Balbir