Skip to contentSkip to conversation

Bug in 2.4.26 in mm/filemap.c when using RLIMIT_RSS

DISCUSSION Ake 3 participants 7 messages Jan 26, 2005 – Jan 28, 2005

Subsystems (2)
lore
Share & tools
lore

Ake

author
#0 lore raw

Use of rlim[RLIMIT_RSS] in mm/filemap.c is wrong.
It is passed down to kernel as a number of bytes but is being used as a number of pages.

There is also a misinformative comment in fs/proc/array.c in proc_pid_stat where it says
mm ? mm->rss : 0, /* you might want to shift this left 3 */ the number 3 should probably be PAGE_SHIFT-10.

Signature · 3 lines
Ake Sandgren, HPC2N, Umea University, S-90187 Umea, Sweden
Internet: [email protected]	Phone: +46 90 7866134 Fax: +46 90 7866126
Mobile: +46 70 7716134 WWW: http://www.hpc2n.umu.se
#1 lore raw
Quoted 8 lines · Ake

Use of rlim[RLIMIT_RSS] in mm/filemap.c is wrong.
It is passed down to kernel as a number of bytes but is being used as a number of pages.

There is also a misinformative comment in fs/proc/array.c in proc_pid_stat where it says
mm ? mm->rss : 0, /* you might want to shift this left 3 */ the number 3 should probably be PAGE_SHIFT-10.

Amazing that this has never been noticed before - I bet not many people use RSS limits with madvise().

This transform the rlimit in pages before the comparison, can you please test it.

mm/filemap.c renamed from mm/filemap.c.orig +3 -0
@@ -2609,6 +2609,9 @@
 	error = -EIO;
 	rlim_rss = current->rlim ?  current->rlim[RLIMIT_RSS].rlim_cur :
 				LONG_MAX; /* default: see resource.h */
+
+	rlim_rss = (rlim_rss & PAGE_MASK) >> PAGE_SHIFT;
+
 	if ((vma->vm_mm->rss + (end - start)) > rlim_rss)
 		return error;
 
author
#2 lore raw
Quoted 4 lines · Marcelo Tosatti
Quoted 4 lines

There is also a misinformative comment in fs/proc/array.c in proc_pid_stat where it says
mm ? mm->rss : 0, /* you might want to shift this left 3 */ the number 3 should probably be PAGE_SHIFT-10.

Don't forget the comment (it's still there in 2.6) :-)

Quoted 2 lines

Amazing that this has never been noticed before - I bet not many people use RSS limits with madvise().

Neither do we. :-)

I just found it when trying to figure out if the kernel actually used any of the rlimits and if so how.
(Trying to make PBS work correctly)

Quoted 6 lines

This transform the rlimit in pages before the comparison, can you please test it.

mm/filemap.c line 2616

Quoted 8 lines
mm/filemap.c renamed from mm/filemap.c.orig +3 -0
@@ -2609,6 +2609,9 @@
 	error = -EIO;
 	rlim_rss = current->rlim ?  current->rlim[RLIMIT_RSS].rlim_cur :
 				LONG_MAX; /* default: see resource.h */
+
+	rlim_rss = (rlim_rss & PAGE_MASK) >> PAGE_SHIFT;
+
 	if ((vma->vm_mm->rss + (end - start)) > rlim_rss)
 		return error;

Since we don't use it i can't really test it, but a visual inspection is good enough in this simple case. And since this is the only place in 2.4 that RLIMIT_RSS is used, the problem is solved.

BTW do you know if there is any plans for 2.6++ to actually use RLIMIT_RSS? I saw a hint in that direction in mm/thrash.c grab_swap_token but it is commented out and only skeleton code...

I'm asking since the above code piece has been removed.

