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;
}


Reply via email to