How can a C++ application use more Heap than RSS Memory?A way to determine a process's “real” memory usage, i.e. private dirty RSS?How to measure actual memory usage of an application or process?How can I profile C++ code running on Linux?How do I discover memory usage of my application in Android?C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?Can a local variable's memory be accessed outside its scope?Why is reading lines from stdin much slower in C++ than Python?How to profile shared memory?Measure static, heap and stack memory ? (c++, Linux - Centos 7)Measuring dynamic memory usage using C++ sanitizers

Most practical knots for hitching a line to an object while keeping the bitter end as tight as possible, without sag?

Vacuum collapse -- why do strong metals implode but glass doesn't?

Why was 'ordinate' adopted to signify y-coordinate?

Do I have to learn /o/ or /ɔ/ separately?

Don't teach Dhamma to those who can't appreciate it or aren't interested

Germany: Can you be convicted for being a murderer twice?

Is it allowable to use an organization's name to publish a paper in a conference, even after I graduate from it?

How can I support the recycling, but not the new production of aluminum?

are there nouns that change meaning based on gender?

Is refusing to concede in the face of an unstoppable Nexus combo punishable?

Is there such a thing as too inconvenient?

Why don't we use Cavea-B

Is a butterfly one or two animals?

Is it safe to remove the bottom chords of a series of garage roof trusses?

If all closed subsets of a set are compact, does it follow that this set is subset of a compact set?

What is the difference between a premise and an assumption in logic?

Was this pillow joke on Friends intentional or a mistake?

Do living authors still get paid royalties for their old work?

The teacher logged me in as administrator for doing a short task, is the whole system now compromised?

How to decide whether an eshop is safe or compromised

Earliest evidence of objects intended for future archaeologists?

What are the pros and cons of Einstein-Cartan Theory?

Can a Beast Master ranger choose a swarm as an animal companion?

Starships without computers?



How can a C++ application use more Heap than RSS Memory?


A way to determine a process's “real” memory usage, i.e. private dirty RSS?How to measure actual memory usage of an application or process?How can I profile C++ code running on Linux?How do I discover memory usage of my application in Android?C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?Can a local variable's memory be accessed outside its scope?Why is reading lines from stdin much slower in C++ than Python?How to profile shared memory?Measure static, heap and stack memory ? (c++, Linux - Centos 7)Measuring dynamic memory usage using C++ sanitizers






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have a C++ executable for a multithreads application which involves the opening of UDP ports.



I'm measuring the memory usage of this application using different tools.



From my understanding of Linux memory usage, RSS = Heap + Stack + Shared + CodeSize.



However, now I think that the equation is wrong, because my application has:



  • Peak Heap usage: 40Mb

  • Peak RSS: 30Mb

I measured the numbers with different tools (valgrind, heaptrack, top..) so I can say that they are correct.



How can it be possible?
What are the causes and the consequences of this situation?



Thanks










share|improve this question


























  • If I well understand RSS, this is the amout of RAM used at a certain point of time. So, this only means that all the address space of your program is not loaded all in RAM. There's surely some part of it on the swap

    – Gojita
    Mar 27 at 15:36











  • Wiki page for RSS explains this quite well. RSS is how much of your memory is actually in RAM. There are many reasons why memory allocated by your program may not be in RAM yet or anymore.

    – user4581301
    Mar 27 at 15:36











  • It is all about the paging i.e. some pages are on swapping partition when peek period, since they are more likely not used by the code (cold zone) and kernel understanding this and moving it from RAM to HDD.

    – Victor Gubin
    Mar 27 at 15:38












  • @SergeiKurenkov The SWAP column from top always shows 0 during my application execution.

    – alsora
    Mar 27 at 15:43







  • 3





    Memory allocated but not yet used will not yet have main memory assigned. If you allocate a huge array, you may not see an increase in RSS. If you access the first and last element in the array, you may only see the pages that contain the first and last elements, and nothing between, in RSS.

    – user4581301
    Mar 27 at 15:45

















