How are global arrays loaded in memory (pintos)

67 Views Asked by At

I'm working on a PintOS Project(VM).

For Validation of what I implemented, I made a user program on which global array size of ten pages(4096 * 10). And I write a value on every first byte of the page.

What I intended was that Pintos occurs 10 page faults, but it happended only two times, and every values were stored well in only one page.

I thought ten virtual pages would be allocated for global array buf, but actually only one is allocated.

Can anybody tell me why my expectation was wrong? I think I have a wrong idea on how global arrays are stored in memory.


#define SIZE 10 * 4096
volatile char buf[SIZE] = {0}; 

int main (int argc, char**argv){
    int cnt = 0; 
    for(int i = 0; i < SIZE; i += 4096)
    {
        printf("%p", &buf[i]); 
        buf[i] = 'a' ;
    }

    for(int i = 0; i < SIZE; i += 4096)
    {
        printf("%d %c\n", cnt ++, buf[i]); 
    }

The Following output is as below.

hello from page fault.
hello from page fault.
0x804bce0
0x804cce0
0x804dce0
0x804ece0
0x804fce0
0x8050ce0
0x8051ce0
0x8052ce0
0x8053ce0
0x8054ce0
1 a
2 a
3 a
4 a
5 a
6 a
7 a
8 a
9 a

As the result shows, each &buf[i] requires different page(their indexes are 0x804b, 0x804c, ...)

Th

0

There are 0 best solutions below