Signature · 3 lines
Ake Sandgren, HPC2N, Umea University, S-90187 Umea, Sweden
Internet: [email protected]	Phone: +46 90 7866134 Fax: +46 90 7866126
Mobile: +46 70 7716134 WWW: http://www.hpc2n.umu.se
#3 lore raw
Quoted 36 lines · Ake
Quoted 4 lines · Marcelo Tosatti
Quoted 1 line

There is also a misinformative comment in fs/proc/array.c

in proc_pid_stat where it says

Quoted 2 lines

mm ? mm->rss : 0, /* you might want to shift this left 3 */ the number 3 should probably be PAGE_SHIFT-10.

Don't forget the comment (it's still there in 2.6) :-)

Quoted 2 lines

Amazing that this has never been noticed before - I bet not many people use RSS limits with madvise().

Neither do we. :-)

I just found it when trying to figure out if the kernel actually used any of the rlimits and if so how.
(Trying to make PBS work correctly)

Quoted 6 lines

This transform the rlimit in pages before the comparison, can you please test it.

mm/filemap.c line 2616

Quoted 8 lines
mm/filemap.c renamed from mm/filemap.c.orig +3 -0
@@ -2609,6 +2609,9 @@
 	error = -EIO;
 	rlim_rss = current->rlim ?  current->rlim[RLIMIT_RSS].rlim_cur :
 				LONG_MAX; /* default: see resource.h */
+
+	rlim_rss = (rlim_rss & PAGE_MASK) >> PAGE_SHIFT;
+
 	if ((vma->vm_mm->rss + (end - start)) > rlim_rss)
 		return error;

Since we don't use it i can't really test it, but a visual inspection is good enough in this simple case. And since this is the only place in 2.4 that RLIMIT_RSS is used, the problem is solved.

Quoted 3 lines

BTW do you know if there is any plans for 2.6++ to actually use RLIMIT_RSS? I saw a hint in that direction in mm/thrash.c grab_swap_token but it is commented out and only skeleton code...

Nope, RLIMIT_RSS does not seem to be used at all in v2.6:

linux-2.6.11-rc1 # findgrep RLIMIT_RSS
./fs/proc/array.c
./include/asm-arm26/resource.h
./include/asm-ia64/resource.h
./include/asm-frv/resource.h
./include/asm-i386/resource.h
./include/asm-alpha/resource.h
./include/asm-ppc64/resource.h
./include/asm-x86_64/resource.h
./include/asm-s390/resource.h
./include/asm-mips/resource.h
./include/asm-sparc64/resource.h
./include/asm-cris/resource.h
./include/asm-v850/resource.h
./include/asm-m68k/resource.h
./include/asm-sparc/resource.h
./include/asm-parisc/resource.h
./include/asm-arm/resource.h
./include/asm-sh/resource.h
./include/asm-m32r/resource.h
./include/asm-h8300/resource.h
./include/asm-ppc/resource.h

Quoted 1 line

I'm asking since the above code piece has been removed.

Its there for compatibility reasons, support for it might be added in the future?

#4 lore raw
Quoted 14 lines · Marcelo Tosatti
Quoted 13 lines · Ake

mm/filemap.c line 2616

Quoted 12 lines · Marcelo Tosatti
mm/filemap.c renamed from mm/filemap.c.orig +3 -0
@@ -2609,6 +2609,9 @@
 	error = -EIO;
 	rlim_rss = current->rlim ?  current->rlim[RLIMIT_RSS].rlim_cur :
 				LONG_MAX; /* default: see resource.h */
+
+	rlim_rss = (rlim_rss & PAGE_MASK) >> PAGE_SHIFT;
+
 	if ((vma->vm_mm->rss + (end - start)) > rlim_rss)
 		return error;

Isn't the right fix just to remove rlim_rss and this RLIMIT_RSS code from here? It's pretty silly for madvise alone to be taking notice of it. Presumably the code crept in by mistake from some tree which was using an RLIMIT_RSS patch on 2.4.

Quoted 4 lines
Quoted 4 lines

