Question

Assuming we use malloc() to apply for a big memory space, such as 16GB. After initialization the according physical pages would be located. Basically the malloc() would allocate contiguous space in virtual memory and then mapped to contiguous physical memory which consists of lots of pages whose size is traditionally 4KB. Let index them as: page0,1,2,3......n. I want to know If I access page by the sequence of page 0,1,2,3...K(contiguous), or by the sequence of page0, 100, 200, 300, k*100(discontiguous).

In above two cases, I both access k pages, I guess the 2nd case would be much slower. So I try to design a small test to prove that. The results show that only 20% performance degradation. My test program read by cache line size(64KB) when access each page.

I have two problem: 1. Could you tell me why the discontiguous access is slower? 2. Why it's only 20% slower, not 30%, 50% or much slower?

I run the test program in a machine with 2 8-core cpu and 64GB memory. Could you explain it theoretically or teach me how to design the test program( I guess my design has problem). Thanks

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top