|
From: Skarakis, K. <kon...@un...> - 2014-10-06 15:09:05
|
Hello,
I am having trouble running programs that need to use "ulimit" under valgrind. For instance, here is a simple script that changes the limit of open files to 100000. All commands below are executed as root:
> cat foo
#!/bin/sh
ulimit -n 100000
I can run it fine on its own.
> ./foo
> echo $?
0
But under valgrind I get blocked with "Operation not permitted":
> valgrind ./foo
==729== Memcheck, a memory error detector
==729== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==729== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==729== Command: ./foo
==729==
./foo: line 2: ulimit: open files: cannot modify limit: Operation not permitted
==729==
==729== HEAP SUMMARY:
==729== in use at exit: 22,355 bytes in 579 blocks
==729== total heap usage: 689 allocs, 110 frees, 34,516 bytes allocated
==729==
==729== LEAK SUMMARY:
==729== definitely lost: 0 bytes in 0 blocks
==729== indirectly lost: 0 bytes in 0 blocks
==729== possibly lost: 0 bytes in 0 blocks
==729== still reachable: 22,355 bytes in 579 blocks
==729== suppressed: 0 bytes in 0 blocks
==729== Rerun with --leak-check=full to see details of leaked memory
==729==
==729== For counts of detected and suppressed errors, rerun with: -v
==729== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
Right now I have no entries in /etc/security/limits.conf, however it looks like the file is not even accessed:
> strace -s 100 -f /usr/bin/valgrind ./foo > trace 2>&1
> grep limits.conf trace
> echo $?
1
Any hints will be much appreciated.
My platform is 64-bit Linux.
Thank you,
Costas
PS: Here is part of the trace I took above. Maybe it is obvious to someone what goes wrong:
read(255, "#!/bin/sh\nulimit -n 100000\n", 27) = 27
rt_sigprocmask(SIG_SETMASK, ~[ILL TRAP BUS FPE KILL SEGV STOP], NULL, 8) = 0
gettid() = 784
read(1027, "G", 1) = 1
rt_sigprocmask(SIG_SETMASK, ~[], ~[ILL TRAP BUS FPE KILL SEGV STOP], 8) = 0
rt_sigtimedwait(~[], 0x4029a1d00) = -1 EAGAIN (Resource temporarily unavailable)
rt_sigprocmask(SIG_SETMASK, ~[ILL TRAP BUS FPE KILL SEGV STOP], NULL, 8) = 0
getrlimit(RLIMIT_NOFILE, {rlim_cur=1034, rlim_max=8*1024}) = 0
getrlimit(RLIMIT_NOFILE, {rlim_cur=1034, rlim_max=8*1024}) = 0
fstat(2, {st_mode=S_IFREG|0644, st_size=129020, ...}) = 0
mmap(0x4028000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x4028000
gettid() = 784
write(1028, "H", 1) = 1
rt_sigprocmask(SIG_SETMASK, [], ~[ILL TRAP BUS FPE KILL SEGV STOP], 8) = 0
write(2, "./foo: line 2: ulimit: open files: cannot modify limit: Operation not permitted\n", 80./foo: line 2: ulimit: open files: cannot modify limit: Operation not permitted) = 80
|
|
From: Tom H. <to...@co...> - 2014-10-06 15:22:32
|
On 06/10/14 16:08, Skarakis, Konstantinos wrote: > I am having trouble running programs that need to use "ulimit" under valgrind. For instance, here is a simple script that changes the limit of open files to 100000. All commands below are executed as root: > >> cat foo > #!/bin/sh > ulimit -n 100000 > > I can run it fine on its own. > >> ./foo >> echo $? > 0 > > But under valgrind I get blocked with "Operation not permitted": Because valgrind needs to reserve a few file descriptors for it's own use it effectively reduces the hard limit slightly, so you won't be able to raise your own soft limit above that reduced hard limit. If you query the hard limit with getrlimit and then increase your soft limit to that then you should find it works. Tom -- Tom Hughes (to...@co...) http://compton.nu/ |
|
From: Tom H. <to...@co...> - 2014-10-06 15:36:49
|
On 06/10/14 16:22, Tom Hughes wrote: > On 06/10/14 16:08, Skarakis, Konstantinos wrote: > >> I am having trouble running programs that need to use "ulimit" under valgrind. For instance, here is a simple script that changes the limit of open files to 100000. All commands below are executed as root: >> >>> cat foo >> #!/bin/sh >> ulimit -n 100000 >> >> I can run it fine on its own. >> >>> ./foo >>> echo $? >> 0 >> >> But under valgrind I get blocked with "Operation not permitted": > > Because valgrind needs to reserve a few file descriptors for it's own > use it effectively reduces the hard limit slightly, so you won't be able > to raise your own soft limit above that reduced hard limit. Actually it's worse than that, we allocate the 10 reserved descriptors immediately above the soft limit (assuming there is space) and effectively convert the initial soft limit to a hard limit. Tom -- Tom Hughes (to...@co...) http://compton.nu/ |
|
From: Skarakis, K. <kon...@un...> - 2014-10-06 15:57:18
|
OK, here is my bad code:
> cat rlimit.c
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
int main(){
struct rlimit limit;
getrlimit(RLIMIT_NOFILE,&limit);
printf("%d \n",limit.rlim_max);
}
When I just run it I get 8192:
> ./rlimit.o
8192
I do get a smaller limit (1024) under Valgrind:
> valgrind ./rlimit.o
==1070== Memcheck, a memory error detector
==1070== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==1070== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==1070== Command: ./rlimit.o
==1070==
1024
==1070==
==1070== HEAP SUMMARY:
==1070== in use at exit: 0 bytes in 0 blocks
==1070== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==1070==
==1070== All heap blocks were freed -- no leaks are possible
==1070==
==1070== For counts of detected and suppressed errors, rerun with: -v
==1070== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
So I change my script to set to a lower value (100).
> cat foo
#!/bin/sh
ulimit -n 100
Still doesn't work:
> valgrind ./foo
==1071== Memcheck, a memory error detector
==1071== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==1071== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==1071== Command: ./foo
==1071==
./foo: line 2: ulimit: open files: cannot modify limit: Operation not permitted
Assuming I am doing something wrong and this small example should work, is there a way to raise the soft/hard limits that valgrind uses?
Also, if the problem was that I was exceeding the hard limit, shouldn't the error be "Limit exceeded" rather than "Operation not permitted".
Costas
-----Original Message-----
From: Tom Hughes [mailto:to...@co...]
Sent: Monday, October 06, 2014 6:37 PM
To: Skarakis, Konstantinos; val...@li...
Subject: Re: ulimit under valgrind
On 06/10/14 16:22, Tom Hughes wrote:
> On 06/10/14 16:08, Skarakis, Konstantinos wrote:
>
>> I am having trouble running programs that need to use "ulimit" under valgrind. For instance, here is a simple script that changes the limit of open files to 100000. All commands below are executed as root:
>>
>>> cat foo
>> #!/bin/sh
>> ulimit -n 100000
>>
>> I can run it fine on its own.
>>
>>> ./foo
>>> echo $?
>> 0
>>
>> But under valgrind I get blocked with "Operation not permitted":
>
> Because valgrind needs to reserve a few file descriptors for it's own
> use it effectively reduces the hard limit slightly, so you won't be
> able to raise your own soft limit above that reduced hard limit.
Actually it's worse than that, we allocate the 10 reserved descriptors immediately above the soft limit (assuming there is space) and effectively convert the initial soft limit to a hard limit.
Tom
--
Tom Hughes (to...@co...)
http://compton.nu/
|
|
From: Dan K. <da...@ke...> - 2014-10-06 16:08:02
|
What if you use ulimit on the outside, before valgrind runs, and raise the soft limit to 10 higher than your inner script would? |
|
From: Skarakis, K. <kon...@un...> - 2014-10-07 08:02:47
|
I am not sure I followed your instructions correctly, but I think that did it. > cat foo #!/bin/sh ulimit -n 100000 > ulimit -n 1024 > valgrind --log-file=/tmp/log ./foo ./foo: line 2: ulimit: open files: cannot modify limit: Operation not permitted > ulimit -n 100010 > ulimit -n 100010 > valgrind --log-file=/tmp/log ./foo > echo $? 0 Thanks Dan. And thanks Tom. -----Original Message----- From: dan...@gm... [mailto:dan...@gm...] On Behalf Of Dan Kegel Sent: Monday, October 06, 2014 7:08 PM To: Skarakis, Konstantinos Cc: Tom Hughes; val...@li... Subject: Re: [Valgrind-users] ulimit under valgrind What if you use ulimit on the outside, before valgrind runs, and raise the soft limit to 10 higher than your inner script would? |