1















I have a C++ executable for a multithreads application which involves the opening of UDP ports.



I'm measuring the memory usage of this application using different tools.



From my understanding of Linux memory usage, RSS = Heap + Stack + Shared + CodeSize.



However, now I think that the equation is wrong, because my application has:



  • Peak Heap usage: 40Mb

  • Peak RSS: 30Mb

I measured the numbers with different tools (valgrind, heaptrack, top..) so I can say that they are correct.



How can it be possible?
What are the causes and the consequences of this situation?



Thanks










share|improve this question


























  • If I well understand RSS, this is the amout of RAM used at a certain point of time. So, this only means that all the address space of your program is not loaded all in RAM. There's surely some part of it on the swap

    – Gojita
    Mar 27 at 15:36











  • Wiki page for RSS explains this quite well. RSS is how much of your memory is actually in RAM. There are many reasons why memory allocated by your program may not be in RAM yet or anymore.

    – user4581301
    Mar 27 at 15:36











  • It is all about the paging i.e. some pages are on swapping partition when peek period, since they are more likely not used by the code (cold zone) and kernel understanding this and moving it from RAM to HDD.

    – Victor Gubin
    Mar 27 at 15:38












  • @SergeiKurenkov The SWAP column from top always shows 0 during my application execution.

    – alsora
    Mar 27 at 15:43







  • 3





    Memory allocated but not yet used will not yet have main memory assigned. If you allocate a huge array, you may not see an increase in RSS. If you access the first and last element in the array, you may only see the pages that contain the first and last elements, and nothing between, in RSS.

    – user4581301
    Mar 27 at 15:45













1












1








1


0






I have a C++ executable for a multithreads application which involves the opening of UDP ports.



I'm measuring the memory usage of this application using different tools.



From my understanding of Linux memory usage, RSS = Heap + Stack + Shared + CodeSize.



However, now I think that the equation is wrong, because my application has:



  • Peak Heap usage: 40Mb

  • Peak RSS: 30Mb

I measured the numbers with different tools (valgrind, heaptrack, top..) so I can say that they are correct.



How can it be possible?
What are the causes and the consequences of this situation?



Thanks










share|improve this question
















I have a C++ executable for a multithreads application which involves the opening of UDP ports.



I'm measuring the memory usage of this application using different tools.



From my understanding of Linux memory usage, RSS = Heap + Stack + Shared + CodeSize.



However, now I think that the equation is wrong, because my application has:



  • Peak Heap usage: 40Mb

  • Peak RSS: 30Mb

I measured the numbers with different tools (valgrind, heaptrack, top..) so I can say that they are correct.



How can it be possible?
What are the causes and the consequences of this situation?



Thanks







c++ memory heap






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 15:31









user4581301

22.9k5 gold badges22 silver badges37 bronze badges




22.9k5 gold badges22 silver badges37 bronze badges










asked Mar 27 at 15:29









alsoraalsora

3662 silver badges12 bronze badges




