• memory consumption in deb9 vs deb10.

    From Anu Anu@21:1/5 to All on Fri Jul 1 14:20:01 2022
    Hi,
    In the below c++ program we are trying to divide a bigger memory block into smaller subblock by moving pointers by 1 page. While creating subblock we
    are
    initializing the variable of a structure which is of 64 bits. We tried to
    run this code on debian10 and debian9. What we observed is
    In deb9 only 64 bits memory is consumed but in deb10 consuming the entire
    page.
    Can someone help me understand what causes this difference? Can this be
    related to the way the kernel handles the memory? Thanks for your help in advance.

    #include <vector>
    #include <stdlib.h>
    #include <fcntl.h>
    #include <unistd.h>

    using namespace std;

    typedef unsigned char u8;
    typedef unsigned int u32;
    typedef unsigned long long u64;

    struct e{
    u8* f;
    u64* s;
    };
    struct se{
    u64 cid;
    void* np;
    };
    const u64 a = -1;
    u32 subchunk = 2878;
    u32 subchunkperchunk = 140;
    u32 chunksize = 1028096; //in bytes
    u32 TSize = 4096;
    u32 eleOfChunk = 50;
    u32 eSize = 4096;
    u64 x;
    vector<e> v;
    int it=0;

    u64& add(const void* ep)
    {
    void* subChunkPtr = (void*) (((u64)ep) / chunksize * chunksize);
    u64 firstElementLocation = ((u64)subChunkPtr) + TSize;
    u32 indexInsideSubChunk = (((u64)ep)-firstElementLocation) / eSize;
    se* elePtr = ((se*)subChunkPtr) + indexInsideSubChunk;
    return elePtr->cid;
    }

    int main()
    {
    int file = open("Result", O_CREAT|O_WRONLY, S_IRWXU);
    dup2(file, 1);
    for (u32 i=0; i<= subchunk/subchunkperchunk; i++)
    {
    u32 eleInCurrChunk;
    if (i != subchunk/subchunkperchunk)
    {
    eleInCurrChunk = subchunkperchunk;
    }
    else
    {
    eleInCurrChunk = subchunk % subchunkperchunk;
    if (eleInCurrChunk == 0)
    {
    break;
    }
    }
    u32 CSize = (eleInCurrChunk+1) * chunksize;
    u8* sp;
    sp = new u8[CSize];
    u8* ssp = sp + (chunksize - ((u64)sp % chunksize));
    for (u32 j = 0; j < eleInCurrChunk; ++j) //create block
    {
    u8* scp = ssp + j * chunksize;
    u8* ep = scp + TSize;
    for (u32 k=0; k < eleOfChunk ; ++k) //create subblock
    {
    v.push_back(e());
    v[it].f = ep;
    v[it].s = &add(ep);
    add(ep)= a; //set the 64 bits to high
    ep += eSize;
    ++it;
    }
    system("free -m");
    }
    }
    return 0;
    }

    <div dir="ltr"> Hi,<br>In the below c++ program we are trying to divide a bigger memory block into smaller subblock by moving pointers by 1 page. While creating subblock we are<br>initializing the variable of a structure which is of 64 bits. We tried
    to run this code on debian10 and debian9. What we observed is <br>In deb9 only 64 bits memory is consumed but in deb10 consuming the entire page.<br>Can someone help me understand what causes this difference? Can this be related to the way the kernel
    handles the memory? Thanks for your help in advance.<br><div><br></div><div>#include &lt;vector&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;fcntl.h&gt;<br>#include &lt;unistd.h&gt;<br><br>using namespace std;<br><br>typedef unsigned char u8;<br>
    typedef unsigned int u32;<br>typedef unsigned long long u64;<br><br>struct e{<br>   u8* f;<br>   u64* s;<br>};<br>struct se{<br>   u64 cid;<br>   void* np;<br>};<br>const u64 a = -1;<br>u32 subchunk = 2878;<br>u32 subchunkperchunk = 140;<br>u32
    chunksize = 1028096;   //in bytes<br>u32 TSize = 4096;<br>u32 eleOfChunk = 50;<br>u32 eSize = 4096;<br>u64 x;<br>vector&lt;e&gt; v;<br>int it=0;<br><br>u64&amp; add(const void* ep)<br>{<br>    void* subChunkPtr = (void*) (((u64)ep) / chunksize *
    chunksize);<br>    u64 firstElementLocation = ((u64)subChunkPtr) + TSize;<br>    u32 indexInsideSubChunk = (((u64)ep)-firstElementLocation) / eSize;<br>    se* elePtr = ((se*)subChunkPtr) + indexInsideSubChunk;<br>    return elePtr-&gt;cid;<br>}<
    <br>int main()<br>{<br>    int file = open(&quot;Result&quot;, O_CREAT|O_WRONLY, S_IRWXU);<br>    dup2(file, 1);<br>    for (u32 i=0; i&lt;= subchunk/subchunkperchunk; i++)<br>    {<br>      u32 eleInCurrChunk;<br>      if (i != subchunk/
    subchunkperchunk)<br>      {<br>         eleInCurrChunk = subchunkperchunk;<br>      }<br>      else<br>      {<br>         eleInCurrChunk = subchunk % subchunkperchunk;<br>         if (eleInCurrChunk == 0)<br>         {<
                break;<br>         }<br>      }<br>      u32 CSize = (eleInCurrChunk+1) * chunksize;<br>      u8* sp;<br>      sp = new u8[CSize];<br>      u8* ssp = sp + (chunksize - ((u64)sp % chunksize));<br>      for (u32
    j = 0; j &lt; eleInCurrChunk; ++j)    //create block<br>      {<br>         u8* scp = ssp + j * chunksize;<br>         u8* ep = scp + TSize;<br>         for (u32 k=0; k &lt; eleOfChunk ; ++k)   //create subblock<br>         {<br>
                 v.push_back(e());<br>             v[it].f = ep;<br>             v[it].s = &amp;add(ep);<br>             add(ep)= a;               //set the 64 bits to high<br>             ep += eSize;<br>       
         ++it;<br>        }<br>        system(&quot;free -m&quot;);<br>      }<br>    }<br>  return 0;<br>}<br><br></div></div>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andrey Rahmatullin@21:1/5 to Emyr Williams on Sat Jul 2 21:10:01 2022
    On Sat, Jul 02, 2022 at 08:04:15PM +0100, Emyr Williams wrote:
    Hi Anu,

    How can we replicate the conditions? Your e-mail isn't clear, what compiler arguments did you use? And what metrics are you using to measure memory usage?
    Please note that debian-mentors is not a good place for such questions.
    I will even say that the question is most likely not specific to Debian at
    all.

    --
    WBR, wRAR

    -----BEGIN PGP SIGNATURE-----

    iQJhBAABCgBLFiEEolIP6gqGcKZh3YxVM2L3AxpJkuEFAmLAl6QtFIAAAAAAFQAP cGthLWFkZHJlc3NAZ251cGcub3Jnd3JhckBkZWJpYW4ub3JnAAoJEDNi9wMaSZLh VzEP/1OX9UPR5w9/Auh1HcjygGC7ynIAD+JhgGxzc36xe7S4Q2LxTSWcjEIbPd9z VLEttE74wUUUWeRX3s6lx59JD3VonxQQvrI+6XkxfnzLD1tjkB3eSkM7MmN4u/r+ wjnVvNpWyD+oKxV26i/XrBQNAu1coK63a8le0Pg17dgWSTSVxOGV6ZsokVm+vwiI 2pjIuIDXvjfbsPj/IucnpiMFvoXzWTUsyDDWLW3ed+4Ka1C+NCaiLG6PIeNFfdzn NrCfWBNmh9pV2m5M9DPl4JzVhXnKVpP50844L7z4nlpnmavpxs5hP3rQGbYW39yQ MGgCq2VwI32TPbzfQi8VFpPCM2xv2wxkMQ+9hCEBURFPIGJm809dc1WM10ikwL5y cvvvatDM+vaVA7ohBHOzRTcK24x8jxAIfSKGyfSrG3o0J512+D4XlN0fDv9h6od/ lpT6No1NJJ4Uc60PxxoXOiM8j2oqekyd8iWTrcIFLzwjooQugwSRyhhle76QDwiJ NJ/XIcNkwynOrEbWO+kVov76p88S9GVrSRm0dYiMzmRq9/9FkrK4K4x6vr23+TQW /zQ7rV7hRkfqebp0zx9hbNYv22rEJbGvWgAmPdHpEt7XCtrTzTcWnCdSUyjRRfFR IK7ojnMAKcr+i+oVQ8gTYr2OiEkagyPcOavYBHLDfMxTO3Qf
    =EXPa
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Emyr Williams@21:1/5 to Anu Anu on Sat Jul 2 21:10:01 2022
    Hi Anu,

    How can we replicate the conditions? Your e-mail isn't clear, what
    compiler arguments did you use? And what metrics are you using to
    measure memory usage?

    Kindest regards



    On 01/07/2022 13:19, Anu Anu wrote:
     Hi,
    In the below c++ program we are trying to divide a bigger memory block
    into smaller subblock by moving pointers by 1 page. While creating
    subblock we are
    initializing the variable of a structure which is of 64 bits. We tried
    to run this code on debian10 and debian9. What we observed is
    In deb9 only 64 bits memory is consumed but in deb10 consuming the
    entire page.
    Can someone help me understand what causes this difference? Can this
    be related to the way the kernel handles the memory? Thanks for your
    help in advance.

    #include <vector>
    #include <stdlib.h>
    #include <fcntl.h>
    #include <unistd.h>

    using namespace std;

    typedef unsigned char u8;
    typedef unsigned int u32;
    typedef unsigned long long u64;

    struct e{
       u8* f;
       u64* s;
    };
    struct se{
       u64 cid;
       void* np;
    };
    const u64 a = -1;
    u32 subchunk = 2878;
    u32 subchunkperchunk = 140;
    u32 chunksize = 1028096;   //in bytes
    u32 TSize = 4096;
    u32 eleOfChunk = 50;
    u32 eSize = 4096;
    u64 x;
    vector<e> v;
    int it=0;

    u64& add(const void* ep)
    {
        void* subChunkPtr = (void*) (((u64)ep) / chunksize * chunksize);
        u64 firstElementLocation = ((u64)subChunkPtr) + TSize;
        u32 indexInsideSubChunk = (((u64)ep)-firstElementLocation) / eSize;
        se* elePtr = ((se*)subChunkPtr) + indexInsideSubChunk;
        return elePtr->cid;
    }

    int main()
    {
        int file = open("Result", O_CREAT|O_WRONLY, S_IRWXU);
        dup2(file, 1);
        for (u32 i=0; i<= subchunk/subchunkperchunk; i++)
        {
          u32 eleInCurrChunk;
          if (i != subchunk/subchunkperchunk)
          {
             eleInCurrChunk = subchunkperchunk;
          }
          else
          {
             eleInCurrChunk = subchunk % subchunkperchunk;
             if (eleInCurrChunk == 0)
             {
                break;
             }
          }
          u32 CSize = (eleInCurrChunk+1) * chunksize;
          u8* sp;
          sp = new u8[CSize];
          u8* ssp = sp + (chunksize - ((u64)sp % chunksize));
          for (u32 j = 0; j < eleInCurrChunk; ++j)    //create block
          {
             u8* scp = ssp + j * chunksize;
             u8* ep = scp + TSize;
             for (u32 k=0; k < eleOfChunk ; ++k)   //create subblock
             {
                 v.push_back(e());
                 v[it].f = ep;
                 v[it].s = &add(ep);
                 add(ep)= a;               //set the 64 bits to high
                 ep += eSize;
                 ++it;
            }
            system("free -m");
          }
        }
      return 0;
    }


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)