Limit and measure VSS/RSS

Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I'm writing a program on Ubuntu 16.04, and it will fork, do some setups and exec another program. I need to:
- Limit the maximum VSS the program could use
- Limit the maximum RSS the program could use
- Measure the maximum VSS the program used during its execution
- Measure the maximum RSS the program used during its execution
So far I can do 1. and 4. as following:
pid_t chpid = fork();
if (!chpid)
// I do lots of setup here
struct rlimit rlim;
rlim.rlim_cur = rlim.rlim_max = limit_VSS;
setrlimit(RLIMIT_AS, &rlim); // 1.
execv(path, args);
struct rusage stats;
wait3(NULL, 0, &stats);
long max_RSS = stats.ru_maxrss; // 4.
How can I implement 2. and 3.?
The RLIMIT_RSS option in setrlimit seems not useful, and I don't know how to get VmPeak in /proc/pid/status after the process is terminated (or right before the process terminates).
I need a efficient way, i.e., not having a significant impact on the exec program. (There are ptrace and some tools such as valgrind, but it will slow down the execution a lot.)
memory c
add a comment |Â
up vote
3
down vote
favorite
I'm writing a program on Ubuntu 16.04, and it will fork, do some setups and exec another program. I need to:
- Limit the maximum VSS the program could use
- Limit the maximum RSS the program could use
- Measure the maximum VSS the program used during its execution
- Measure the maximum RSS the program used during its execution
So far I can do 1. and 4. as following:
pid_t chpid = fork();
if (!chpid)
// I do lots of setup here
struct rlimit rlim;
rlim.rlim_cur = rlim.rlim_max = limit_VSS;
setrlimit(RLIMIT_AS, &rlim); // 1.
execv(path, args);
struct rusage stats;
wait3(NULL, 0, &stats);
long max_RSS = stats.ru_maxrss; // 4.
How can I implement 2. and 3.?
The RLIMIT_RSS option in setrlimit seems not useful, and I don't know how to get VmPeak in /proc/pid/status after the process is terminated (or right before the process terminates).
I need a efficient way, i.e., not having a significant impact on the exec program. (There are ptrace and some tools such as valgrind, but it will slow down the execution a lot.)
memory c
2
Sorry, what is VSS and RSS?
â datUser
Dec 28 '17 at 18:55
@datUser Virtual Set Size and Resident Set Size. Explanation.
â Colera Su
Dec 29 '17 at 0:37
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I'm writing a program on Ubuntu 16.04, and it will fork, do some setups and exec another program. I need to:
- Limit the maximum VSS the program could use
- Limit the maximum RSS the program could use
- Measure the maximum VSS the program used during its execution
- Measure the maximum RSS the program used during its execution
So far I can do 1. and 4. as following:
pid_t chpid = fork();
if (!chpid)
// I do lots of setup here
struct rlimit rlim;
rlim.rlim_cur = rlim.rlim_max = limit_VSS;
setrlimit(RLIMIT_AS, &rlim); // 1.
execv(path, args);
struct rusage stats;
wait3(NULL, 0, &stats);
long max_RSS = stats.ru_maxrss; // 4.
How can I implement 2. and 3.?
The RLIMIT_RSS option in setrlimit seems not useful, and I don't know how to get VmPeak in /proc/pid/status after the process is terminated (or right before the process terminates).
I need a efficient way, i.e., not having a significant impact on the exec program. (There are ptrace and some tools such as valgrind, but it will slow down the execution a lot.)
memory c
I'm writing a program on Ubuntu 16.04, and it will fork, do some setups and exec another program. I need to:
- Limit the maximum VSS the program could use
- Limit the maximum RSS the program could use
- Measure the maximum VSS the program used during its execution
- Measure the maximum RSS the program used during its execution
So far I can do 1. and 4. as following:
pid_t chpid = fork();
if (!chpid)
// I do lots of setup here
struct rlimit rlim;
rlim.rlim_cur = rlim.rlim_max = limit_VSS;
setrlimit(RLIMIT_AS, &rlim); // 1.
execv(path, args);
struct rusage stats;
wait3(NULL, 0, &stats);
long max_RSS = stats.ru_maxrss; // 4.
How can I implement 2. and 3.?
The RLIMIT_RSS option in setrlimit seems not useful, and I don't know how to get VmPeak in /proc/pid/status after the process is terminated (or right before the process terminates).
I need a efficient way, i.e., not having a significant impact on the exec program. (There are ptrace and some tools such as valgrind, but it will slow down the execution a lot.)
memory c
edited Dec 26 '17 at 11:31
asked Dec 25 '17 at 11:45
Colera Su
193
193
2
Sorry, what is VSS and RSS?
â datUser
Dec 28 '17 at 18:55
@datUser Virtual Set Size and Resident Set Size. Explanation.
â Colera Su
Dec 29 '17 at 0:37
add a comment |Â
2
Sorry, what is VSS and RSS?
â datUser
Dec 28 '17 at 18:55
@datUser Virtual Set Size and Resident Set Size. Explanation.
â Colera Su
Dec 29 '17 at 0:37
2
2
Sorry, what is VSS and RSS?
â datUser
Dec 28 '17 at 18:55
Sorry, what is VSS and RSS?
â datUser
Dec 28 '17 at 18:55
@datUser Virtual Set Size and Resident Set Size. Explanation.
â Colera Su
Dec 29 '17 at 0:37
@datUser Virtual Set Size and Resident Set Size. Explanation.
â Colera Su
Dec 29 '17 at 0:37
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
I don't know about separating out VSS from RSS usage, but you could look at using memory pools, or using a malloc substitute which monitors and/or enforces maximum allocation from the system.
Take a look at the taskstats process accounting package. It doesn't record final memory usage, but does record High watermark of RSS usage and VM usage, which may be what you want anyway? I'm not sure if it's available as standard with Ubuntu's 16.04 kernels - you may need to build a kernel module to get it.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I don't know about separating out VSS from RSS usage, but you could look at using memory pools, or using a malloc substitute which monitors and/or enforces maximum allocation from the system.
Take a look at the taskstats process accounting package. It doesn't record final memory usage, but does record High watermark of RSS usage and VM usage, which may be what you want anyway? I'm not sure if it's available as standard with Ubuntu's 16.04 kernels - you may need to build a kernel module to get it.
add a comment |Â
up vote
0
down vote
I don't know about separating out VSS from RSS usage, but you could look at using memory pools, or using a malloc substitute which monitors and/or enforces maximum allocation from the system.
Take a look at the taskstats process accounting package. It doesn't record final memory usage, but does record High watermark of RSS usage and VM usage, which may be what you want anyway? I'm not sure if it's available as standard with Ubuntu's 16.04 kernels - you may need to build a kernel module to get it.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
I don't know about separating out VSS from RSS usage, but you could look at using memory pools, or using a malloc substitute which monitors and/or enforces maximum allocation from the system.
Take a look at the taskstats process accounting package. It doesn't record final memory usage, but does record High watermark of RSS usage and VM usage, which may be what you want anyway? I'm not sure if it's available as standard with Ubuntu's 16.04 kernels - you may need to build a kernel module to get it.
I don't know about separating out VSS from RSS usage, but you could look at using memory pools, or using a malloc substitute which monitors and/or enforces maximum allocation from the system.
Take a look at the taskstats process accounting package. It doesn't record final memory usage, but does record High watermark of RSS usage and VM usage, which may be what you want anyway? I'm not sure if it's available as standard with Ubuntu's 16.04 kernels - you may need to build a kernel module to get it.
answered Dec 31 '17 at 1:35
mc0e
656512
656512
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f412943%2flimit-and-measure-vss-rss%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
Sorry, what is VSS and RSS?
â datUser
Dec 28 '17 at 18:55
@datUser Virtual Set Size and Resident Set Size. Explanation.
â Colera Su
Dec 29 '17 at 0:37