How to write a simple "page error generator"?

In my course project on the Linux kernel, I need to simulate a situation where, due to low memory, there is part of the page exchange .

I want to write a program that requires a lot of physical memory, so that the pages accessed by this program should change and change several times.

+4
source share
2 answers

Because of this, first of all, you really need to allocate a buffer that is larger than your RAM. I hope that you are running a 64-bit OS or that you have PAE enabled. If we say 4 GB of RAM, you need something like:

double* pBigArray = (double*)malloc(sizeof(double) * 536870912); 
// You actually need more than that. This is just 4GB.

, RAM, . , . , , , .

, , .

, , :

double lfBigChecksum = 0.0;
while (true)
{
   int iIndex = rand() % BUFFER_SIZE;
   lfBigChecksum += pBigArray[iIndex];
}

8 4 , ( ).

+5

, . IE ++

int *foo = new int[10000000];

40 ( , int 4 ) . (, ), .

-2

Source: https://habr.com/ru/post/1584507/


All Articles