Since we don't use it i can't really test it, but a visual inspection is good enough in this simple case. And since this is the only place in 2.4 that RLIMIT_RSS is used, the problem is solved.

Quoted 8 lines
Quoted 3 lines

BTW do you know if there is any plans for 2.6++ to actually use RLIMIT_RSS? I saw a hint in that direction in mm/thrash.c grab_swap_token but it is commented out and only skeleton code...

Nope, RLIMIT_RSS does not seem to be used at all in v2.6:

Its there for compatibility reasons, support for it might be added in the future?

Rik had a patch implementing RLIMIT_RSS in 2.6-mm for a while. But I think there were a couple of problems with it, and no great demand for the feature, so Andrew dropped it until someone makes a better case for it.

Hugh

#5 lore raw
Quoted 4 lines · Hugh Dickins
Quoted 3 lines · Marcelo Tosatti
Quoted 2 lines · Ake
Quoted 1 line · Marcelo Tosatti
Quoted 16 lines
Quoted 11 lines
Quoted 11 lines

mm/filemap.c line 2616

Quoted 11 lines
mm/filemap.c renamed from mm/filemap.c.orig +3 -0
@@ -2609,6 +2609,9 @@
 	error = -EIO;
 	rlim_rss = current->rlim ?  current->rlim[RLIMIT_RSS].rlim_cur :
 				LONG_MAX; /* default: see resource.h */
+
+	rlim_rss = (rlim_rss & PAGE_MASK) >> PAGE_SHIFT;
+
 	if ((vma->vm_mm->rss + (end - start)) > rlim_rss)
 		return error;

Isn't the right fix just to remove rlim_rss and this RLIMIT_RSS code from here? It's pretty silly for madvise alone to be taking notice of it. Presumably the code crept in by mistake from some tree which was using an RLIMIT_RSS patch on 2.4.

True. Will do it.

Quoted 19 lines
Quoted 4 lines
Quoted 4 lines

Since we don't use it i can't really test it, but a visual inspection is good enough in this simple case. And since this is the only place in 2.4 that RLIMIT_RSS is used, the problem is solved.

Quoted 8 lines
Quoted 3 lines

BTW do you know if there is any plans for 2.6++ to actually use RLIMIT_RSS? I saw a hint in that direction in mm/thrash.c grab_swap_token but it is commented out and only skeleton code...

Nope, RLIMIT_RSS does not seem to be used at all in v2.6:

Its there for compatibility reasons, support for it might be added in the future?

Rik had a patch implementing RLIMIT_RSS in 2.6-mm for a while. But I think there were a couple of problems with it, and no great demand for the feature, so Andrew dropped it until someone makes a better case for it.

Hugh

author
#6 lore raw
In reply to Hugh Dickins
Quoted 6 lines · Hugh Dickins
Quoted 6 lines
Quoted 3 lines

BTW do you know if there is any plans for 2.6++ to actually use RLIMIT_RSS? I saw a hint in that direction in mm/thrash.c grab_swap_token but it is commented out and only skeleton code...

Nope, RLIMIT_RSS does not seem to be used at all in v2.6:

Quoted 7 lines
Quoted 2 lines

Its there for compatibility reasons, support for it might be added in the future?

Rik had a patch implementing RLIMIT_RSS in 2.6-mm for a while. But I think there were a couple of problems with it, and no great demand for the feature, so Andrew dropped it until someone makes a better case for it.

Well, the use for it is for compute clusters where you really would like to be able to limit this. Esp on smp boxes where there is multiple compute jobs running simultaneously. Be it mpi or separate jobs you really want to limit their RSS use so they don't steal memory from each other.

Signature · 3 lines
Ake Sandgren, HPC2N, Umea University, S-90187 Umea, Sweden
Internet: [email protected]	Phone: +46 90 7866134 Fax: +46 90 7866126
Mobile: +46 70 7716134 WWW: http://www.hpc2n.umu.se