In my operating systems textbook, there is a paragraph which states:

As for the contents of each PTE, we have a number of different bits in there worth understanding at some level. A valid bit is common to indicate whether the particular translation is valid; for example, when a program starts running, it will have code and heap at one end of its address space, and the stack at the other. All the unused space in-between will be marked invalid, and if the process tries to access such memory, it will generate a trap to the OS which will likely terminate the process. Thus, the valid bit is crucial for supporting a sparse address space; by simply marking all the unused pages in the address space invalid, we remove the need to allocate physical frames for those pages and thus save a great deal of memory.

However, the bold sentences confuse me. I thought the whole point of paging was that you do away with the contiguous regions of logical code segments like stacks and heaps? With paging, couldn't the stack and heap be anywhere and non-contiguous? What guarantee do you have that the code, heap and stack will be separated to the top and bottom of the address space,as they say?

  • $\begingroup$ Yes, with pages you don’t need contiguous physical memory anymore, but most runtime still use contiguous virtual address space (to avoid yet another address inventory). Each stack or allocation arena or file mapping has typically a address and a length. $\endgroup$
    – eckes
    Oct 31, 2019 at 20:17
  • 1
    $\begingroup$ Can you credit the original source of the copied material? See cs.stackexchange.com/help/referencing for our guidelines on how to do that. $\endgroup$
    – D.W.
    Oct 31, 2019 at 21:11

1 Answer 1


There are two different address spaces, let's call them logical and physical. The addresses a programmer thinks about are the logical addresses, the page table translates logical addresses to physical addresses.

As you point out, paging allows you to sparsely map the logical address space to the physical address space.

But the bold sentences in your quote are talking about the sparsity of the logical address space. The quote is arguing that the valid bit is necessary for the sparsity of the logical address space.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.