3662 silver badges12 bronze badges















  • If I well understand RSS, this is the amout of RAM used at a certain point of time. So, this only means that all the address space of your program is not loaded all in RAM. There's surely some part of it on the swap

    – Gojita
    Mar 27 at 15:36











  • Wiki page for RSS explains this quite well. RSS is how much of your memory is actually in RAM. There are many reasons why memory allocated by your program may not be in RAM yet or anymore.

    – user4581301
    Mar 27 at 15:36











  • It is all about the paging i.e. some pages are on swapping partition when peek period, since they are more likely not used by the code (cold zone) and kernel understanding this and moving it from RAM to HDD.

    – Victor Gubin
    Mar 27 at 15:38












  • @SergeiKurenkov The SWAP column from top always shows 0 during my application execution.

    – alsora
    Mar 27 at 15:43







  • 3





    Memory allocated but not yet used will not yet have main memory assigned. If you allocate a huge array, you may not see an increase in RSS. If you access the first and last element in the array, you may only see the pages that contain the first and last elements, and nothing between, in RSS.

    – user4581301
    Mar 27 at 15:45

















  • If I well understand RSS, this is the amout of RAM used at a certain point of time. So, this only means that all the address space of your program is not loaded all in RAM. There's surely some part of it on the swap

    – Gojita
    Mar 27 at 15:36











  • Wiki page for RSS explains this quite well. RSS is how much of your memory is actually in RAM. There are many reasons why memory allocated by your program may not be in RAM yet or anymore.

    – user4581301
    Mar 27 at 15:36











  • It is all about the paging i.e. some pages are on swapping partition when peek period, since they are more likely not used by the code (cold zone) and kernel understanding this and moving it from RAM to HDD.

    – Victor Gubin
    Mar 27 at 15:38












  • @SergeiKurenkov The SWAP column from top always shows 0 during my application execution.

    – alsora
    Mar 27 at 15:43







  • 3





    Memory allocated but not yet used will not yet have main memory assigned. If you allocate a huge array, you may not see an increase in RSS. If you access the first and last element in the array, you may only see the pages that contain the first and last elements, and nothing between, in RSS.

    – user4581301
    Mar 27 at 15:45
















If I well understand RSS, this is the amout of RAM used at a certain point of time. So, this only means that all the address space of your program is not loaded all in RAM. There's surely some part of it on the swap

– Gojita
Mar 27 at 15:36





If I well understand RSS, this is the amout of RAM used at a certain point of time. So, this only means that all the address space of your program is not loaded all in RAM. There's surely some part of it on the swap

– Gojita
Mar 27 at 15:36













Wiki page for RSS explains this quite well. RSS is how much of your memory is actually in RAM. There are many reasons why memory allocated by your program may not be in RAM yet or anymore.

– user4581301
Mar 27 at 15:36





Wiki page for RSS explains this quite well. RSS is how much of your memory is actually in RAM. There are many reasons why memory allocated by your program may not be in RAM yet or anymore.

– user4581301
Mar 27 at 15:36













It is all about the paging i.e. some pages are on swapping partition when peek period, since they are more likely not used by the code (cold zone) and kernel understanding this and moving it from RAM to HDD.

– Victor Gubin
Mar 27 at 15:38






It is all about the paging i.e. some pages are on swapping partition when peek period, since they are more likely not used by the code (cold zone) and kernel understanding this and moving it from RAM to HDD.

– Victor Gubin
Mar 27 at 15:38














@SergeiKurenkov The SWAP column from top always shows 0 during my application execution.

– alsora
Mar 27 at 15:43






@SergeiKurenkov The SWAP column from top always shows 0 during my application execution.

– alsora
Mar 27 at 15:43





3




3





Memory allocated but not yet used will not yet have main memory assigned. If you allocate a huge array, you may not see an increase in RSS. If you access the first and last element in the array, you may only see the pages that contain the first and last elements, and nothing between, in RSS.

– user4581301
Mar 27 at 15:45





Memory allocated but not yet used will not yet have main memory assigned. If you allocate a huge array, you may not see an increase in RSS. If you access the first and last element in the array, you may only see the pages that contain the first and last elements, and nothing between, in RSS.

– user4581301
Mar 27 at 15:45












2 Answers
2






active

oldest

votes


















0














As @user4581301 pointed out in the comments, there was a problem in my idea of RSS.



HEAP = DynamicMemoryAllocated



RSS = DynamicMemoryInitialized + Stack + Shared + CodeSize



So it is not true that all the heap size is contained in the RSS, but only the part of it which has been initialized.



If you allocate space for a 10Mb array, this is HEAP.
If you start initializing it, then the initialized parts will be counted as RSS.






