Limit and measure VSS/RSS

The name of the pictureThe name of the pictureThe name of the pictureClash 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:



  1. Limit the maximum VSS the program could use

  2. Limit the maximum RSS the program could use

  3. Measure the maximum VSS the program used during its execution

  4. 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.)







share|improve this question


















  • 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














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:



  1. Limit the maximum VSS the program could use

  2. Limit the maximum RSS the program could use

  3. Measure the maximum VSS the program used during its execution

  4. 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.)







share|improve this question


















  • 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












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:



  1. Limit the maximum VSS the program could use

  2. Limit the maximum RSS the program could use

  3. Measure the maximum VSS the program used during its execution

  4. 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.)







share|improve this question














I'm writing a program on Ubuntu 16.04, and it will fork, do some setups and exec another program. I need to:



  1. Limit the maximum VSS the program could use

  2. Limit the maximum RSS the program could use

  3. Measure the maximum VSS the program used during its execution

  4. 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.)









share|improve this question













share|improve this question




share|improve this question








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












  • 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










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.






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    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






























    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.






    share|improve this answer
























      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.






      share|improve this answer






















        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.






        share|improve this answer












        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 31 '17 at 1:35









        mc0e

        656512




        656512






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            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













































































            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)