How does page table handle both stack and heap memory addresses?

Viewed 1428

I've been taught that when the CPU generates a logical address, it is translated to physical address using page table, which usually is a contigous array allocated in operating system's memory space. The index into this array is the uppermost bits of the virtual address (aka page number).

Also, I know that the logical address for heap addresses are low while those for stack addresses are high, since they grow in opposite directions with stack starting from 0xffffffffffffffff.

So my question is that since the page number is low for heap addresses but very high for stack addresses, the page number (or the index in the page table) that CPU generates is not contigous but is either very high or very low. Then how is it used to index the page table without creating a very large page table.

Also, we need to maintain the size of the process and raise segmentation fault when the page number is greater than the limit (the number of pages/frames allocated to out process). How is this done if the valid page numbers aren't continous.

1 Answers
Related