share|improve this answer
































    0














    RSS is the Resident Set Size.



    Not all the heap is necessarily resident - it may be swapped out, for example.



    However, the Virtual memory usage will include all of the heap (both resident and non-resident portions).






    share|improve this answer



























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      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',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55380944%2fhow-can-a-c-application-use-more-heap-than-rss-memory%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      As @user4581301 pointed out in the comments, there was a problem in my idea of RSS.



      HEAP = DynamicMemoryAllocated



      RSS = DynamicMemoryInitialized + Stack + Shared + CodeSize



      So it is not true that all the heap size is contained in the RSS, but only the part of it which has been initialized.



      If you allocate space for a 10Mb array, this is HEAP.
      If you start initializing it, then the initialized parts will be counted as RSS.






      share|improve this answer





























        0














        As @user4581301 pointed out in the comments, there was a problem in my idea of RSS.



        HEAP = DynamicMemoryAllocated



        RSS = DynamicMemoryInitialized + Stack + Shared + CodeSize



        So it is not true that all the heap size is contained in the RSS, but only the part of it which has been initialized.



        If you allocate space for a 10Mb array, this is HEAP.
        If you start initializing it, then the initialized parts will be counted as RSS.






        share|improve this answer



























          0












          0








          0







          As @user4581301 pointed out in the comments, there was a problem in my idea of RSS.



          HEAP = DynamicMemoryAllocated



          RSS = DynamicMemoryInitialized + Stack + Shared + CodeSize



          So it is not true that all the heap size is contained in the RSS, but only the part of it which has been initialized.



          If you allocate space for a 10Mb array, this is HEAP.
          If you start initializing it, then the initialized parts will be counted as RSS.






          share|improve this answer













          As @user4581301 pointed out in the comments, there was a problem in my idea of RSS.



          HEAP = DynamicMemoryAllocated



          RSS = DynamicMemoryInitialized + Stack + Shared + CodeSize



          So it is not true that all the heap size is contained in the RSS, but only the part of it which has been initialized.



          If you allocate space for a 10Mb array, this is HEAP.
          If you start initializing it, then the initialized parts will be counted as RSS.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Apr 10 at 10:19









          alsoraalsora

          3662 silver badges12 bronze badges




          3662 silver badges12 bronze badges


























              0














              RSS is the Resident Set Size.



              Not all the heap is necessarily resident - it may be swapped out, for example.



              However, the Virtual memory usage will include all of the heap (both resident and non-resident portions).






              share|improve this answer





























                0














                RSS is the Resident Set Size.



                Not all the heap is necessarily resident - it may be swapped out, for example.



                However, the Virtual memory usage will include all of the heap (both resident and non-resident portions).






                share|improve this answer



























                  0












                  0








                  0







                  RSS is the Resident Set Size.



                  Not all the heap is necessarily resident - it may be swapped out, for example.



                  However, the Virtual memory usage will include all of the heap (both resident and non-resident portions).






                  share|improve this answer













                  RSS is the Resident Set Size.



                  Not all the heap is necessarily resident - it may be swapped out, for example.



                  However, the Virtual memory usage will include all of the heap (both resident and non-resident portions).







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Apr 10 at 10:50









                  Toby SpeightToby Speight

                  18.4k13 gold badges49 silver badges70 bronze badges




                  18.4k13 gold badges49 silver badges70 bronze badges






























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55380944%2fhow-can-a-c-application-use-more-heap-than-rss-memory%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Obelisk of Theodosius Contents History Description Notes Bibliography Further reading External links Navigation menuAge of spirituality : late antique and early Christian art, third to seventh centuryOver 60 picturesObelisks of the World41°00′21.24″N 28°58′31.43″E / 41.0059000°N 28.9753972°E / 41.0059000; 28.97539727724550-7235741376235741376

                      밀양 대씨 역사 각주 함께 보기 둘러보기 메뉴밀양 대씨

                      1973년 목차 사건 문화 탄생 사망 노벨상 달력 둘러보기 메뉴